SecurityUtils 工具类笔记
SecurityUtils 类
package com.cloud.wl.hp.config.utils;
import com.cloud.wl.hp.base.common.mapper.JsonMapperUtil;
import com.cloud.wl.hp.base.dto.RestResultDTO;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* @author wanglin
* @version 1.0
* @date 2022-01-19 周三
*/
public class SecurityUtils {
/**
* security 统一返回信息处理
*
* @param response
* @param code
* @param msg
* @throws IOException
*/
public static void resultSuccessMsg(HttpServletResponse response, Integer code, Object data, String msg) throws IOException {
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Cache-Control", "no-cache");
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json; charset=utf-8");
response.setStatus(code);
RestResultDTO result = new RestResultDTO<>(code, msg, data, null);
response.getWriter().write(JsonMapperUtil.toJson(result));
response.getWriter().flush();
}
/**
* security 统一返回信息处理
*
* @param response
* @param code
* @param msg
* @param exceptionMsg
* @throws IOException
*/
public static void resultFailMsg(HttpServletResponse response, Integer code, String msg, String exceptionMsg) throws IOException {
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Cache-Control", "no-cache");
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json; charset=utf-8");
response.setStatus(code);
RestResultDTO result = new RestResultDTO<>(code, msg, null, exceptionMsg);
response.getWriter().write(JsonMapperUtil.toJson(result));
response.getWriter().flush();
}
/**
* security 统一返回信息处理
*
* @param response
* @param code
* @param msg
* @throws IOException
*/
public static void resultFailMsg(HttpServletResponse response, Integer code, String msg) throws IOException {
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Cache-Control", "no-cache");
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json; charset=utf-8");
response.setStatus(code);
RestResultDTO result = new RestResultDTO<>(code, msg, null, null);
response.getWriter().write(JsonMapperUtil.toJson(result));
response.getWriter().flush();
}
/**
* security 统一返回信息处理
*
* @param response
* @param msg
* @throws IOException
*/
public static void resultFailMsg(HttpServletResponse response, String msg) throws IOException {
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Cache-Control", "no-cache");
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json; charset=utf-8");
RestResultDTO result = new RestResultDTO<>(0, msg, null, null);
response.getWriter().write(JsonMapperUtil.toJson(result));
response.getWriter().flush();
}
}
关注林哥,持续更新哦!!!★,°:.☆( ̄▽ ̄)/$:.°★ 。