这个项目写到现在,基本的雏形出来了,在此感谢一直关注的童鞋,送你们一句最近刚学习的一句鸡汤:念念不忘,必有回响。再贴一张ui图片:
·······················································································································································
此项目下载地址:https://git.oschina.net/z77z/springboot_mybatisplus
·······················································································································································
前篇思考问题解决
- 前篇我们只是完成了同一账户的登录人数限制shiro拦截器的编写,对于手动踢出用户的功能只是说了采用在session域中添加一个key为kickout的布尔值,由之前编写的KickoutSessionControlFilter拦截器来判断是否将用户踢出,还没有说怎么获取当前在线用户的列表的核心代码,下面贴出来:
/**
* <p>
* 服务实现类
* </p>
*
* @author z77z
* @since 2017-02-10
*/
@Service
public class SysUserService extends ServiceImpl<SysUserMapper, SysUser> {
@Autowired
RedisSessionDAO redisSessionDAO;
public Page<UserOnlineBo> getPagePlus(FrontPage<UserOnlineBo> frontPage) {
// 因为我们是用redis实现了shiro的session的Dao,而且是采用了shiro+redis这个插件
// 所以从spring容器中获取redisSessionDAO
// 来获取session列表.
Collection<Session> sessions = redisSessionDAO.getActiveSessions();
Iterator<Session> it = sessions.iterator();
List<UserOnlineBo> onlineUserList = new ArrayList<UserOnlineBo>();
Page<UserOnlineBo> pageList = frontPage.getPagePlus();
// 遍历session
while (it.hasNext()) {
// 这是shiro已经存入session的
// 现在直接取就是了
Session session = it.next();
// 如果被标记为踢出就不显示
Object obj = session.getAttribute("kickout");
if (obj != null)
continue;
UserOnlineBo onlineUser = getSessionBo(session);
onlineUserList.add(onlineUser);
}
// 再将List<UserOnlineBo>转换成mybatisPlus封装的page对象
int page = frontPage.getPage() - 1;
int rows = frontPage.getRows() - 1;
int startIndex = page * rows;
int endIndex = (page * rows) + rows;