使用重定向後拿到訊息的方法
阿新 • • 發佈:2021-01-31
技術標籤:springbootjavajavascriptspring
使用redirect重定向url後可以用RedirectAttributes拿到訊息並將訊息展示到前端
通過attributes.addFlashAttribute方法
@PostMapping("/types")
public String posy(Type type, RedirectAttributes attributes){
Type type1 = typeService.saveType(type);
if (type1 == null ) {
attributes.addFlashAttribute("messgage","操作失敗");
} else {
attributes.addFlashAttribute("message","操作成功");
}
return "redirect:/admin/types";
}