示例#1
0
 /**
  * 根据ID获取用户
  *
  * @param id
  * @return 取不到返回null
  */
 public static User get(String id) {
   User user = (User) CacheUtils.get(USER_CACHE, USER_CACHE_ID_ + id);
   if (user == null) {
     user = userDao.selectOne(id);
     if (user == null) {
       return null;
     }
     user.setRoleList(roleDao.findList(new Role(user)));
     CacheUtils.put(USER_CACHE, USER_CACHE_ID_ + user.getId(), user);
     CacheUtils.put(USER_CACHE, USER_CACHE_LOGIN_NAME_ + user.getLoginName(), user);
   }
   return user;
 }
示例#2
0
 /**
  * 根据登录名获取用户
  *
  * @param loginName
  * @return 取不到返回null
  */
 public static User getByLoginName(String loginName) {
   User user = (User) CacheUtils.get(USER_CACHE, USER_CACHE_LOGIN_NAME_ + loginName);
   if (user == null) {
     User queryUser = new User();
     queryUser.setLoginName(loginName);
     ;
     user = userDao.getByLoginName(queryUser);
     if (user == null) {
       return null;
     }
     user.setRoleList(roleDao.findList(new Role(user)));
     CacheUtils.put(USER_CACHE, USER_CACHE_ID_ + user.getId(), user);
     CacheUtils.put(USER_CACHE, USER_CACHE_LOGIN_NAME_ + user.getLoginName(), user);
   }
   return user;
 }
示例#3
0
 /**
  * 写入SYS_CACHE缓存
  *
  * @param key
  * @return
  */
 public static void put(String key, Object value) {
   put(SYS_CACHE, key, value);
 }