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

档案网站建设文献综述中国核工业第五建设有限公司

档案网站建设文献综述,中国核工业第五建设有限公司,坑梓网站建设信息,少儿编程课有没有必要学摘自:https://www.cnblogs.com/haicheng92/p/18721636 学习要带着目的,参照现实问题 本次目标: 了解 CommonsLang3 API 文档,找对路后以后开发直接查询 API 文档,摈弃盲目的百度掌握基础的字符串、日期、数值等工具…

摘自:https://www.cnblogs.com/haicheng92/p/18721636

学习要带着目的,参照现实问题

本次目标:

  • 了解 CommonsLang3 API 文档,找对路后以后开发直接查询 API 文档,摈弃盲目的百度
  • 掌握基础的字符串、日期、数值等工具方法,初步替代手搓的工具类

为什么要用 CommonsLang3?

  • 比自己手写的工具方法安全性高,不易出 Bug
  • 第三方工具包,便于携带,开箱即用,一通百通,再也不用收集各种工具方法了

介绍

Common3Lang3官网

The standard Java libraries fail to provide enough methods for manipulation of its core classes. Apache Commons Lang provides these extra methods.
Apache Commons Lang provides a host of helper utilities for the java.lang API, notably String manipulation methods, basic numerical methods, object reflection, concurrency, creation and serialization and System properties. Additionally it contains basic enhancements to java.util.Date and a series of utilities dedicated to help with building methods, such as hashCode, toString and equals.

意:Java 标准库没有提供足够的方法去操作核心类,于是 Apache Commons Lang 就补充了这些方法。
Apache Commons Lang 为 java.lang 中的核心类提供了一系列辅助工具 API,尤其是字符串操作方法,基础数字方法,对象反射,并发,创建和序列化以及系统属性。另外它还包括对 java.util.Date 的基础增强,还有一系列实用工具用来辅助 building 方法,比如 hashCode,toString 和 equals。

CommonsLang3 和 CommonsLang 的区别:Lang3 可以看做是 Lang 的高阶版本,二者同源不同库,使用上并不兼容。建议使用 Lang3 库

CommonsLang3 API 文档

都是有些简单的英文,再加上翻译软件,有点耐心都能看懂。

字符串

文档中写的非常非常非常清楚,一定要看文档,看源码也行!!

日期实践

 
String[] datePatterns = new String[] {"yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd"};
String dateStr = "2025-02-18 11:06:20";
Date date = DateUtils.parseDate(dateStr, Locale.CHINESE, datePatterns);
log.info("字符串转为日期:{}", date);
String str = DateFormatUtils.format(date, datePatterns[0]);
log.info("日期转为字符串:{}", str);

对象工具类

在实际开发中,有大量嵌套属性的判空操作,比如以下:

 
Employee employee = this.getEmployee();
// 如果员工不空,且员工所属部门也不空,则 do something
if (employee != null && employee.getDepartment() != null) {
log.info("!=null:all not null");
}
// 使用 Objects
if (Objects.nonNull(employee) && Objects.nonNull(employee.getDepartment())) {
log.info("Objects.nonNull:all not null");
}
// 使用 CommangsLang3 ObjectUitis,等同于以上两种写法,但是更加简洁明了
if (ObjectUtils.allNotNull(employee, employee.getDepartment())) {
log.info("ObjectUtils.allNotNull:all not null");
}

还有大量设置默认值的操作,比如【如果为空,则设置默认值】

 
Employee emp = new Employee("张三");
//emp.setDepartment(new Department("测试"));
// 条件判断:如果员工对象部门为空,则默认创建一个部门
Department depart0 = emp.getDepartment();
if (Objects.isNull(depart0)) {
depart0 = new Department("开发0");
}
log.info("部门: {}", depart0.getName());
// Optional 新写法1
Department depart1 = Optional.ofNullable(emp.getDepartment()).orElse(new Department("开发1"));
log.info("部门: {}", depart1.getName());
// Optional 新写法2
Department depart2 = Optional.ofNullable(emp.getDepartment()).orElseGet(() -> new Department("开发2"));
log.info("部门: {}", depart2.getName());
// Lang3 defaultIfNull 等同于 Optional 新写法1
Department depart3 = ObjectUtils.defaultIfNull(emp.getDepartment(), new Department("开发3"));
log.info("部门: {}", depart3.getName());
// Lang3 getIfNull 等同于 Optional 新写法2
Department depart4 = ObjectUtils.getIfNull(emp.getDepartment(), () -> new Department("开发4"));
log.info("部门: {}", depart4.getName());
  • orElse 无论 Optional 的值是否为 null,都会计算 default 的值。
  • orElseGet 只有当 Optional 的值为 null 时,才会去计算函数表达式的值,类似于懒加载,功能上相当于短路。
    所以建议使用 Optional.orElseGet() 或 ObjectUtils.getIfNull() 方法。

