I have Java with Spring
public String addStudent(@RequestParam(value = "selStud") Long idS,
@RequestParam(required = false, value = "selDisc") Long idD,
ModelMap modelMap){
long selectedId = idS;
long selDiscipline = idD;
return "redirect:/";
}
and this HTML:
<form action="#" th:action="@{/add-student}" class="new-student-form" method="post" >
<ul name="selDisc" type="none" th:each="discipline : ${disciplineList.disciplines}" th:value="${discipline.id}">
<div th:onclick="|javascript:showDiv('${discipline.id}');|"
th:text="${discipline.name}"
th:value="${discipline.id}"
class="discipline-name" >..
</div>
<div th:id="${discipline.id}">
<ul class="discipline-info"
th:unless="${#lists.isEmpty(discipline.students)}">
<li th:each="student : ${discipline.students}"
th:text="${student.student}" class="studName" name="studName">
</li>
</li>
</ul>
<div name="studOption" th:id="${discipline.id}">
<select name="selStud" required >
<option th:each="student : ${students}"
th:value="${student.id}"
th:id="${student.id}"
name="studentOption"
th:text="${student.student}">Select</option>
</select>
<input type="submit" class="add-student-to-disc" value="Добавить в дисциплину">
</div>
</div>
</li>
</ul>
</form>
With @RequestParam(value = "selStud") Long idS
I get th:value="${student.id}"
from Option, from Select with name "selStud". Example selectedId = 5
.
But with @RequestParam(required = false, value = "selDisc") Long idD
I get NULL from <ul name="selDisc">
. And @RequestParam(value = "selDisc") Long idD
does not work, because selDisc all time return null. I have an error "Required Long parameter is not present"
I want to get discipline id, what am I doing wrong?
I put <input name="selDisc" th:value="${discipline.id}" type="hidden">
after the first div.
But it works by chance.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.