public static String createSuccessResponse(Integer httpCode, String message, Object result, SerializerFeature serializerFeature, SerializeFilter filter, HttpServletResponse response){
PrintWriter printWriter = null;
String jsonString = "";
try {
response.setCharacterEncoding(RESPONSE_CHARACTERENCODING);
response.setContentType(RESPONSE_CONTENTTYPE);
response.setStatus(httpCode);
printWriter = response.getWriter();
SerializeConfig config = new SerializeConfig();
config.put(Date.class, new SimpleDateFormatSerializer("yyyy-MM-dd"));
Map<String, Object> map = new HashMap<String, Object>();
if(null != result){
map.put("res_code", httpCode);
map.put("message", message);
map.put("data",result);
if(null!=filter){
jsonString = JSONObject.toJSONString(map,filter,serializerFeature);
}else{
// jsonString = JSONObject.toJSONString(map,config,serializerFeature);
jsonString = JSONObject.toJSONStringWithDateFormat(map,"yyyy-MM-dd");
}
printWriter.write(jsonString);
}
printWriter.flush();
} catch (Exception e) {
log.error("createResponse failed", e);
} finally {
if(null!=printWriter)printWriter.close();
}
return jsonString;
}
ServletUtil.java 文件源码
java
阅读 40
收藏 0
点赞 0
评论 0
项目:spring-boot-frameset
作者:
评论列表
文章目录