springmvc 数据精准绑定

因为使用dwz 的lookup功能,回调的值通过name以 xxx.xxValue 来自动得到,而我还有些表单数据的name是没有前缀的, 到springmvc后台绑定的的话默认的绑定是有问题的。这是需要用到 initBinder 注解功能

 

1     @InitBinder("bannerInfo")  

2     public void initBinder1(WebDataBinder binder) {  

3         binder.setFieldDefaultPrefix("bannerInfo.");  

4     } 
1 @RequestMapping(value = "/add", method = RequestMethod.POST)

2 @ResponseBody 

3 public String add(@ModelAttribute("bannerInfo") BannerInfo bannerInfo) { 

4     //。。。。。

5  }
1 <form method="POST" action="${contextPath}/banner-info/add" class="required-validate pageForm" onsubmit="return validateCallback(this, dialogReloadNavTab);">

2     <label>栏位名称</label>

3     <input type="text" name="bannerName" />

4     <label>相关编号</label>

5     <input type="text" name="bannerInfo.code" />

6     <input type="submit" value="提交" />

7 </form>

 

 

 

参考:

  http://jinnianshilongnian.iteye.com/blog/1888474

你可能感兴趣的:(springMVC)