springMVC校验注解@Valid

J2EE 码拜 8年前 (2016-06-01) 1720次浏览
框架是同事搭建的,有model包和entity包,
其中model对应表单数据
entity对应数据库
本人发现之前的controller都没有对参数进行校验。
本人想把校验加上,使用注解
例如:用户
model叫UserModel
entity叫User
在controller中怎么把model的对象赋值给entity对象?
UserModel 字段有userName等加上了@NotNull的注解
@RequestMapping(value = {“/edit”} , method = RequestMethod.POST)
public String updateDb(@ModelAttribute UserModel   userModel ,Model model,HttpSession session){
//这里怎么把userModel赋值给User?
//使用beanUtis?还是其他方式?

//把User传递给server
return “success”;
}
解决方案

20

应该不能直接赋值给entity的吧,但是假如字段都对上的话应该可以直接插入不用再换成entity的

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明springMVC校验注解@Valid
喜欢 (1)
[1034331897@qq.com]
分享 (0)