菜鸟新手,常用的方法保存一下,方便使用
protected void responseOutWithJson(HttpServletResponse response, Object responseObject) {
//将实体对象转换为JSON Object转换
JSONObject responseJSONObject = JSONObject.fromObject(responseObject);
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json; charset=utf-8");
PrintWriter out = null;
try {
out = response.getWriter();
out.append(responseJSONObject.toString());
logger.debug("返回是\n");
logger.debug(responseJSONObject.toString());
} catch (IOException e) {
e.printStackTrace();
} finally {
if (out != null) {
out.close();
}
}
}
更多内容请关注公众号查看