首页>代码>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日