3 Star 0 Fork 0

IFUNIT / springMvc-validate

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

#springMvc-validate mvc:interceptors </mvc:interceptors>

Controlloer
@Validations(

requiredStringValidators = {
                            @RequiredStringValidator(field = "name", message = "姓名不能为空!", trim = true),
                            @RequiredStringValidator(field = "email", message = "邮箱不能为空!", trim = true),
                            @RequiredStringValidator(field = "mobile", message = "手机不能为空!", trim = true),
                            @RequiredStringValidator(field = "username", message = "用户名不能为空!", trim = true),
                            @RequiredStringValidator(field = "userType", message = "用户类型不能为空!", trim = true) },

stringLengthValidators = { @StringLengthValidator(field = "username", message = "用户名只能在6-12位之间", minLength = "5", maxLength = "12") },

emailValidators = { @EmailValidator(field = "email", message = "邮箱格式不正确!") })
@RequestMapping(value = "/admin_save")
public String save(HttpServletRequest request, ModelMap model,
                   @RequestParam(value = "rePassword") String rePassword, Admin admin) {

    if (admin.getId() == null && StringUtils.isBlank(admin.getPassword())) {
        FormUtils.addFormError(request, "password", "密码不能为空!");
    } else if (StringUtils.isNotBlank(admin.getPassword())
               && !StringUtils.equals(admin.getPassword(), rePassword)) {
        FormUtils.addFormError(request, "rePassword", "两次密码不一致!");
    }

    if (FormUtils.hasErrors(request)) {
        return "admin/user_input";
    }
    userService.save(admin);

    return "redirect:admin_list.jhtml";
}

然后通过FormUtils.getFormErrors来显示错误

空文件

简介

springMvc的验证框架 展开 收起
Java
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Java
1
https://gitee.com/ifunit/springMvc-validate.git
git@gitee.com:ifunit/springMvc-validate.git
ifunit
springMvc-validate
springMvc-validate
master

搜索帮助