这是我的更新用户方法:
@ResponseBody
@Transactional
@RequestMapping(value = "/profile/edit/{id}", method = RequestMethod.POST)
public String updateUser(@PathVariable("id") final Integer id, String firstname, String lastname, final RedirectAttributes redirectAttributes) {
respository.updateFirstname(id,firstname);
respository.updateLastname(id, lastname);
redirectAttributes.addFlashAttribute("message", "Successfully changed..");
return "redirect:/profile";
}
一切正常。还有数据库中的更新。但重定向只是一个字符串,不会更改路径。谁能告诉我为什么?
最佳答案
问题出在 @ResponseBody
注释中。删除后,重定向应按预期工作。通过使用它,您可以覆盖 Spring MVC 的默认行为,并将返回值视为原始响应。
关于POST 上的 Spring 重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40631150/