• MVC效验器


    步骤一:导入依赖

    <!--数据效验-->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>5.4.1.Final</version>
    </dependency>

    步骤二:实体类

      

    步骤三:新增控制器

    @Controller
    @RequestMapping("/person")
    public class PersonController {
    
        @RequestMapping( value = "/validationPerson")
        //@ResponseBody
        public String validationPerson(@Validated Dog dog, BindingResult br, Model model){
            if (br.hasErrors()){
                //判断是否存在验证错误的信息
                List<ObjectError> allErrors = br.getAllErrors();
                for (ObjectError item:allErrors){
                    System.out.println("1111111"+item.getDefaultMessage());
                    model.addAttribute("error",item);
                }
            }
            return "error";
        }
    }

    步骤四:结果

      

  • 相关阅读:
    Php compiler for .NET framework
    C++ Virtual Inheritance Memory Layout
    MIT公开课汉化
    OpenGL like Vulkan
    C++ Chrono Timer
    VisTools: C++模仿Java体系
    Lua IDE
    PHP调试
    Decoda
    JSRDB
  • 原文地址:https://www.cnblogs.com/wnwn/p/11841529.html
Copyright © 2020-2023  润新知