我想使用post/redirect/get模式转换post请求,以防止出现“映射到HTTP路径的模糊处理程序方法”错误。详情请参见This question。
以下是初始代码:
@Controller
@RequestMapping("/bus/topologie")
public class TopologieController {
private static final String VIEW_TOPOLOGIE = "topologie";
@RequestMapping(method = RequestMethod.POST, params = { "genererCle" })
public String genererCle(final Topologie topologie, final Model model)
throws IOException {
cadreService.genererCle(topologie);
return VIEW_TOPOLOGIE;
}我真的不知道如何使用PRG模式对其进行重新编码。即使我认为我理解了潜在的概念。
发布于 2016-05-25 18:09:11
您需要添加另一个方法来处理同一url映射的GET请求。因此,在POST方法中,您只需进行重定向,而在GET方法中,您可以执行所有业务流程。
@Controller
@RequestMapping("/bus/topologie")
public class TopologieController {
private static final String VIEW_TOPOLOGIE = "topologie";
@RequestMapping(method = RequestMethod.POST, params = { "genererCle" })
public String genererClePost(final Topologie topologie, final RedirectAttributes redirectAttributes, @RequestParam("genererCle") final String genererCle, final Model model)
throws IOException {
redirectAttributes.addAttribute("genererCle", genererCle);
return "redirect:/bus/topologie";
}
@RequestMapping(method = RequestMethod.GET, params = { "genererCle" })
public String genererCleGet(final Topologie topologie, final Model model)
throws IOException {
cadreService.genererCle(topologie);
return VIEW_TOPOLOGIE;
}https://stackoverflow.com/questions/37433564
复制相似问题