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

wordpress如何备份 网站wordpress 安装 此网页包含重定向循环

wordpress如何备份 网站,wordpress 安装 此网页包含重定向循环,凡客诚品陈年女儿,建设银行采购网站背景#xff1a; Lombok 这个插件大家日常工作中几乎是必备的#xff0c;几个简单的注解就可以帮助我们减少一大坨get/set方法等#xff1b;其中Builder注解使用的也很广泛#xff0c;使用了建造者模式帮助我们构建出个性化的对象#xff0c;本次踩坑点就在这个地方。 先… 背景 Lombok 这个插件大家日常工作中几乎是必备的几个简单的注解就可以帮助我们减少一大坨get/set方法等其中Builder注解使用的也很广泛使用了建造者模式帮助我们构建出个性化的对象本次踩坑点就在这个地方。 先讲一下踩坑的大致流程在一个需求中需要对接口内部的一个上下文对象 增加一个属性Map而这个上下文对象在别的接口中也有使用那就需要兼容其他接口所以我给这个新增的Map属性增加一个默认值 MapObject,Object map Maps.newHashMap() 然而还是获取这个属性的时候发生了异常原因就在当前类上面的Builder注解下文会举一个例子具体说明一下。 举例 package com.shizhuang.duapp.nbinterface.interfaces.facade;import com.google.common.collect.Maps; import lombok.Builder; import lombok.Getter;import java.util.Map;Getter Builder public class CommodityModel {private String title;private Long brandId;private Integer channelCode;private MapString,Long extraInfoMap Maps.newHashMap();public static void main(String[] args) {CommodityModel model CommodityModel.builder().brandId(100L).title(NB 新百伦).build();Object price model.getExtraInfoMap().getOrDefault(price, 100L);System.out.println(price: price);} }问题来了如上代码直接执行main方法是否会打印出 price: 100 答案分割图 嗯哼答案是大家贼熟悉的 NPE 看到这NPE肯定是 extraInfoMap 这个属性是Null 但是我们明明给了一个默认值嘛为啥子会是Null 呢答案就在编译后的代码中如下着重关注标记的代码 // // Source code recreated from a .class file by IntelliJ IDEA // (powered by FernFlower decompiler) // package com.shizhuang.duapp.nbinterface.interfaces.facade;import com.google.common.collect.Maps; import java.util.Map;public class CommodityModel {private String title;private Long brandId;private Integer channelCode;private MapString, Long extraInfoMap Maps.newHashMap();public static void main(String[] args) {CommodityModel model builder().brandId(100L).title(NB 新百伦).build();Object price model.getExtraInfoMap().getOrDefault(price, 100L);System.out.println(price: price);}CommodityModel(String title, Long brandId, Integer channelCode, MapString, Long extraInfoMap) {this.title title;this.brandId brandId;this.channelCode channelCode;this.extraInfoMap extraInfoMap;}//方法1public static CommodityModelBuilder builder() {return new CommodityModelBuilder();}--- 省略Get方法 ---public static class CommodityModelBuilder {private String title;private Long brandId;private Integer channelCode;private MapString, Long extraInfoMap;CommodityModelBuilder() {}//方法2public CommodityModelBuilder title(String title) {this.title title;return this;}//方法3public CommodityModelBuilder brandId(Long brandId) {this.brandId brandId;return this;}public CommodityModelBuilder channelCode(Integer channelCode) {this.channelCode channelCode;return this;}public CommodityModelBuilder extraInfoMap(MapString, Long extraInfoMap) {this.extraInfoMap extraInfoMap;return this;}//方法4public CommodityModel build() {return new CommodityModel(this.title, this.brandId, this.channelCode, this.extraInfoMap);}public String toString() {return CommodityModel.CommodityModelBuilder(title this.title , brandId this.brandId , channelCode this.channelCode , extraInfoMap this.extraInfoMap );}} }Lombok的Builder 注解在编译期间会帮我们生成一个内部的Builder类并生成一个创建这个内部builder对象的静态方法方法1然后我们的代码是调用了方法1方法2方法3和方法4其中方法4中的this.extraInfoMap 是内部类中的属性并没有默认值所以build()方法返回的对象extraInfoMap就是一个null; 解决 在需要默认值的属性上面增加 Builder.Default 注解 // // Source code recreated from a .class file by IntelliJ IDEA // (powered by FernFlower decompiler) //package com.shizhuang.duapp.nbinterface.interfaces.facade;import com.google.common.collect.Maps; import java.util.Map;public class CommodityModel {private String title;private Long brandId;private Integer channelCode;private MapString, Long extraInfoMap;// 方法1private static MapString, Long $default$extraInfoMap() {return Maps.newHashMap();}--- 省略部分代码 ---public MapString, Long getExtraInfoMap() {return this.extraInfoMap;}public static class CommodityModelBuilder {private String title;private Long brandId;private Integer channelCode;private boolean extraInfoMap$set;private MapString, Long extraInfoMap$value;CommodityModelBuilder() {}public CommodityModelBuilder title(String title) {this.title title;return this;}--- 省略部分代码 ---public CommodityModelBuilder extraInfoMap(MapString, Long extraInfoMap) {this.extraInfoMap$value extraInfoMap;// 标记用户已对目标属性赋值处理了this.extraInfoMap$set true;return this;}public CommodityModel build() {// this.extraInfoMap$value 是内部类的属性MapString, Long extraInfoMap$value this.extraInfoMap$value;// 用户如果没有操作则使用方法1为内部类赋值if (!this.extraInfoMap$set) {extraInfoMap$value CommodityModel.$default$extraInfoMap();}// 使用内部类的属性创建对象return new CommodityModel(this.title, this.brandId, this.channelCode, extraInfoMap$value);}} }此时再看编译后的代码会发现内部类中有一个属性extraInfoMap$set 会标记用户是否对extraInfoMap属性处理过没有操作的话就会赋值我们加的默认值 Maps.newHashMap(); 总结 日常我们业务开发中有很多小的需求只需要增加一个属性就可以解决此时就要注意历史逻辑中是否用 Lombok 的 Builder方式创建对象
http://www.pierceye.com/news/80457/

