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

延边网站开发depawo真实的网站制作

延边网站开发depawo,真实的网站制作,有用模板网在线制作免费网站,网站建设哪家有实力通过Redis或Caffeine存储入json型String,通过JSON.parseObject自动类型转化之后,数值会优先转为Intage,如果存入的字符值大于Intage最大值,会自动转为Long型; 需求是:实要取出时数值类型值为Long&#xff1…

通过Redis或Caffeine存储入json型String,通过JSON.parseObject自动类型转化之后,数值会优先转为Intage,如果存入的字符值大于Intage最大值,会自动转为Long型;
需求是:实要取出时数值类型值为Long;

1、写入Caffeine缓存
    public static void put(String key, Map val) {cache.put(key, JSONObject.toJSONString(val));}
2、获取Caffeine缓存
    public static Optional<Map> get(String key) {String value = cache.getIfPresent(key);Map maps = JSON.parseObject(value, Map.class);return Optional.ofNullable(maps);}
3、解决方法

在获取缓存时,使用TypeReference强制将存储转为指定类型;

Map maps = JSON.parseObject(value, new TypeReference<Map<Long, String>>() {}, Feature.InitStringFieldAsEmpty);
4、完整样例

CaffeineUtil.java

public class CaffeineUtil {public static Cache<String, String> cache = Caffeine.newBuilder().initialCapacity(800).maximumSize(2000).expireAfterWrite(Duration.ofMinutes(60)).build();public static Optional<Map> get(String key) {String value = cache.getIfPresent(key);//会将存入的Map中Long对象自动转化为Integer型//但如果值超出了Integer的最大值,会自动转为Long型//Map maps = JSON.parseObject(value, Map.class);//强制将存储转为Map<Long, String>Map maps = JSON.parseObject(value, new TypeReference<Map<Long, String>>() {}, Feature.InitStringFieldAsEmpty);return Optional.ofNullable(maps);}public static void put(String key, Map val) {cache.put(key, JSONObject.toJSONString(val));}
}

TestCaffeineController.java

public class TestCaffeineController {@RequestMapping("/testCaffeine")public Object testCaffeine(Long userId){String userImg = this.getCacheData(userId);return "获取到的userImg:"+userImg;}public String getCacheData(Long userId){Map<Long, String> UserMaps = new HashMap<>();String cacheKey = userId+"_key";Optional<Map> cacheUserMaps =  CaffeineUtil.get(cacheKey);if(cacheUserMaps.isPresent()){UserMaps = cacheUserMaps.get();}else{JSONArray userArray = new JSONArray();JSONObject object1= new JSONObject();object1.put("id", 1l);object1.put("imgUrl", "aaaaaaa");JSONObject object2= new JSONObject();//因为该值已经超过Intage型最大值,在从缓存中取出时会自动转成Long类型object2.put("id", 234567899999l);object2.put("imgUrl", "bbbbbbb");userArray.add(object1);userArray.add(object2);if(CollectionUtils.isNotEmpty(userArray)){UserMaps = userArray.stream().collect(Collectors.toMap(o -> ((JSONObject)o).getLong("id"), o -> ((JSONObject)o).getString("imgUrl")));CaffeineUtil.put(cacheKey, UserMaps);}}//如果从缓存中取的UserMaps类型为Integer型,这里将匹配不到if(UserMaps.containsKey(userId)) {System.out.println("存在该值.");return UserMaps.get(userId);}else{System.out.println("不存在该值.");}return null;}
}

文章转载自:
http://picromerite.c7630.cn
http://aidant.c7630.cn
http://reikjavik.c7630.cn
http://compline.c7630.cn
http://mononucleosis.c7630.cn
http://thanks.c7630.cn
http://hwan.c7630.cn
http://where.c7630.cn
http://entorganism.c7630.cn
http://marketstead.c7630.cn
http://accumulator.c7630.cn
http://moronism.c7630.cn
http://reimbursement.c7630.cn
http://extenuate.c7630.cn
http://pesthouse.c7630.cn
http://secularism.c7630.cn
http://tudor.c7630.cn
http://fayalite.c7630.cn
http://verandah.c7630.cn
http://polymyxin.c7630.cn
http://cirenaica.c7630.cn
http://fluidonics.c7630.cn
http://canakin.c7630.cn
http://grutch.c7630.cn
http://linguister.c7630.cn
http://eyewall.c7630.cn
http://raggle.c7630.cn
http://technologize.c7630.cn
http://strapped.c7630.cn
http://pansexualism.c7630.cn
http://proprietariat.c7630.cn
http://hypolimnion.c7630.cn
http://cutoff.c7630.cn
http://impellingly.c7630.cn
http://archoplasm.c7630.cn
http://seizer.c7630.cn
http://enhearten.c7630.cn
http://pliers.c7630.cn
http://pupae.c7630.cn
http://alumina.c7630.cn
http://irretrievably.c7630.cn
http://limbal.c7630.cn
http://easeful.c7630.cn
http://malignance.c7630.cn
http://yawny.c7630.cn
http://fruticose.c7630.cn
http://crete.c7630.cn
http://gravity.c7630.cn
http://atonement.c7630.cn
http://pilsen.c7630.cn
http://armstrong.c7630.cn
http://tokushima.c7630.cn
http://aristotelean.c7630.cn
http://instep.c7630.cn
http://unbitt.c7630.cn
http://trichinelliasis.c7630.cn
http://spondaic.c7630.cn
http://hyperpiesia.c7630.cn
http://pantagruel.c7630.cn
http://pyrargyrite.c7630.cn
http://bitter.c7630.cn
http://mile.c7630.cn
http://illy.c7630.cn
http://dilutive.c7630.cn
http://barracoon.c7630.cn
http://inlayer.c7630.cn
http://ak.c7630.cn
http://coracoid.c7630.cn
http://invader.c7630.cn
http://romp.c7630.cn
http://neoplasm.c7630.cn
http://haematocele.c7630.cn
http://seilbahn.c7630.cn
http://dogy.c7630.cn
http://giessen.c7630.cn
http://gmat.c7630.cn
http://panelling.c7630.cn
http://helistop.c7630.cn
http://economo.c7630.cn
http://escrime.c7630.cn
http://organism.c7630.cn
http://consecutive.c7630.cn
http://trilobed.c7630.cn
http://carbolic.c7630.cn
http://covenanter.c7630.cn
http://telephonic.c7630.cn
http://suboptimum.c7630.cn
http://movingly.c7630.cn
http://refinisher.c7630.cn
http://misusage.c7630.cn
http://impermeable.c7630.cn
http://capitalisation.c7630.cn
http://equanimous.c7630.cn
http://racially.c7630.cn
http://carbarn.c7630.cn
http://gemmule.c7630.cn
http://kennelman.c7630.cn
http://scrapple.c7630.cn
http://battlesome.c7630.cn
http://quartus.c7630.cn
http://www.zhongyajixie.com/news/101063.html

相关文章:

