Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
guns-vip
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
chenjunxiong
guns-vip
Commits
3e72d632
Commit
3e72d632
authored
Apr 25, 2017
by
fsn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改ConstantFactory缓存的key的策略
parent
0c0cef90
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
31 additions
and
13 deletions
+31
-13
src/main/java/com/stylefeng/guns/common/constant/cache/Cache.java
+1
-1
src/main/java/com/stylefeng/guns/common/constant/cache/CacheKey.java
+23
-0
src/main/java/com/stylefeng/guns/common/constant/factory/ConstantFactory.java
+7
-6
src/main/java/com/stylefeng/guns/modular/system/dao/DictDao.java
+0
-3
src/test/java/com/stylefeng/guns/cache/CacheTest.java
+0
-3
No files found.
src/main/java/com/stylefeng/guns/common/constant/Cache.java
→
src/main/java/com/stylefeng/guns/common/constant/
cache/
Cache.java
View file @
3e72d632
package
com
.
stylefeng
.
guns
.
common
.
constant
;
package
com
.
stylefeng
.
guns
.
common
.
constant
.
cache
;
/**
/**
* 所有缓存名称的集合
* 所有缓存名称的集合
...
...
src/main/java/com/stylefeng/guns/common/constant/cache/CacheKey.java
0 → 100644
View file @
3e72d632
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_"
;
}
src/main/java/com/stylefeng/guns/common/constant/factory/ConstantFactory.java
View file @
3e72d632
package
com
.
stylefeng
.
guns
.
common
.
constant
.
factory
;
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.ManagerStatus
;
import
com.stylefeng.guns.common.constant.state.MenuStatus
;
import
com.stylefeng.guns.common.constant.state.MenuStatus
;
import
com.stylefeng.guns.common.constant.state.Sex
;
import
com.stylefeng.guns.common.constant.state.Sex
;
...
@@ -29,14 +30,14 @@ public class ConstantFactory {
...
@@ -29,14 +30,14 @@ public class ConstantFactory {
private
RoleMapper
roleMapper
=
SpringContextHolder
.
getBean
(
RoleMapper
.
class
);
private
RoleMapper
roleMapper
=
SpringContextHolder
.
getBean
(
RoleMapper
.
class
);
private
DeptMapper
deptMapper
=
SpringContextHolder
.
getBean
(
DeptMapper
.
class
);
private
DeptMapper
deptMapper
=
SpringContextHolder
.
getBean
(
DeptMapper
.
class
);
public
static
ConstantFactory
me
(){
public
static
ConstantFactory
me
()
{
return
SpringContextHolder
.
getBean
(
"constantFactory"
);
return
SpringContextHolder
.
getBean
(
"constantFactory"
);
}
}
/**
/**
* 通过角色ids获取角色名称
* 通过角色ids获取角色名称
*/
*/
@Cacheable
(
Cache
.
CONSTANT
)
@Cacheable
(
value
=
Cache
.
CONSTANT
,
key
=
"'"
+
CacheKey
.
ROLES_NAME
+
"'+#roleIds"
)
public
String
getRoleName
(
String
roleIds
)
{
public
String
getRoleName
(
String
roleIds
)
{
Integer
[]
roles
=
Convert
.
toIntArray
(
roleIds
);
Integer
[]
roles
=
Convert
.
toIntArray
(
roleIds
);
StringBuilder
sb
=
new
StringBuilder
();
StringBuilder
sb
=
new
StringBuilder
();
...
@@ -52,7 +53,7 @@ public class ConstantFactory {
...
@@ -52,7 +53,7 @@ public class ConstantFactory {
/**
/**
* 通过角色id获取角色名称
* 通过角色id获取角色名称
*/
*/
@Cacheable
(
Cache
.
CONSTANT
)
@Cacheable
(
value
=
Cache
.
CONSTANT
,
key
=
"'"
+
CacheKey
.
SINGLE_ROLE_NAME
+
"'+#roleId"
)
public
String
getSingleRoleName
(
Integer
roleId
)
{
public
String
getSingleRoleName
(
Integer
roleId
)
{
if
(
0
==
roleId
)
{
if
(
0
==
roleId
)
{
return
"--"
;
return
"--"
;
...
@@ -67,7 +68,7 @@ public class ConstantFactory {
...
@@ -67,7 +68,7 @@ public class ConstantFactory {
/**
/**
* 通过角色id获取角色英文名称
* 通过角色id获取角色英文名称
*/
*/
@Cacheable
(
Cache
.
CONSTANT
)
@Cacheable
(
value
=
Cache
.
CONSTANT
,
key
=
"'"
+
CacheKey
.
SINGLE_ROLE_TIP
+
"'+#roleId"
)
public
String
getSingleRoleTip
(
Integer
roleId
)
{
public
String
getSingleRoleTip
(
Integer
roleId
)
{
if
(
0
==
roleId
)
{
if
(
0
==
roleId
)
{
return
"--"
;
return
"--"
;
...
@@ -82,7 +83,7 @@ public class ConstantFactory {
...
@@ -82,7 +83,7 @@ public class ConstantFactory {
/**
/**
* 获取部门名称
* 获取部门名称
*/
*/
@Cacheable
(
Cache
.
CONSTANT
)
@Cacheable
(
value
=
Cache
.
CONSTANT
,
key
=
"'"
+
CacheKey
.
DEPT_NAME
+
"'+#deptId"
)
public
String
getDeptName
(
Integer
deptId
)
{
public
String
getDeptName
(
Integer
deptId
)
{
Dept
dept
=
deptMapper
.
selectById
(
deptId
);
Dept
dept
=
deptMapper
.
selectById
(
deptId
);
if
(
ToolUtil
.
isNotEmpty
(
dept
)
&&
ToolUtil
.
isNotEmpty
(
dept
.
getFullname
()))
{
if
(
ToolUtil
.
isNotEmpty
(
dept
)
&&
ToolUtil
.
isNotEmpty
(
dept
.
getFullname
()))
{
...
...
src/main/java/com/stylefeng/guns/modular/system/dao/DictDao.java
View file @
3e72d632
package
com
.
stylefeng
.
guns
.
modular
.
system
.
dao
;
package
com
.
stylefeng
.
guns
.
modular
.
system
.
dao
;
import
com.stylefeng.guns.common.constant.Cache
;
import
com.stylefeng.guns.persistence.model.Dict
;
import
com.stylefeng.guns.persistence.model.Dict
;
import
org.apache.ibatis.annotations.Param
;
import
org.apache.ibatis.annotations.Param
;
import
org.springframework.cache.annotation.Cacheable
;
import
java.util.List
;
import
java.util.List
;
...
@@ -22,6 +20,5 @@ public interface DictDao {
...
@@ -22,6 +20,5 @@ public interface DictDao {
* @return
* @return
* @date 2017年2月13日 下午11:11:28
* @date 2017年2月13日 下午11:11:28
*/
*/
@Cacheable
(
Cache
.
CONSTANT
)
public
List
<
Dict
>
selectByCode
(
@Param
(
"code"
)
String
code
);
public
List
<
Dict
>
selectByCode
(
@Param
(
"code"
)
String
code
);
}
}
src/test/java/com/stylefeng/guns/cache/CacheTest.java
View file @
3e72d632
...
@@ -54,9 +54,6 @@ public class CacheTest extends BaseTest{
...
@@ -54,9 +54,6 @@ public class CacheTest extends BaseTest{
System
.
out
.
println
();
System
.
out
.
println
();
System
.
out
.
println
();
System
.
out
.
println
();
Object
constant
=
CacheKit
.
get
(
"CONSTANT"
,
1
);
System
.
out
.
println
(
constant
);
List
constant1
=
CacheKit
.
getKeys
(
"CONSTANT"
);
List
constant1
=
CacheKit
.
getKeys
(
"CONSTANT"
);
System
.
out
.
println
(
JSON
.
toJSONString
(
constant1
));
System
.
out
.
println
(
JSON
.
toJSONString
(
constant1
));
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment