由于某些原因,我的Tomcat / Spring配置不会自动解码GET参数(我认为它应该自动完成)。
这是我的设置:
@RestController
public class MyController {
@RequestMapping(value = "/do-something", method = RequestMethod.GET)
public String doSomething(RequestPojo req) {
// req.getPhone -- is not decoded, ie might be something like 00%204 instead of 004
}
}
public class RequestPojo {
private String phone;
// getter and setter
}
以下是mvc-dispatcher-servlet的内容:
<mvc:default-servlet-handler/>
<mvc:annotation-driven>
<mvc:message-converters register-defaults="false">
<ref bean="customJsonHttpMessageConverter"/>
</mvc:message-converters>
</mvc:annotation-driven>
<context:component-scan base-package="com.onoff.controller">
<context:include-filter expression="org.springframework.stereotype.Controller" type="annotation"/>
</context:component-scan>
<bean id="multipartResolver" name="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="1073741824"/>
<property name="defaultEncoding" value="utf8"/>
</bean>
<bean id="customJsonHttpMessageConverter" class="com.onoff.util.CustomJsonHttpMessageConverter">
<property name="supportedMediaTypes" value="application/json; charset=utf-8"/>
</bean>
我在发帖前检查了一些建议。
URIEncoding="UTF-8"
在Tomcat中的 server.xml 中指定。
任何线索? 任何帮助/建议将受到高度赞赏。
提前谢谢。
答案 0 :(得分:1)
请尝试使用@ModelAttribute
public String doSomething(@ModelAttribute RequestPojo req) { // req.getPhone -- is not decoded, ie might be something like 00%204 instead of 004 }