分布式restful中的问题

1、 访问服务后返回值中有中文乱码

在RequestMapping中添加produces属性。

@RequestMapping(value = "/user/register", method = RequestMethod.POST, produces = MediaType.TEXT_PLAIN_VALUE + ";charset=utf-8")

如果返回是json的场合,APPLICATION_JSON_VALUE

2、 put类型请求无法获取参数

在web.xml中添加对于过滤器

<filter>

<filter-name>HttpMethodFilter</filter-name>

<filter-class>org.springframework.web.filter.HttpPutFormContentFilter</filter-class>

</filter>

<filter-mapping>

扫描二维码关注公众号,回复: 5089618 查看本文章

<filter-name>HttpMethodFilter</filter-name>

<url-pattern>/*</url-pattern>

</filter-mapping>

注意:

需要注意的是,该过滤器只能接受enctype值为application/x-www-form-urlencoded的表单,也就是说,在使用该过滤器时,form表单的代码必须如下:

<form action="" method="put" enctype="application/x-www-form-urlencoded">  

......  

</form>  

猜你喜欢

转载自www.cnblogs.com/mollie-x/p/10326118.html