嗨,在我的春季休眠注释应用程序中,我使用jsp作为视图。在jsp中,我正在从mysql数据库中将值加载到下拉列表中。但是我无法将所选值从jsp页面传输到控制器。我在mysql中有两个表employee表和team表。我想显示所选团队中的所有雇员。例如,如果我从下拉列表中选择team1,我想显示team1中的所有雇员。
我的用于将mysql数据库值加载到dropdownlist的jsp页面代码片段
<form:form method="POST" action="Search.html">
<table>
<tr>
<td>
<form:label path="teams.teamId" id="teams">Team Name</form:label>
</td>
<td>
<form:select path="teams.teamId" cssStyle="width: 150px;">
<option value="-1">Select a type</option>
<c:forEach items="${teamKey}" var="teams">
<option value="${teams.teamId}" >${teams.teamName}</option>
</c:forEach>
<tr>
<td colspan="2"><input type="submit" value="submit"> </td>
</tr>
</form:select>
</tr>
</table>
</form:form>
在resourcedaoimpl中的休眠选择查询
@Override
public void serchResources(int teamid) {
// TODO Auto-generated method stub
System.out.println("teamid is given---------- :"+teamid);
sessionfactory.getCurrentSession().createQuery("FROM Resource WHERE teamId=" +teamid);
System.out.println("After query teamid is given--************* :"+teamid);
}
监修班
@RequestMapping(value="/Search",method = RequestMethod.POST)
public ModelAndView fromSearch(@ModelAttribute("command") Resource resource,BindingResult result){
return new ModelAndView("redirect:/searchResult.html");
}
@RequestMapping(value="/searchResult",method = RequestMethod.GET)
public ModelAndView searchResult(@ModelAttribute("command") Resource resource,BindingResult result){
Map<String, Object> model = new HashMap<String, Object>();
//to print employee table
model.put("resourcekey",resourceServices.listResources());
//lists teams
model.put("teamKey", addteamServices.listTeams());
return new ModelAndView("Search",model);
}
感谢您的任何建议。
最佳答案
您需要在表单标签中包含modelAttribute
,
<form:form method="POST" action="Search.html" modelAttribute="command" >
因此,当您尝试在控制器中获取它们时,将具有model属性的值