这一次和spring源码贡献者有多近(1)
身为一个Java的coder,一直以成为优秀源码贡献者为目标努力。最近工作中发现一个springboot的case,我知道机会来了,话不多说,直接进入正题。
工程背景
1、容器出于性能考虑选择undertow容器,弃用tomcat。
2、SPRING WEB
3、表单请求,含中文字符。
CASE复现
表单请求,中文乱码(输入的是‘中文’两个字)
代码如下
springboot版本:2.3.1.RELEASE
pom依赖:
<dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-undertow</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId><exclusions><exclusion><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-tomcat</artifactId></exclusion></exclusions></dependency></dependencies>
controller层:
@RequestMapping(value = "/api")@RestController@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)public class ContainerController {public static final String VALUE = "中文";@PostMapping(value = "/test", consumes = {MediaType.APPLICATION_FORM_URLENCODED_VALUE})public Boolean test(String key){return VALUE.equals(key);}public static void main(String[] args) {SpringApplication.run(ContainerController.class, args);}}
调用:
###模拟 发送form表单请求POST localhost:8080/api/testContent-Type: application/x-www-form-urlencodedkey=中文
看了下自己写的代码,核心大概也就算一行吧。其他的全是springboot自带code,问题一定出在springboot吧,这么思考,我觉得没毛病。出现BUG我心里居然乐开了花,心想这个问题还不简单,先找到在哪里转成乱码的,然后正确转换一下,再提个MR,这样我也是SPRING的源码贡献者啦!!!
