spring清空缓存标签;
http://sishuok.com/forum/blogPost/list/7952.html
@CacheEvict:主要对方法配置,用来标记要清空缓存的方法,当这个方法被调用并满足一定条件后,即会清空缓存。
value:缓存的位置,不能为空。
key:缓存的key,默认为空。
condition:触发的条件,只有满足条件的情况才会清楚缓存,默认为空,支持SpEL。
allEntries:true表示清除value中的全部缓存,默认为false。(有这个就不用指定key,一个value是存多个key的地点)
@CacheEvict(value = "user", allEntries = true)
用缓存标签的时候需要在调用更新的方法的时候,更新缓存
@Override
@Cacheable(value="getRoleLimt",key="'getRoleLimt='+#o.roleid")
public List
// TODO Auto-generated method stub
return opmRolelimitMapper.select(o);
}
@Override
@Transactional(rollbackFor=Exception.class)
@CacheEvict(value="getRoleLimt", allEntries = true)
public int updateRole(OpmRole opmRole,List
// TODO Auto-generated method stub
System.out.println("==========================213213213===================");
if("".equals(opmRole.getOrganid())||null==opmRole.getOrganid()){
throw new Exception("传入参数为空!");
}
TbCusMark tbCusMark = new TbCusMark();
tbCusMark.setMarketKey(BigDecimal.valueOf(Long.valueOf(opmRole.getOrganid())));
TbCusMark mark= tbCusMarkMapper.selectOne(tbCusMark);
if(mark==null){
throw new Exception("交易市场找不到!");
}
OpmRole role =new OpmRole();
if(opmRole.getId()==null||"".equals(opmRole.getId())){
role.setOrganid(opmRole.getOrganid());
role.setLevel1(Short.valueOf("0"));
role.setName(opmRole.getName());
role.setMemo(opmRole.getMemo());
opmRoleMapper.insert(role);
}else{
OpmRolelimit opmRolelimit = new OpmRolelimit();
opmRolelimit.setRoleid(opmRole.getId());
opmRolelimitMapper.delete(opmRolelimit);
opmRoleMapper.updateByPrimaryKeySelective(opmRole);
}
OpmMenuitemlimit opmMenuitemlimit = new OpmMenuitemlimit();
List
OpmMenuitem item = new OpmMenuitem();
List
try{
for(String l :list){
OpmRolelimit opmLimt = new OpmRolelimit();
int up=0;
for(OpmMenuitem i: items){
if(i.getId().equals(l)){
opmLimt.setMenuitemid(i.getId());
opmLimt.setDisplayorder(-1L);
opmLimt.setName("查看");
if(opmRole.getId()==null||"".equals(opmRole.getId())){
opmLimt.setRoleid(role.getId());
up= opmRolelimitMapper.insert(opmLimt);
}else{
opmLimt.setRoleid(opmRole.getId());
up= opmRolelimitMapper.insert(opmLimt);
}
break;
}
}
if(up==0){
for(OpmMenuitemlimit lm : opmLimits){
if(lm.getId().equals(l)){
opmLimt.setMenuitemid(lm.getMenuitemid());
opmLimt.setDisplayorder(lm.getDisplayorder());
opmLimt.setName(lm.getName());
opmLimt.setMenuitemlimitid(lm.getId());
opmLimt.setDisplayorder(lm.getDisplayorder());
opmLimt.setName(lm.getName());
String org= opmRole.getOrganid();
if(opmRole.getId()==null||"".equals(opmRole.getId())){
opmLimt.setRoleid(role.getId());
up= opmRolelimitMapper.insert(opmLimt);
}else{
opmLimt.setRoleid(opmRole.getId());
opmRolelimitMapper.insert(opmLimt);
}
break;
}
}
}
}
}catch(Exception e){
throw new Exception("保存角色异常!");
}
return 1;
}