我正在开发一个旧的Spring项目,我想从我的发帖请求中更新视图中的某些字段。

我没有运气就尝试了以下方法:

@RequestMapping(value="/dashboard/{calories}", method=RequestMethod.POST)
public void updateCals (@PathVariable Long calories, Model model, HttpSession session, HttpServletRequest request, HttpServletResponse response) {
            request.getSession().setAttribute("tea", tea);
    model.addAttribute("tea", tea);
}


我应该在末尾添加返回或重定向吗?任何帮助将不胜感激

最佳答案

返回重定向:

@RequestMapping(value="/dashboard/{calories}", method=RequestMethod.POST)
public void updateCals (@PathVariable Long calories, Model model, HttpSession session, HttpServletRequest request, HttpServletResponse response) {
            request.getSession().setAttribute("tea", tea);
            model.addAttribute("tea", tea);
            return "redirect:/example";
}

09-26 21:04