当前位置: 首页 > news >正文

自己什么建设网站dz网站标题

自己什么建设网站,dz网站标题,店务系统,深圳外贸集团项目中,用于缓存姓名、地名、单位名称等一些较固定名称的id-name小组件。用于减少一些表的关连操作和冗余字段。优化代码结构。扩展也方便,写不同的枚举就行了。 具体用法: {NameCacheUser.USER.getName(userId);NameCacheUser.ACCOUNT.getN…

项目中,用于缓存姓名、地名、单位名称等一些较固定名称的id-name小组件。用于减少一些表的关连操作和冗余字段。优化代码结构。扩展也方便,写不同的枚举就行了。
具体用法:

{NameCacheUser.USER.getName(userId);NameCacheUser.ACCOUNT.getName(accountId);NameCacheUser.OFFICE.getName(officeId);
}
public enum NameCacheUser implements NameCacheBee {USER(userId -> {UserMapper userMapper = ZYSpringUtils.getBean(UserMapper.class);User user = userMapper.selectById(userId);return null != user ? user.getUserName() : null;}),ACCOUNT(accountId -> {UserAccountMapper userMapper = ZYSpringUtils.getBean(UserAccountMapper.class);UserAccount user = userMapper.selectById(accountId);return null != user ? user.getUserName() : null;}),OFFICE(officeId -> {OfficeMapper officeMapper = ZYSpringUtils.getBean(OfficeMapper.class);Office office = officeMapper.selectById(officeId);return null != office ? office.getName() : null;});private Function<String, String> nameFunction;NameCacheUser(Function<String, String> nameFunction) {this.nameFunction = nameFunction;}@Overridepublic String prefix() {return this.name().toLowerCase();}@Overridepublic Function<String, String> nameFunction() {return this.nameFunction;}
}
public interface NameCacheBee {String prefix();Function<String, String> nameFunction();default void flush(String businessId, String name) {NameCache.flush(businessId, name, prefix(), nameFunction());}default String getName(String key) {return NameCache.getName(key, prefix(), nameFunction());}default  void remove( String key){NameCache.remove(prefix(), key);}default   void remove(List<String> keys){NameCache.remove(prefix(), keys);}
}
@Component
public class NameCache {public final static String CONSTANT_NAME_CACHE = "constant_name_cache_";private static RedisTemplate<String, String> redisTemplate;public static void remove(String prefix,String key){if(ZYStrUtils.isNotNull(key)){remove(prefix,Collections.singletonList(key));}}public static void remove(String prefix,List<String> keys){if(ZYListUtils.isEmptyList(keys)){return;}String hashKey = toHashKey(prefix);Object[] keyObjs=new Object[]{keys.size()};for (int i=0;i<keyObjs.length;i++){keyObjs[i]=keys.get(i);}redisTemplate.opsForHash().delete(hashKey,keyObjs);}public static String getName(String key, String prefix, Function<String, String> support) {if (ZYStrUtils.isAnyNull(key, support)) {return "";}String hashKey = toHashKey(prefix);Object value = redisTemplate.opsForHash().get(hashKey, key);if (ZYStrUtils.isNotNull(value)) {return String.valueOf(value);}String name = support.apply(key);if (ZYStrUtils.isNotNull(name)) {redisTemplate.opsForHash().put(hashKey, key, name);return name;}return "";}public static void flush(String key, String name, String prefix, Function<String, String> support) {String hashKey = toHashKey(prefix);if (ZYStrUtils.isNotNull(name)) {redisTemplate.opsForHash().put(hashKey, key, name);} else {String findName = support.apply(key);if (ZYStrUtils.isNotNull(findName)) {redisTemplate.opsForHash().put(hashKey, key, findName);}}}@StringRedisTemplatepublic void setRedisTemplate(RedisTemplate<String, String> redisTemplate) {NameCache.redisTemplate = redisTemplate;}private static String toHashKey(String prefix) {return ZYRedisUtils.wrapperKey(CONSTANT_NAME_CACHE + prefix).toLowerCase();}}

在缓存中的效果:
![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/868531a473f241e4bf9d7d83bfb551c3.png

在这里插入图片描述
在这里插入图片描述

http://www.yayakq.cn/news/504737/

相关文章:

  • 做公司网站有什么好处网站建设与推广实训心得
  • 网站开发总结性报告长沙网站优化公司
  • 石家庄网站建设专家订阅号 wordpress
  • 如何让做网站公司网站建设多少费用哪里济南兴田德润有活动吗
  • 网站公司建设网站价格峰峰信息港邯郸信息港
  • 企业网站设计html做旅游网站的yi
  • 企业网站案例欣赏谷德设计网展示设计
  • 做交易网站国家企业信用信息系统(河南)
  • 淘宝网站建设特点龙岗网站建设需要考量些什么
  • 有没有找客户的网站wordpress自定义搜索
  • 网站建设需要确定的问题如何跟帖做网站
  • 对电子商务网站与建设的心得教育类网站怎么做
  • 东营网站建设哪家专业网站文件验证
  • 广东省建设业协会网站化工网站源码
  • 西安营销网站舆情分析是什么
  • 商务网站建设的第一步wordpress空间转服务器
  • 宿迁做网站哪家好wordpress免费企业模板下载
  • 网站建设要咨询哪些内容网页设计一般怎么收费
  • 公司网站域名解析谁来做校友录网站开发设计
  • 资料共享的网站开发wordpress目录结构分析
  • dw做响应式网站网站关键词设置多少合适
  • 网站佣金怎么做凭证网站建设公司好做吗
  • 怎么建设手机小说网站做高性能的网站 哪门语言好
  • 黄石建网站保定百度推广优化排名
  • 做电影网站用什么格式好网站开发是分为前端和后端吗
  • 网站备案logo域名解析怎么做
  • html企业网站模板下载自学做网站要学什么
  • 爱站网挖掘词设计师用的装修设计软件
  • 多个网站给一个网站推广最好的微网站建设公司推荐
  • 网站后台配置wordpress客户端 接口