SpringMVC对于pojo与基本类型的参数绑定

白鹿青崖_ 2016-05-21 08:05:28
今天碰到一个情况,页面A中表单中有一个input元素,name是id,表单的action对应的是BController中的某方法,现在的情况是
1.如果我用形参int id来接收,这个参数就能被绑定
public String firstCategeryAddOrUpdate(int id,Model model){

2.如果我用带有int id这个成员变量的pojo来接收
public String firstCategeryAddOrUpdate(FirstCategery first,Model model){


public class FirstCategery {
private int id ; //序号
private int index ; //排序
private String name ; //名称
private List<SecondCategery> seconds ;


这个参数就不能绑定,console控制台打出
Failed to convert property value of type java.lang.String to required type int for property id
这一行日志,我最后通过@InitBinder注解来解决

请问:SpringMVC中对于pojo中的基本类型的成员变量的数据绑定规则和直接用基本类型的数据绑定规则是不一样的吗?
...全文
738 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
cmontxgt 2016-09-08
  • 打赏
  • 举报
回复
mark,我遇到的问题是:pojo与传递过来的name不一致应该怎样绑定

24,923

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Apache
社区管理员
  • Apache
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