jQuery MiniUI
标题:
前端提交和后端接收数据不一致的问题
[打印本页]
作者:
小布丁
时间:
2018-2-12 14:59:56
标题:
前端提交和后端接收数据不一致的问题
遇见一个特别诡异的问题,前端采用ajax 提交json数据。上送的数据是这样子的:
{"id":"","neckName":"中","loginName":"12312","birthday":"","registerTime":"2018-02-12","uniqueId":"QCN1518418088553","nation":"1","sex":"1","status":"1","address":"","certificateNo":"312321312312312312","phone":"12312","email":""}。
注意:里面的id为空,后台采用springmvc接收表单,@RequestBody User user实体类接收,然后打印这个实体, logger.info("user-string:"+user.toString());
得到的结果:user-string:User [id=0, loginName=12312, sex=1, nation=1, password=null, birthday=null, status=1, uniqueId=QCN1518418088553, email=, address=, phone=12312, neckName=中, passwordBirthday=null, registerTime=Mon Feb 12 08:00:00 CST 2018, certificateNo=312321312312312312, imgs=null]
为啥这个user的id变成0了,导致我在保存的时候直接报错了,java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.String
作者:
felt
时间:
2018-2-12 15:47:30
看一下浏览器的网络交互,提交的时候这个这里面传递的数据是空的还是“”。
作者:
小布丁
时间:
2018-2-13 09:28:03
felt 发表于 2018-2-12 15:47
看一下浏览器的网络交互,提交的时候这个这里面传递的数据是空的还是“”。
...
这个问题貌似也不知道咋造成的,我把实体类的id改成Integer类型,原来是long类型,然后在dao层操作数据库的时候作类型的手动转换
欢迎光临 jQuery MiniUI (http://miniui.com/discuss/)
Powered by Discuz! X2