设为首页 收藏本站
查看: 666|回复: 0

[经验分享] apache commons组件

[复制链接]

尚未签到

发表于 2016-12-30 08:18:52 | 显示全部楼层 |阅读模式
  http://www.blogjava.net/sean/articles/Jakarta_Commons_Notes.html
  [Jakarta Commons笔记] 开篇
[Jakarta Commons笔记] Commons Lang
[Jakarta Commons笔记] org.apache.commons.lang
[Jakarta Commons笔记] 代码范例 - ArrayUtils
[Jakarta Commons笔记] 代码范例 - StringUtils
[Jakarta Commons笔记] org.apache.commons.lang.builder
[Jakarta Commons笔记] org.apache.commons.lang.math
[Jakarta Commons笔记] org.apache.commons.lang.time
[Jakarta Commons笔记] Commons BeanUtils
[Jakarta Commons笔记] 代码范例 - BeanUtils
[Jakarta Commons笔记] Commons Collections
[Jakarta Commons笔记] Commons Collections - Bag组
[Jakarta Commons笔记] Commons Collections - Buffer组
[Jakarta Commons笔记] Commons Collections - Map组
[Jakarta Commons笔记] Commons Collections - Collection组
[Jakarta Commons笔记] Commons Collections - Comparator组
[Jakarta Commons笔记] Commons Collections - Predicate组
[Jakarta Commons笔记] Commons Collections - Transformer组
[Jakarta Commons笔记] Commons Collections - Closure组
[Jakarta Commons笔记] Commons Collections - Iterator组
[Jakarta Commons笔记] 结语 
1)org.apache.commons.lang
这个包提供了一些有用的包含static方法的Util类。除了6个Exception类和2个已经deprecated的数字类之外,commons.lang包共包含了17个实用的类:
 
ArrayUtils – 用于对数组的操作,如添加、查找、删除、子数组、倒序、元素类型转换等;
BitField – 用于操作位元,提供了一些方便而安全的方法;
BooleanUtils – 用于操作和转换boolean或者Boolean及相应的数组;
CharEncoding – 包含了Java环境支持的字符编码,提供是否支持某种编码的判断;
CharRange – 用于设定字符范围并做相应检查;
CharSet – 用于设定一组字符作为范围并做相应检查;
CharSetUtils – 用于操作CharSet;
CharUtils – 用于操作char值和Character对象;
ClassUtils – 用于对Java类的操作,不使用反射;
ObjectUtils – 用于操作Java对象,提供null安全的访问和其他一些功能;
RandomStringUtils – 用于生成随机的字符串;(验证码)
SerializationUtils – 用于处理对象序列化,提供比一般Java序列化更高级的处理能力;
StringEscapeUtils – 用于正确处理转义字符,产生正确的Java、JavaScript、HTML、XML和SQL代码;
StringUtils – 处理String的核心类,提供了相当多的功能;(判断字符串是否为空等:isBlank(String str)、isNumeric(String str)、reverse(String str)等
SystemUtils – 在java.lang.System基础上提供更方便的访问,如用户路径、Java版本、时区、操作系统等判断;
Validate – 提供验证的操作,有点类似assert断言;
WordUtils – 用于处理单词大小写、换行等。
 
StringUtils:
   (1) StringUtils.center(" demoNormalJavaBeans ", 40, "=");
   显示结果:========= demoNormalJavaBeans ==========
   解释:参数1显示在中间,左右用"="号包裹,输出总长度为40。

 (2) Object[] rawOutput1 = new Object[] { "The city of customer ", name,"'s first address is ", city, "." };        System.out.println(StringUtils.join(rawOutput1));
   显示结果:The city of customer John Smith's first address is Los Angeles.
   解释:将数组元素连接起来。

  2) org.apache.commons.configuration 配置包
  Configuration parameters may be loaded from the following sources: 处理的配置文件类型:

  • Properties files
  • XML documents
  • Windows INI files
  • Property list files (plist)
  • JNDI
  • JDBC Datasource
  • System properties
  • Applet parameters
  • Servlet parameters
  Different configuration sources can be mixed using a ConfigurationFactory and a CompositeConfiguration. Additional sources of configuration parameters can be created by using custom configuration objects. This customization can be achieved by extending AbstractConfiguration or AbstractFileConfiguration.
  The full Javadoc API documentation is available here.
  3)org.apache.commons.beanutils.BeanUtils配置包
  关键方法的解释和运用:
  (1) public static void copyProperties(Object dest, Object orig):
  Copy property values from the origin bean to the destination bean for all cases where the property names are the same.
  eg:BeanUtils.copyProperties(user1,user2);
  (2) public static void copyProperty(Object bean, String name, Object value):
  Copy the specified property value to the specified destination bean, performing any type conversion that is required.
  eg:BeanUtils.copyProperty(student,"stuName","leh"); //赋值给student实体stuName属性值为"leh";
  (3) public static String getProperty(Object bean, String name):
  Return the value of the specified property of the specified bean, no matter which property reference format is used, as a String.(返回带格式的属性值,也可以不带格式,不带格式相当于下面的getSimpleProperty()方法)
  eg: String cityPattern = "addresses[0].city";
         String city = (String) PropertyUtils.getProperty(customer, cityPattern);
         //customer对象中有Address类型,后者有city属性。
  (4) public static void setProperty(Object bean, String name, Object value): 
  (4) public static String getSimpleProperty(Object bean, String name):
  eg:BeanUtils.getProperty(student,"stuName"); //得到student实体的stuName属性的值。stuName为student的基本类型;
  (5) public static void populate(Object bean, Map properties):
  Populate the JavaBeans properties of the specified bean, based on the specified name/value pairs.
  eg:
  Map userMap =hashMap();
  userMap.put("stuName","leh");  
  …… 
  BeanUtils.populate(student,userMap);//将userMap中的键的值赋值给同student中与map的键同名的属性。同名则复制,不同则不赋值。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-321302-1-1.html 上篇帖子: apache commons-dbutils 下篇帖子: apache-io扩展
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表