任何身份都可以进入主页 但是不是谁都可以评论
if (request.getSession().getAttribute("user") != null) { comment.setCommentRole(Role.ADMIN.getValue()); } else { comment.setCommentRole(Role.VISITOR.getValue()); } comment.setCommentAuthorAvatar(MyUtils.getGravatar(comment.getCommentAuthorEmail()));在拦截器中不同的用户进入到不同的界面:
@Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object o) throws IOException { //这里可以根据session的用户来判断角色的权限,根据权限来转发不同的页面 if(request.getSession().getAttribute("user") == null) { response.sendRedirect("/login"); return false; } return true; }