RedirectAttributes重定向:
@RequestMapping(value = "/delete/{id}")
public ModelAndView delete(@PathVariable Integer id, RedirectAttributes ra) {
ModelAndView result = new ModelAndView("redirect:/countries");
countryService.deleteById(id);
ra.addFlashAttribute("msg", "删除成功!");
return result;
}
ModelAndView的用法
@RequestMapping(value = "/save", method = RequestMethod.POST)
public ModelAndView save(Country country) {
ModelAndView result = new ModelAndView("view");
String msg = country.getId() == null ? "新增成功!" : "更新成功!";
countryService.save(country);
result.addObject("country", country);
result.addObject("msg", msg);
return result;
}
Javax包校验
<!-- 自定义校验 -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>