首页>代码>Spring MVC用户注册配置入门教程及其代码实例demo下载>/RegUser/src/main/java/com/zuidaima/user/controllers/UserValidation.java
package com.zuidaima.user.controllers;

import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import com.zuidaima.user.model.User;

@Component("userValidator")
public class UserValidation {

	/**
	 * 数据校验
	 * @param target
	 * @param errors
	 */
	public void validate(Object target, Errors errors) {
		User registration = (User) target;
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userName",
				"NotEmpty.registration.userName",
				"用户名不能为空.");
		String userName = registration.getUserName();
		if ((userName.length()) > 50) {
			errors.rejectValue("userName",
					"lengthOfUser.registration.userName",
					"用户名长度不可大于50.");
		}
		if (!(registration.getPassword()).equals(registration
				.getConfirmPassword())) {
			errors.rejectValue("password",
					"matchingPassword.registration.password",
					"两次输入的密码不一致.");
		}
	}
}
最近下载更多
李亮  LV19 2023年3月7日
a1677596408  LV23 2022年7月1日
543666826  LV33 2021年11月28日
15827485252  LV19 2021年8月4日
Sunny_yan  LV9 2021年4月1日
0011100  LV12 2020年6月10日
f123654789  LV17 2019年9月19日
yangdong  LV13 2019年8月7日
半夜起来删代码  LV2 2019年6月20日
hxxxxxx  LV1 2019年5月23日
最近浏览更多
renxi222 2月29日
暂无贡献等级
你爹正在加载中  LV4 2023年8月3日
小妹妹  LV7 2023年5月22日
win1991  LV6 2023年5月14日
李亮  LV19 2023年3月7日
a1677596408  LV23 2022年7月1日
兰文斌  LV6 2022年5月4日
HCY666  LV2 2021年12月21日
543666826  LV33 2021年11月28日
lvhaowen  LV20 2021年10月27日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友