Commit d432240e by stylefeng

工具类加上渲染工具类

parent ab2aed47
......@@ -8,6 +8,11 @@ package com.stylefeng.guns.core.exception;
public enum GunsExceptionEnum {
/**
* 其他
*/
WRITE_ERROR(500,"渲染界面错误"),
/**
* 文件上传
*/
FILE_READING_ERROR(400,"FILE_READING_ERROR!"),
......
package com.stylefeng.guns.core.util;
import com.alibaba.fastjson.JSON;
import com.stylefeng.guns.core.exception.GunsException;
import com.stylefeng.guns.core.exception.GunsExceptionEnum;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
/**
* 渲染工具类
*
* @author fengshuonan
* @date 2017-08-25 14:13
*/
public class RenderUtil {
/**
* 渲染json对象
*/
public static void renderJson(HttpServletResponse response, Object jsonObject) {
try {
response.setCharacterEncoding("UTF-8");
PrintWriter writer = response.getWriter();
writer.write(JSON.toJSONString(jsonObject));
} catch (IOException e) {
throw new GunsException(GunsExceptionEnum.WRITE_ERROR);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment