我用的spring 3.2 的版本,用responseBody 返回JSON 在IE下会变成下载,试了很多办法终于解决了!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
@Controller @RequestMapping ( "/data" )
public class TestController {
@ResponseBody
@RequestMapping (method = RequestMethod.GET,value = "/channel/{type}" )
public
Channel getChannel( @PathVariable
String type){
Channel c = new
Channel();
c.setId( 1 );
c.setName( "中国啊啊" );
c.setType(type);
return
c;
}
} |
在 springMVC 的 servlet.xml中这样配置
<mvc:annotation-driven> <mvc:message-converters register-defaults="true"> <bean id="jsonConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"> <property name="supportedMediaTypes" value="text/html;charset=UTF-8" /> </bean> </mvc:message-converters> </mvc:annotation-driven>