@wenshao 你好,想跟你请教个问题:
我看你写的那个FastJsonHttpMessageConverter,我的spring mvc配置文件怎样写才能让输出的时间是yyyy-MM-dd HH
还真是这两个包的问题。
配置好了,访问后出现:The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers. 是不是还有什么参数没有加上
哈,我自己改源码了。先凑合着用,等温少更新之后,就用他的。
http://code.alibabatech.com/jira/browse/FASTJSON-190
public class MappingFastjsonHttpMessageConverter extends AbstractHttpMessageConverter<Object> { public static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8"); private SerializerFeature[] serializerFeature; public SerializerFeature[] getSerializerFeature() { return serializerFeature; } public void setSerializerFeature(SerializerFeature[] serializerFeature) { this.serializerFeature = serializerFeature; } public MappingFastjsonHttpMessageConverter() { super(new MediaType("application", "json", DEFAULT_CHARSET)); } @Override public boolean canRead(Class<?> clazz, MediaType mediaType) { return true; } @Override public boolean canWrite(Class<?> clazz, MediaType mediaType) { return true; } @Override protected boolean supports(Class<?> clazz) { throw new UnsupportedOperationException(); } @Override protected Object readInternal(Class<?> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException { return JSON.parseObject(StreamUtil.readBytes(inputMessage.getBody()), clazz); } @Override protected void writeInternal(Object o, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException { String jsonString = JSON.toJSONString(o, serializerFeature); OutputStream out = outputMessage.getBody(); out.write(jsonString.getBytes(DEFAULT_CHARSET)); out.flush(); } }
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"> <property name="messageConverters"> <list> <bean class="xxx.web.json.MappingFastjsonHttpMessageConverter"> <property name="supportedMediaTypes" value="application/json" /> <property name="serializerFeature"> <list> <value>WriteMapNullValue</value> <value>QuoteFieldNames</value> </list> </property> </bean> </list> </property> </bean>
你都配置了转换器了,当然直接return obj就行了
@RequestMapping(params = "queryUserInfo") @ResponseBody public List<UserInfoDO> queryUserInfo(){ System.out.println("================begin=================="); List<UserInfoDO> userList=userInfoService.queryUserInfo(); return userList; }
Controller 中如何输出呢。
@RequestMapping(params = "queryUserInfo") @ResponseBody public void queryUserInfo(){ System.out.println("================begin=================="); List<UserInfoDO> userList=userInfoService.queryUserInfo();
JSON.toJSONString(userList);
如何输出呢? }
我等待温少的1.1.28。哈
温少,这个问题解决了么?
这个功能在当前的1.1.27版本中还没做好,你来提交一个patch?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
暂无简介
文章 0 评论 0
接受
发布评论
评论(10)
还真是这两个包的问题。
配置好了,访问后出现:
The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers. 是不是还有什么参数没有加上
哈,我自己改源码了。先凑合着用,等温少更新之后,就用他的。
http://code.alibabatech.com/jira/browse/FASTJSON-190
你都配置了转换器了,当然直接return obj就行了
Controller 中如何输出呢。
@RequestMapping(params = "queryUserInfo")
@ResponseBody
public void queryUserInfo(){
System.out.println("================begin==================");
List<UserInfoDO> userList=userInfoService.queryUserInfo();
JSON.toJSONString(userList);
如何输出呢?
}
我等待温少的1.1.28。哈
温少,这个问题解决了么?
这个功能在当前的1.1.27版本中还没做好,你来提交一个patch?