【发布时间】:2016-10-14 14:01:30
【问题描述】:
我有一个如下所示的列表页面,当我单击“编辑”按钮时,我想将 patientId 发送到 getObject(),这样如果 patientId 存在,我就可以从 DB 加载对象。我尝试了很多方法,但它在getObject()中将null作为patiendId。 任何建议,将不胜感激。
以下是我的列表页面::
<c:forEach var="pat" items="${patients}" varStatus="status">
<tr>
<c:url var="editUrl" value="/patient/${pat.patientId}"/>
<td>${pat.firstName}</td>
<td>${pat.mobileNumber1}</td>
<td>${pat.emailId1}</td>
<td><a href='<c:out value="${editUrl}"/>'>Edit</a></td>
</tr>
</c:forEach>
控制器代码::
@Controller
@RequestMapping(value="/patient")
public class PatientController {
@ModelAttribute
public Patient getObject(@RequestParam(required=false) String patientId){
System.out.println("Model Attribute method :: "+patientId);
//Here I want to load the object using patientId.
return(patientId != null ? patientDAO.findPatientById(patientId) : new Patient());
}
@RequestMapping(value="/{patientId}", method=RequestMethod.GET)
public String editPatient(@PathVariable("patientId")String patientId){
System.out.println("Editing Id : "+patientId);
//Able to get the Id here.
return "editPage";
}
【问题讨论】:
标签: spring modelattribute