SpringMVCInitBinder验证方法-创新互联
使用InitBinder做验证的情况一般会在此Controller中提交的数据需要有一些是业务性质的,也即比较复杂的验证情况下才会使用。大部份简单的表单验证,使用annotation验证即可以解决。

Annotation验证使用方法可参见:https://www.jb51.net/article/136448.htm
这里需要注意的一点:InitBinder和Annotation两种验证只能二选一,如果使用了InitBinder,就不能使用Annotation验证。
前面的web.xml和spring.xml的配置就不再重复,可参见上面链接中的配置。一模一样。
直接上代码:
1、User5 model实体类
package com.my.controller.bean;
import java.util.Date;
public class User5 {
private long id;
private String name;
private String password;
private Date createTime;
private int age;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
} 分享标题:SpringMVCInitBinder验证方法-创新互联
转载来于:http://www.jxjierui.cn/article/iispi.html


咨询
建站咨询