相关文章:

  • 网站建设公司织梦模板营销网站是什么意思
  • 东莞做网站多少钱网上写作平台有哪些
  • 想把书放到二手网站如何做网站建站的技术解决方案
  • 网站相互推广怎么做零基础学ps多久可以学会
  • 无锡网站建设价格最优河北网站制作多少钱
  • html5 网站推荐网站怎么做语言切换
  • 怎么申请免费国内免费网站做网站首页文件
  • 网站成功秘诀西宁市营销网站建设公司
  • 最牛的SEO教程网站天津本地网站
  • logo网站设计做企业网站的字体大小要求
  • 企业网站案例分析网站做的相似
  • thinkphp 企业网站源码花18000去达内培训值吗
  • 公司为什么建立网站网站手机端 怎么做
  • 响应式科技公司网站模板下载移动电商网站开发需求文档
  • 自己做的网站怎么放视频教程重庆承越网站建设地址
  • 网站开发需要看什么书网站建设自助搭配系统
  • 网建公司浅谈网站建设的目的和意义户型图装修设计图app
  • asp.net+制作网站开发湛江网站制作专业
  • 网站做的简单是什么意思企业网站建设结论
  • c语言网站建设wordpress 中文数据
  • 无锡市滨湖区建设局网站唐山做网站公司费用
  • html5响应式网站开发新手学做网站手机
  • 博达网站建设网站开发价格明细
  • 建站网站的图片在线绘画软件
  • 深圳做网站需要多少费用做最好的网站新新
  • 企业网站的价值体现是在内蒙古做网站的公司有哪些
  • 建设网站英文翻译网站制作软件平台
  • 珠海响应式网站建设费用wordpress语言设置为繁体字
  • 教育门户网站系统建设方案以下哪些不属于h5制作软件
  • 上海网站建设服务市价金方时代网站建设