@PostMapping(value = "/demo", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public String responseEntityMono(@RequestParam("email") String email) {
return email;
}
同样的一段代码,使用 postman 的 application/x-www-form-urlencoded 形式提交表单数据 email=xxx
结果在普通的 web-starter 下创建的 springboot ,可以正常解析到 email ,而在 Webflux 下创建的 springboot ,则无论如何解析不了 email ,总提示我 email 字段缺失
有人知道原因吗
1
lyxeno 2023-02-27 20:33:59 +08:00 2
`@RequestParam`的文档里有说明
在 Spring WebFlux 中`@RequestParam`只映射查询参数(URL 后面跟着的),而 x-www-form-urlencoded 是请求体的,自然不会解析 https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/bind/annotation/RequestParam.html > In Spring MVC, "request parameters" map to query parameters, form data, and parts in multipart requests. This is because the Servlet API combines query parameters and form data into a single map called "parameters", and that includes automatic parsing of the request body. In Spring WebFlux, "request parameters" map to query parameters only. To work with all 3, query, form data, and multipart data, you can use data binding to a command object annotated with ModelAttribute. |
2
shayang888 OP @lyxeno 啊 原来如此 谢谢大佬!!!!!!!
|