/** * 系统管理模块启动类 */ @SpringBootApplication @EnableDiscoveryClient ++++++++++++++1 @EnableCaching // 开启注解式缓存(默认使用的缓存中间件是redis) public class ManagerServiceApplication { public static void main(String[] args) { SpringApplication.run(ManagerServiceApplication.class,args); } /** * Spring Security框架中的密码加密器 * @return */ @Bean public BCryptPasswordEncoder passwordEncoder() { return new BCryptPasswordEncoder(); } }
2
@Service +++++2 @CacheConfig(cacheNames = "com.powernode.service.impl.SysRoleServiceImpl") public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> implements SysRoleService{ @Autowired private SysRoleMapper sysRoleMapper; @Autowired private SysRoleMenuService sysRoleMenuService; @Autowired private SysRoleMenuMapper sysRoleMenuMapper; /** * 查询的是系统中所有角色数据(全量查询) * 全量查询是需要将数据存放到缓存中 * * @return */ @Override +++++++++++3 @Cacheable(key = ManagerConstants.SYS_ALL_ROLE_KEY) public List<SysRole> querySysRoleList() { return sysRoleMapper.selectList(new LambdaQueryWrapper<SysRole>() .orderByDesc(SysRole::getCreateTime) ); }
}
+++++++++4
public interface ManagerConstants { /** * 系统所有角色数据存放到redis中的KEY */ String SYS_ALL_ROLE_KEY = "'roles'"; /** * 系统所有权限数据存放到redis中的KEY */ String SYS_ALL_MENU_KEY = "'menus'"; }