springmvc 数据精准绑定

本文详细介绍了如何在Spring MVC中利用initBinder注解解决使用DWZ的lookup功能时,表单数据name没有前缀导致后台绑定错误的问题。通过设置字段默认前缀,确保数据正确绑定。

因为使用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

转载于:https://www.cnblogs.com/xunux/p/4485778.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值