spring - Spring WebFlux + thymeleaf: Post request redirect 获取页面返回 303 查看其他状态
问题描述
我只是使用 SpringBoot + WebFlux + thymeleaf 来编写控制器。
@RequestMapping(value = "/create", method = RequestMethod.GET)
public String createCityForm(Model model) {
model.addAttribute("city", new City());
model.addAttribute("action", "create");
return CITY_FORM_PATH_NAME;
}
@RequestMapping(value = "/create", method = RequestMethod.POST)
public String postCity(@ModelAttribute City city) {
cityService.saveCity(city);
return REDIRECT_TO_CITY_URL;
}
我使用 thymeleaf 页面接收表单,并重定向/返回 get 方法页面,但浏览器给出 303 查看其他状态。此外,删除资源也不起作用。
解决方案
SEE_OTHER
状态实际上是在没有明确指定 HTTP 代码的情况下调用时的默认状态(RedirectView
就像ThymeleafReactiveViewResolver
那样)。
如果你想覆盖这个状态,RedirectView
当它与redirect:
视图名称中的模式匹配时,直接返回而不是让 Thymeleaf 这样做:
@RequestMapping(value = "/create", method = RequestMethod.GET)
public RedirectView createCityForm(Model model) {
model.addAttribute("city", new City());
model.addAttribute("action", "create");
return new RedirectView("/target_url", HttpStatus.MOVED_PERMANENTLY);
}
推荐阅读
- python - Visual Studio 代码不再显示调用堆栈中的线程
- jpa - @PostLoad CassandraRepository 的相邻事件?
- php - strip_tags 和 tinymce 问题
- angular - 如何托管角度开发工具的角度材料?
- laravel - Laravel 中间件 auth:api 如何从 cookie 中检测令牌?
- reactjs - 在 TypeSCript 中基于类的组件中使用 React useContext
- javascript - 如何在每个区域的反应谷歌地图中添加和编辑多边形
- sql - 值计数器栏的 Informatica BDM 问题
- javascript - htmlOutput 中的图像网格
- powershell - 创建加密文件并授予用户访问权限