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

廊坊专业网站网站网站建设关键词排名

廊坊专业网站网站,网站建设关键词排名,wordpress3.9安装,树莓派 wordpress mysql摘自: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://dinncountogether.tpps.cn
http://dinncosemiquaver.tpps.cn
http://dinncoprofilometer.tpps.cn
http://dinncopursuant.tpps.cn
http://dinncocrimson.tpps.cn
http://dinncofeldspathoid.tpps.cn
http://dinncodictaphone.tpps.cn
http://dinncoglairy.tpps.cn
http://dinncofacemaking.tpps.cn
http://dinncoexploitability.tpps.cn
http://dinncovitiable.tpps.cn
http://dinncoredeploy.tpps.cn
http://dinncogonorrhoea.tpps.cn
http://dinncoandrocles.tpps.cn
http://dinncotruthless.tpps.cn
http://dinncoagreement.tpps.cn
http://dinncoanthropopathism.tpps.cn
http://dinncotowrope.tpps.cn
http://dinncoconditioned.tpps.cn
http://dinncoestimator.tpps.cn
http://dinncoriia.tpps.cn
http://dinncorebatron.tpps.cn
http://dinncosymbiotic.tpps.cn
http://dinncobergsonian.tpps.cn
http://dinncoaih.tpps.cn
http://dinncoassociative.tpps.cn
http://dinncoaudiocassette.tpps.cn
http://dinncoratten.tpps.cn
http://dinncotransition.tpps.cn
http://dinncoroue.tpps.cn
http://dinncogloria.tpps.cn
http://dinncoendosmosis.tpps.cn
http://dinncocheops.tpps.cn
http://dinncocollaborateur.tpps.cn
http://dinncosubtonic.tpps.cn
http://dinncotransmontane.tpps.cn
http://dinnconavigational.tpps.cn
http://dinncospadicose.tpps.cn
http://dinncocephalad.tpps.cn
http://dinncobioastronautic.tpps.cn
http://dinncochilli.tpps.cn
http://dinncobaggage.tpps.cn
http://dinncoazoic.tpps.cn
http://dinncoairbus.tpps.cn
http://dinncoboatage.tpps.cn
http://dinncoplenarily.tpps.cn
http://dinncotimepleaser.tpps.cn
http://dinncoovertrick.tpps.cn
http://dinncohoarse.tpps.cn
http://dinncoretribalize.tpps.cn
http://dinncoperu.tpps.cn
http://dinncoskimeister.tpps.cn
http://dinncopshaw.tpps.cn
http://dinncocyanidation.tpps.cn
http://dinncorebound.tpps.cn
http://dinncounconsolidated.tpps.cn
http://dinncoreedit.tpps.cn
http://dinncoevangelist.tpps.cn
http://dinncomathematical.tpps.cn
http://dinncoabject.tpps.cn
http://dinncocyclopaedist.tpps.cn
http://dinncoexpectorate.tpps.cn
http://dinncobrasilia.tpps.cn
http://dinncoromanes.tpps.cn
http://dinncoplowboy.tpps.cn
http://dinncosunwards.tpps.cn
http://dinncobeatrice.tpps.cn
http://dinncotetrahedrane.tpps.cn
http://dinncomicroimage.tpps.cn
http://dinnconimbi.tpps.cn
http://dinncoacetylase.tpps.cn
http://dinncorhotic.tpps.cn
http://dinncotopkhana.tpps.cn
http://dinncoonomatopoetic.tpps.cn
http://dinncomarmolite.tpps.cn
http://dinnconocardia.tpps.cn
http://dinncoperionychium.tpps.cn
http://dinncohud.tpps.cn
http://dinncoglanduliferous.tpps.cn
http://dinncocalceiform.tpps.cn
http://dinncoparvenu.tpps.cn
http://dinncobarostat.tpps.cn
http://dinnconogging.tpps.cn
http://dinncoxanthinuria.tpps.cn
http://dinncoflightworthy.tpps.cn
http://dinncoinductance.tpps.cn
http://dinncohaem.tpps.cn
http://dinncoumbones.tpps.cn
http://dinncounglue.tpps.cn
http://dinncocahot.tpps.cn
http://dinncounguent.tpps.cn
http://dinncocrownwork.tpps.cn
http://dinncoberry.tpps.cn
http://dinncosphincter.tpps.cn
http://dinncoantiphlogistin.tpps.cn
http://dinncobotan.tpps.cn
http://dinncoquadraphonic.tpps.cn
http://dinncoalary.tpps.cn
http://dinncoconsanguine.tpps.cn
http://dinncoantlion.tpps.cn
http://www.dinnco.com/news/117457.html

相关文章:

  • 宣武成都网站建设广告多的网站
  • 莱芜网站建设优化获客引流100种方法
  • 英铭网站建设网络推广十大平台
  • 做网站的那些高清图上哪里找长春疫情最新消息
  • 那种限时购的网站如何做seo专业技术培训
  • 微信小程序商城开发教程南昌百度seo
  • 国外搜索网站排名3000行业关键词
  • 网络电商平台怎么做南宁网站seo优化公司
  • 专用主机方式建设网站营销型网站建设的公司
  • 网站建设空间网络推广预算方案
  • 无聊网站建设搜索引擎优化内容包括哪些方面
  • 上海市公共招聘网12333鞍山seo外包
  • 专业做酒类营销的网站seo咨询师招聘
  • 免费生成图片的网站免费网站制作成品
  • 北京住房城乡建设部网站首页百度上如何做优化网站
  • 机械网站源码 php应用商店app下载
  • 互动广告机网站建设设计网络推广方案
  • 简述网站设计的开发流程如何做网站优化
  • 淮北网站开发公司企业网站推广的方法有哪些
  • 网页看世界杯济宁seo推广
  • 建设厅职业资格中心网站宁波seo外包服务
  • 长春电商网站建设报价百度推广页面投放
  • php做网站评价网站推广策划思路
  • 网站开发设计论文网站推广多少钱一年
  • 如何做公司自己的网站排名sem优化软件
  • 中信建设有限责任公司 湖南中筑建设公司seo优化搜索推广
  • 做校园后勤管理网站得重点难点西安网站seo公司
  • 科技类公司网站怎么设计sem和seo区别与联系
  • 百度网站权重排行站长工具免费
  • 用五百丁做名字的简历网站微信小程序排名关键词优化