为什么我的 userConsul 模型中没有任何内容
当我提交表单时,我想收集用户咨询信息。然后,我调用我的存储库并调用 Insert 方法。在括号内我包括例如
userRepo.insertoIntoDB(userConsult.getepidemiology);
(我已经保留了其他 get 方法,因为它太长了。
我运行这个方法,当我检查数据库时,我注意到只有我没有使用 userConsult 的字段里面有项目。
我认为这与我的选项/选择标签有关但是我不确定为什么它里面没有任何东西。当我使用 thymeleaf 时,
如果我自己给它测试输入,它就可以正常工作。
请参阅下面的代码:
<form method="POST" th:action="@{/saveConsultation}" th:object="${userConsul}">
<label for="epidemiology">EPIDEMIOLOGY:</label>
<select id="epidemiology">
<option th:each="data : ${consultationData}"
th:text="${data.epidemiology}"
th:value="${data.epidemiology}">
</select>
<a th:href="@{/saveConsultation/{id}(id = ${patient.patientNumber})}" type="submit">Submit</a>
<input type="reset" value="Reset diagnosis">
</form><br>
咨询控制器:
@RequestMapping("/saveConsultation/{id}")
public String saveConsultation(@ModelAttribute("userConsul") userConsul userConsul,HttpSession session,Model model,@PathVariable("id") int patientID){
Object USER_SESSION = session.getAttribute("USER_SESSION");
if (USER_SESSION == null) {
session.setAttribute("message", "You need to login to access the Consultation page");
return "redirect:/login";
}
User OldUser = (User) USER_SESSION;
int userId = OldUser.getID();
userRepository.insertIntoUserCase(userConsul.getEpidemiology(),userConsul.getComplaints(),userConsul.getExamination(),userConsul.getDiagnosis1(),userConsul.getDiagnosis2(),userConsul.getDiagnosis3(),patientID,userId);
return "test";
}
When I submit the form I want to collect the userConsult information. I then call my repository and call the Insert method. inside the brackets I include e.g.
userRepo.insertoIntoDB(userConsult.getepidemiology);
(I have left the other get methods as it is so long.
I run this and when I check my database I notice that only the fields I didnt use userConsult have items inside.
I think there is something to do with my options/select tag however I am unsure why there is nothing inside it. It works fine when I use input tags. I am using thymeleaf.
The Insert function works fine if I give it test inputs myself.
Please see my code below:
<form method="POST" th:action="@{/saveConsultation}" th:object="${userConsul}">
<label for="epidemiology">EPIDEMIOLOGY:</label>
<select id="epidemiology">
<option th:each="data : ${consultationData}"
th:text="${data.epidemiology}"
th:value="${data.epidemiology}">
</select>
<a th:href="@{/saveConsultation/{id}(id = ${patient.patientNumber})}" type="submit">Submit</a>
<input type="reset" value="Reset diagnosis">
</form><br>
Consultation Controller:
@RequestMapping("/saveConsultation/{id}")
public String saveConsultation(@ModelAttribute("userConsul") userConsul userConsul,HttpSession session,Model model,@PathVariable("id") int patientID){
Object USER_SESSION = session.getAttribute("USER_SESSION");
if (USER_SESSION == null) {
session.setAttribute("message", "You need to login to access the Consultation page");
return "redirect:/login";
}
User OldUser = (User) USER_SESSION;
int userId = OldUser.getID();
userRepository.insertIntoUserCase(userConsul.getEpidemiology(),userConsul.getComplaints(),userConsul.getExamination(),userConsul.getDiagnosis1(),userConsul.getDiagnosis2(),userConsul.getDiagnosis3(),patientID,userId);
return "test";
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论