public class MessageConverter extends AbstractHttpMessageConverter {
@Override
protected boolean supports(Class<?> clazz) {
return true;
}
public MessageConverter() {
super(MediaType.ALL);
}
@Override
protected Object readInternal(Class<?> aClass, HttpInputMessage httpInputMessage) throws IOException, HttpMessageNotReadableException {
return null;
}
@Override
protected void writeInternal(Object o, HttpOutputMessage httpOutputMessage) throws IOException {
if (o instanceof ResultBody) {
FileCopyUtils.copy(JSON.toJSONString(o).getBytes(), httpOutputMessage.getBody());
} else {
ResultBody body = new ResultBody(o);
FileCopyUtils.copy(JSON.toJSONString(body).getBytes(), httpOutputMessage.getBody());
}
}
}
@RequestMapping(value = "demo3", method = RequestMethod.GET)
@SystemType(Constants.SYSTEM_PLATFORM)
@NoNeedLogin
String demo3(@RequestParam(value = "str") String str) {
System.out.println(str);
return null;
}
直接返回null的话就不走writeInternal函数。
返回值之类为void时,也一样的