Commit 3e72d632 by fsn

修改ConstantFactory缓存的key的策略

parent 0c0cef90
package com.stylefeng.guns.common.constant;
package com.stylefeng.guns.common.constant.cache;
/**
* 所有缓存名称的集合
......
package com.stylefeng.guns.common.constant.cache;
/**
* 缓存的key集合
*
* @author fengshuonan
* @date 2017-04-25 9:37
*/
public interface CacheKey {
/**
* ConstantFactory中的缓存
*/
String ROLES_NAME = "roles_name_";
String SINGLE_ROLE_NAME = "single_role_name_";
String SINGLE_ROLE_TIP = "single_role_tip_";
String DEPT_NAME = "dept_name_";
}
package com.stylefeng.guns.common.constant.factory;
import com.stylefeng.guns.common.constant.Cache;
import com.stylefeng.guns.common.constant.cache.Cache;
import com.stylefeng.guns.common.constant.cache.CacheKey;
import com.stylefeng.guns.common.constant.state.ManagerStatus;
import com.stylefeng.guns.common.constant.state.MenuStatus;
import com.stylefeng.guns.common.constant.state.Sex;
......@@ -29,14 +30,14 @@ public class ConstantFactory {
private RoleMapper roleMapper = SpringContextHolder.getBean(RoleMapper.class);
private DeptMapper deptMapper = SpringContextHolder.getBean(DeptMapper.class);
public static ConstantFactory me(){
public static ConstantFactory me() {
return SpringContextHolder.getBean("constantFactory");
}
/**
* 通过角色ids获取角色名称
*/
@Cacheable(Cache.CONSTANT)
@Cacheable(value = Cache.CONSTANT, key = "'" + CacheKey.ROLES_NAME + "'+#roleIds")
public String getRoleName(String roleIds) {
Integer[] roles = Convert.toIntArray(roleIds);
StringBuilder sb = new StringBuilder();
......@@ -52,7 +53,7 @@ public class ConstantFactory {
/**
* 通过角色id获取角色名称
*/
@Cacheable(Cache.CONSTANT)
@Cacheable(value = Cache.CONSTANT, key = "'" + CacheKey.SINGLE_ROLE_NAME + "'+#roleId")
public String getSingleRoleName(Integer roleId) {
if (0 == roleId) {
return "--";
......@@ -67,7 +68,7 @@ public class ConstantFactory {
/**
* 通过角色id获取角色英文名称
*/
@Cacheable(Cache.CONSTANT)
@Cacheable(value = Cache.CONSTANT, key = "'" + CacheKey.SINGLE_ROLE_TIP + "'+#roleId")
public String getSingleRoleTip(Integer roleId) {
if (0 == roleId) {
return "--";
......@@ -82,7 +83,7 @@ public class ConstantFactory {
/**
* 获取部门名称
*/
@Cacheable(Cache.CONSTANT)
@Cacheable(value = Cache.CONSTANT, key = "'" + CacheKey.DEPT_NAME + "'+#deptId")
public String getDeptName(Integer deptId) {
Dept dept = deptMapper.selectById(deptId);
if (ToolUtil.isNotEmpty(dept) && ToolUtil.isNotEmpty(dept.getFullname())) {
......
package com.stylefeng.guns.modular.system.dao;
import com.stylefeng.guns.common.constant.Cache;
import com.stylefeng.guns.persistence.model.Dict;
import org.apache.ibatis.annotations.Param;
import org.springframework.cache.annotation.Cacheable;
import java.util.List;
......@@ -22,6 +20,5 @@ public interface DictDao {
* @return
* @date 2017年2月13日 下午11:11:28
*/
@Cacheable(Cache.CONSTANT)
public List<Dict> selectByCode(@Param("code") String code);
}
......@@ -54,9 +54,6 @@ public class CacheTest extends BaseTest{
System.out.println();
System.out.println();
Object constant = CacheKit.get("CONSTANT", 1);
System.out.println(constant);
List constant1 = CacheKit.getKeys("CONSTANT");
System.out.println(JSON.toJSONString(constant1));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment