控制器未从 jsp 页面接收数据
Controller does not recieve data from jsp page
我已将数据从 jsp 页面发送到控制器。它显示错误。
The origin server did not find a current representation for the target
resource or is not willing to disclose that one exists.
这是我的控制器::::
@GetMapping(value = "/createdistrict")
public ModelAndView createdistrict(Locale locale, Model model) {
List<Division> allDivisionList = new ArrayList<Division>();
allDivisionList = this.districtService.listdivisions() ;
Map<Integer,String> allDivision = new LinkedHashMap<Integer,String>();
for( int i=0 ; i < allDivisionList.size() ; i++) {
//System.out.println(" division id ::::::::::" + allDivisionList.get(i).getId() + " division name:::::::::" + allDivisionList.get(i).getName());
allDivision.put(allDivisionList.get(i).getId() , allDivisionList.get(i).getName());
}
return new ModelAndView("createdistrict" , "allDivision" , allDivision);
}
@RequestMapping(value="/adddistrict/{division}")
public String addDistrict(@ModelAttribute("district")District district, ModelMap model ,@RequestParam("division") int division) {
System.out.println("id:::::::::::::::::::" + division);
this.districtService.adddistrict(district, division);
return "redirect:districtlist";
}
这是我的 jsp 页面::::
<form method="POST" action="/farmvill/adddistrict" modelAtribute="district">
<table class="create-table table table-hover">
<tr>
<td>
Division
</td>
<td>
<select id="division" name="division">
<c:forEach items="${allDivision}" var="allDivision">
<option class="dropdivision" value="${allDivision.key}">${allDivision.value }</option>
</c:forEach>
</select>
</td>
</tr>
<tr>
<td>
Name
</td>
<td>
<input type="text" id="name" name="name" path="name"></input>
</td>
</tr>
<!-- End of single tr -->
</table>
<!-- End of table -->
<div class="button-set text-right">
<button type="submit" class="btn site-btn filled-btn" id="savebutton">save</button>
<a href="" class="btn site-btn filled-btn">cancel</a>
<a href="" class="btn site-btn filled-btn">reset</a>
</div>
<!-- End of button-set -->
</form>
我现在应该做什么?
从映射路径中删除 division
。这是一个常规请求参数
@RequestMapping(value="/adddistrict")
public String addDistrict(@ModelAttribute("district")District district, ModelMap model ,@RequestParam("division") int division) {
我已将数据从 jsp 页面发送到控制器。它显示错误。
The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
这是我的控制器::::
@GetMapping(value = "/createdistrict")
public ModelAndView createdistrict(Locale locale, Model model) {
List<Division> allDivisionList = new ArrayList<Division>();
allDivisionList = this.districtService.listdivisions() ;
Map<Integer,String> allDivision = new LinkedHashMap<Integer,String>();
for( int i=0 ; i < allDivisionList.size() ; i++) {
//System.out.println(" division id ::::::::::" + allDivisionList.get(i).getId() + " division name:::::::::" + allDivisionList.get(i).getName());
allDivision.put(allDivisionList.get(i).getId() , allDivisionList.get(i).getName());
}
return new ModelAndView("createdistrict" , "allDivision" , allDivision);
}
@RequestMapping(value="/adddistrict/{division}")
public String addDistrict(@ModelAttribute("district")District district, ModelMap model ,@RequestParam("division") int division) {
System.out.println("id:::::::::::::::::::" + division);
this.districtService.adddistrict(district, division);
return "redirect:districtlist";
}
这是我的 jsp 页面::::
<form method="POST" action="/farmvill/adddistrict" modelAtribute="district">
<table class="create-table table table-hover">
<tr>
<td>
Division
</td>
<td>
<select id="division" name="division">
<c:forEach items="${allDivision}" var="allDivision">
<option class="dropdivision" value="${allDivision.key}">${allDivision.value }</option>
</c:forEach>
</select>
</td>
</tr>
<tr>
<td>
Name
</td>
<td>
<input type="text" id="name" name="name" path="name"></input>
</td>
</tr>
<!-- End of single tr -->
</table>
<!-- End of table -->
<div class="button-set text-right">
<button type="submit" class="btn site-btn filled-btn" id="savebutton">save</button>
<a href="" class="btn site-btn filled-btn">cancel</a>
<a href="" class="btn site-btn filled-btn">reset</a>
</div>
<!-- End of button-set -->
</form>
我现在应该做什么?
从映射路径中删除 division
。这是一个常规请求参数
@RequestMapping(value="/adddistrict")
public String addDistrict(@ModelAttribute("district")District district, ModelMap model ,@RequestParam("division") int division) {