springmvc返回不带引号的字符串
项目使用springboot开发的,大部分出参为json,使用的fastJson,现在有的接口需要返回一个success字符串,发现返回结果为“success”,因为fastJson对出参做了处理,现在添加string类型的解析器就可以了,代码如下:
@Configuration
@EnableWebMvc
public class WebConfiguration extends WebMvcConfigurerAdapter {
@Bean
public StringHttpMessageConverter stringHttpMessageConverter(){
StringHttpMessageConverter converter = new StringHttpMessageConverter(("UTF-8"));
return converter;
}
@Bean
public FastJsonHttpMessageConverter fastJsonHttpMessageConverter(){
FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter();
();
(("UTF-8"));
return converter;
}
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
(stringHttpMessageConverter());
(fastJsonHttpMessageConverter());
}
@Override
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
();
(stringHttpMessageConverter());
(fastJsonHttpMessageConverter());
}
}
**
注意:string类型的解析器要放到json的前面
**