StringUtils 中也有 defulatIfEmpty 这种带有简单逻辑判断的方法,这或许也是一种规律,将简单判断/逻辑封装为方法

分类: Java


文章转载自:

http://x2tudLp8.jgcrr.cn
http://XaVQd9LE.jgcrr.cn
http://7fLQTMbx.jgcrr.cn
http://Izsr3t7y.jgcrr.cn
http://tDXdpkPL.jgcrr.cn
http://GJh7L0cN.jgcrr.cn
http://Tea8FBSh.jgcrr.cn
http://mVv4bNZ2.jgcrr.cn
http://x0pZjD2E.jgcrr.cn
http://c2BhzzvG.jgcrr.cn
http://PThzTfHi.jgcrr.cn
http://mWzJjuj7.jgcrr.cn
http://dWZyjrP7.jgcrr.cn
http://x5TuKWaf.jgcrr.cn
http://sL9dV634.jgcrr.cn
http://S9OumOqG.jgcrr.cn
http://jjalUx90.jgcrr.cn
http://Y9bL0I3e.jgcrr.cn
http://FshFAiaf.jgcrr.cn
http://Euk7Ekza.jgcrr.cn
http://cDMQxuS0.jgcrr.cn
http://u5WHSAgf.jgcrr.cn
http://akugL1yT.jgcrr.cn
http://BAqUL0zc.jgcrr.cn
http://puCz6X43.jgcrr.cn
http://GaDbT4Qk.jgcrr.cn
http://WycoUKCn.jgcrr.cn
http://j0j4K7Qv.jgcrr.cn
http://EaLw5cL5.jgcrr.cn
http://az4oiEEZ.jgcrr.cn
http://www.dtcms.com/wzjs/740209.html

相关文章:

  • 建设网站模块需要哪些wordpress add_theme_page
  • 深圳网站设计我选刻企业管理专业主要课程
  • 平台建设上线网站网站建设如何传视频
  • wordpress4.8是什么seo排名公司
  • 河南高端网站成都门户网站建设
  • 长沙品牌网站建设群晖wordpress 手机
  • 石家庄做网站最好的公司哪家好英文网站 字体大小
  • 小豪自助建站公司网站模板怎么写
  • 公司网站微信推广甘肃省住房建设厅户网站
  • 网站开发公司是外包公司吗网站建设用户量分析
  • 网站后台用什么开发杭州设计 公司 网站建设
  • 做紧固件上什么网站嘉兴网站建设咨询
  • 门户类网站注重什么seo顾问服
  • 有没有做彩票直播的网站网站 关键词 选择
  • 南昌网站建设代理商网站开发代做
  • 网站搭建配置wordpress添加addthis
  • 网站建设贵阳电影网站源码access
  • 138ip地址查询网站长沙工商注册网上核名
  • 如何做返利网站外推广企业所得税怎么算的
  • 公司网站设计欣赏专业app开发企业
  • 网站规划对网站建设起到什么作用网站广告文案
  • 中堂网站建设php做的网站模板下载地址
  • 服务器配置wordpress南京网站排名优化费用
  • 怎样利用网站做引流郑州网站建设贴吧
  • 北京app手机网站制作网站编程好学吗
  • 安丘网站建设制作上海装修公司排名前十口碑
  • 公司网站建设需要什么科目wordpress所有标签
  • 新站整站快速排名威联通如何做网站
  • 不用代码做交互式网站九江专业网站建设
  • 怎么上网站做简易注销的步骤seo基础知识