重定向这是我更新的用户方法:春天在POST
@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'。另外,让你的控制器交易是一个可怕的想法......你应该有一个服务是事务性的边界(以便你可以重用那些东西)。 –