Springmvc controller接收多个对象 存在相同属性时解决方案

如题:

 

controller中需要同时接受两个对象 Student ,Teacher 但是同时都有id,name属性. 此时spring的自动注入就不能正确取值了   

 

 此处简单提供三种解决方案: 

 

1. 创建一个VO 包括Student student; 和Teacher teacher;对象  然后前台传入 student.id student.name teacher.id teacher.name .

 

2. 前台传入 student.name, teacher.name, 后台自定义参数对象解析器实现请求参数绑定方法参数

参照: http://jinnianshilongnian.iteye.com/blog/1717180

 

3. 前台传入json对象 ,后台自定义JSON对象解析器实现请求参数绑定方法参数

参照: http://jinnianshilongnian.iteye.com/blog/1719952 


 

文章来自:http://www.cnblogs.com/wangdaijun/p/5369638.html
© 2021 jiaocheng.bubufx.com  联系我们
ICP备案:鲁ICP备09046678号-3