classpath:包名/包名/包名/包名/文件名(不要后缀)

           

       

        

       

        

       

   


   

    

   

   

       

       

       

   


        @RequestMapping(value="/save",method=RequestMethod.POST)

public String add(@Valid  @ModelAttribute("cmsDifficultyLevel")CmsDifficultyLevel cmsDifficultyLevel,Errors errors,Model model){

//**参数@Valid 不能丢 Errors errors必须放在实体对象后不然报 org.springframework.validation.BeanPropertyBindingResult: 1 errors


if (errors.hasErrors()) {//判断是否出错

model.addAttribute("cmsDifficultyLevel", cmsDifficultyLevel);

return "cms/difficulty/difficulty_add";//这里的路径就是你进入当前页面的路径

}

if (cmsDifficultyLevel.getLevelId() != null) {

CmsDifficultyLevel difficultLevel = difficutlyLevelService.getById(cmsDifficultyLevel.getLevelId());

difficultLevel.setLevelName(cmsDifficultyLevel.getLevelName());

difficutlyLevelService.update(difficultLevel);

} else {

difficutlyLevelService.save(cmsDifficultyLevel);

}

return "redirect:/cms/difficulty";

}

    jsp页面错误打印信息

    <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>

    ${errorMsg}

    

    

    实体 是用@NotBlank(message = "难易程度名不能为空")