admin 管理员组文章数量: 1184232
controller的方法:
entity:
根据教程来说,使用ObjectError类的getDefaultMessage()方法可以获取到实体类中@NotEmpty注解中写好的message,
结果,报错了,长这个样子:
Field error in object 'productUser' on field 'pMessage': rejected value []; codes [NotEmpty.productUser.pMessage,NotEmpty.pMessage,NotEmpty.java.lang.String,NotEmpty]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [productUser.pMessage,pMessage]; arguments []; default message [pMessage]]; default message [产品说明信息不能为空]
Field error in object 'productUser' on field 'pId': rejected value []; codes [NotEmpty.productUser.pId,NotEmpty.pId,NotEmpty.java.lang.String,NotEmpty]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [productUser.pId,pId]; arguments []; default message [pId]]; default message [扫码失败]
Field error in object 'productUser' on field 'pName': rejected value []; codes [NotEmpty.productUser.pName,NotEmpty.pName,NotEmpty.java.lang.String,NotEmpty]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [productUser.pName,pName]; arguments []; default message [pName]]; default message [产品名称不能为空]]
然后就蒙圈了,然后根据搜到的例子来看,他们的controller方法中,只有两个参数,entity类和BindingResult对象,然后我又无语了,对于我来说另一个参数也是至关重要的,搜索了很多,看到了这么一句:
(来自: )
必须相邻
然后调整一下顺序:
搞定。
结论:使用validation检验数据,前面参数和BndingResult参数必须相邻,否则会造成错误。
版权声明:本文标题:深入理解与解决:在Flash环境下的多参数验证疑难 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1770725942a3536896.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论