shiro权限不足自定义响应数据
1.创建一个类,比如叫ShoirPermissionResponse,先捕获异常,然后输出自定义错误信息
/**
* 权限不足
*
* @param response
* @return
*/
@ExceptionHandler({ UnauthorizedException.class, AuthorizationException.class })
public void authorizationException(HttpServletResponse response) {
Map<String, Object> map = new HashMap<>();
map.put("code", "403");
map.put("msg", "用户权限不足");
try {
PrintWriter out = null;
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json; charset=utf-8");
out = response.getWriter();
out.write(JSONObject.toJSONString(map));
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
2.然后在要加权限的控制层继承ShoirPermissionResponse,就可以了😀