【问题标题】:Spring WebFlux + thymeleaf: Post request redirect Get page returns the 303 see other statusSpring WebFlux + thymeleaf: Post request redirect 获取页面返回 303 查看其他状态
【发布时间】:2018-12-27 09:07:24
【问题描述】:

我只是用 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 查看其他状态。 另外,删除资源也不起作用。

【问题讨论】:

  • 您需要提供比这更多的细节。添加您的 VIewresolver 代码。属性文件,如果您使用 .好像重定向配置不正确

标签: spring spring-boot thymeleaf spring-webflux


【解决方案1】:

SEE_OTHER 状态实际上是 RedirectView 在未明确指定 HTTP 代码的情况下调用时的默认状态(如 ThymeleafReactiveViewResolver 所做的那样)。

如果您想覆盖此状态,请直接返回 RedirectView,而不是让 Thymeleaf 在与视图名称中的 redirect: 模式匹配时执行此操作:

@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);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-25
    • 1970-01-01
    • 2021-05-08
    • 2013-06-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多