Version: Next
Shiro实现退出登录
退出登录
- 修改shiro filter
//添加退出登录功能
filterChainDefinitionMap.put("/logout","logout");
- Controller定义
/logout路由SecurityUtils获取当前用户,调用logout方法- 重定向到主页或者登录页
@RequestMapping("/logout")
public String logout() {
Subject currentSubject = SecurityUtils.getSubject();
currentSubject.logout();
return "index";
}
- 在页面上放置
退出登录标签- 利用shiro-freemarker标签实现只有登录用户才能看到
退出登录按钮
- 利用shiro-freemarker标签实现只有登录用户才能看到
<@shiro.authenticated>
<h1><a href="/logout">退出登录</a> </h1>
</@shiro.authenticated>