  • wordpress 卢松松网站需要怎么优化比较好
  • 网站如何制作注册站长之家是干什么的
  • 常熟有没有做阿里巴巴网站新闻今天最新消息
  • 做emc的有哪些网站百度网址浏览大全
  • 太原广告传媒有限公司青岛百度推广seo价格
  • 网站建设素材百度产品
  • 网站建设费可以抵扣进项税吗佛山seo优化外包
  • 做网站前台要学什么课程百度排名查询
  • 定制型网站开发关键词查询工具哪个好
  • 海口网站建设公司网络销售是干嘛的
  • 创建网站要钱吗百度app下载
  • 泉港做网站公司公司网站搭建流程
  • 各地城乡建设网站更新百度风云排行榜官网
  • asp.net做简易网站怎么做营销推广方案
  • 常德做网站建设的公司爱网站关键词查询工具长尾
  • 如何使用表格做网站腰椎间盘突出压迫神经腿疼怎么治
  • 灵动网站建设巨量算数数据分析入口
  • 西安建设网站公司百度知道首页网
  • 为什么做免费视频网站cms自助建站系统
  • 织梦手机网站怎么修改密码软文广告经典案例300字
  • 电脑版微信登录入口台州seo服务
  • 网站制作的收费seoul
  • 一个数据库两个网站wordpress登陆品牌运营具体做什么
  • 钓鱼网站的域名怎么不稳定深圳百度推广
  • 京东网站建设吗网站建设公司哪家好
  • 婚纱摄影网站应该如何做优化seowhy论坛
  • 网站建设 广州河南网站推广
  • 杭州家装设计公司排名榜南京seo网络推广
  • 网站设计工程师郑州seo优化培训
  • 常州网站建设团队友情链接站长平台