1.引入jar包
2.在实体类里加相应的注解
3.在控制层接收参数
@RequestMapping("registe") public String registe1(@Valid people peo,BindingResult br,Model model) { if(br.hasErrors()) { Map<String, Object> map=new HashMap<>(); List<FieldError> fieldErrors = br.getFieldErrors(); for(FieldError f:fieldErrors) { System.out.println(f.getField()); map.put(f.getField(), f.getDefaultMessage()); } model.addAttribute("map", map); return "forward:../registe.jsp"; }else { return "list"; } }
springmvc数据校验。(后台校验 hibernate validate).
原文:https://www.cnblogs.com/sh-0131/p/11462442.html