GVKun编程网logo

apache commons StringUtils

6

如果您想了解apachecommonsStringUtils的知识,那么本篇文章将是您的不二之选。同时我们将深入剖析ApacheCommonsBeanUtils1.9.3发布、ApacheCommon

如果您想了解apache commons StringUtils的知识,那么本篇文章将是您的不二之选。同时我们将深入剖析Apache Commons BeanUtils 1.9.3 发布、Apache Commons DbUtils 1.5 发布、Apache Commons DbUtils 1.6 发布、apache commons StringUtils介绍的各个方面,并给出实际的案例分析,希望能帮助到您!

本文目录一览:

apache commons StringUtils

apache commons StringUtils

StringUtils方法的操作对象是java.lang.String类型的对象,是JDK提供的String类型操作方法的补充,并且是null安全的(即如果输入参数String为null则不会抛出NullPointerException,而是做了相应处理,例如,如果输入为null则返回也是null等,具体可以查看源代码)。

除了构造器,StringUtils中一共有130多个方法,并且都是static的,所以我们可以这样调用StringUtils.xxx()

1. public static boolean isEmpty(String str)
判断某字符串是否为空,为空的标准是str==null或str.length()==0
下面是StringUtils判断是否为空的示例:
StringUtils.isEmpty(null) = true
StringUtils.isEmpty("") = true
StringUtils.isEmpty(" ") = false //注意在StringUtils中空格作非空处理
StringUtils.isEmpty(" ") = false
StringUtils.isEmpty("bob") = false
StringUtils.isEmpty(" bob ") = false

2. public static boolean isNotEmpty(String str)
判断某字符串是否非空,等于!isEmpty(String str)
下面是示例:
StringUtils.isNotEmpty(null) = false
StringUtils.isNotEmpty("") = false
StringUtils.isNotEmpty(" ") = true
StringUtils.isNotEmpty(" ") = true
StringUtils.isNotEmpty("bob") = true
StringUtils.isNotEmpty(" bob ") = true

3. public static boolean isBlank(String str)
判断某字符串是否为空或长度为0或由空白符(whitespace)构成
下面是示例:
StringUtils.isBlank(null) = true
StringUtils.isBlank("") = true
StringUtils.isBlank(" ") = true
StringUtils.isBlank(" ") = true
StringUtils.isBlank("/t /n /f /r") = true //对于制表符、换行符、换页符和回车符StringUtils.isBlank()均识为空白符
StringUtils.isBlank("/b") = false //"/b"为单词边界符
StringUtils.isBlank("bob") = false
StringUtils.isBlank(" bob ") = false

4. public static boolean isNotBlank(String str)
判断某字符串是否不为空且长度不为0且不由空白符(whitespace)构成,等于!isBlank(String str)
下面是示例:
StringUtils.isNotBlank(null) = false
StringUtils.isNotBlank("") = false
StringUtils.isNotBlank(" ") = false
StringUtils.isNotBlank(" ") = false
StringUtils.isNotBlank("/t /n /f /r") = false
StringUtils.isNotBlank("/b") = true
StringUtils.isNotBlank("bob") = true
StringUtils.isNotBlank(" bob ") = true

5. public static String trim(String str)
去掉字符串两端的控制符(control characters, char <= 32),如果输入为null则返回null
下面是示例:
StringUtils.trim(null) = null
StringUtils.trim("") = ""
StringUtils.trim(" ") = ""
StringUtils.trim(" /b /t /n /f /r ") = ""
StringUtils.trim(" /n/tss /b") = "ss"
StringUtils.trim(" d d dd ") = "d d dd"
StringUtils.trim("dd ") = "dd"
StringUtils.trim(" dd ") = "dd"

6. public static String trimToNull(String str)
去掉字符串两端的控制符(control characters, char <= 32),如果变为null或"",则返回null
下面是示例:
StringUtils.trimToNull(null) = null
StringUtils.trimToNull("") = null
StringUtils.trimToNull(" ") = null
StringUtils.trimToNull(" /b /t /n /f /r ") = null
StringUtils.trimToNull(" /n/tss /b") = "ss"
StringUtils.trimToNull(" d d dd ") = "d d dd"
StringUtils.trimToNull("dd ") = "dd"
StringUtils.trimToNull(" dd ") = "dd"

7. public static String trimToEmpty(String str)
去掉字符串两端的控制符(control characters, char <= 32),如果变为null或"",则返回""
下面是示例:
StringUtils.trimToEmpty(null) = ""
StringUtils.trimToEmpty("") = ""
StringUtils.trimToEmpty(" ") = ""
StringUtils.trimToEmpty(" /b /t /n /f /r ") = ""
StringUtils.trimToEmpty(" /n/tss /b") = "ss"
StringUtils.trimToEmpty(" d d dd ") = "d d dd"
StringUtils.trimToEmpty("dd ") = "dd"
StringUtils.trimToEmpty(" dd ") = "dd"

8. public static String strip(String str)
去掉字符串两端的空白符(whitespace),如果输入为null则返回null
下面是示例(注意和trim()的区别):
StringUtils.strip(null) = null
StringUtils.strip("") = ""
StringUtils.strip(" ") = ""
StringUtils.strip(" /b /t /n /f /r ") = "/b"
StringUtils.strip(" /n/tss /b") = "ss /b"
StringUtils.strip(" d d dd ") = "d d dd"
StringUtils.strip("dd ") = "dd"
StringUtils.strip(" dd ") = "dd"

9. public static String stripToNull(String str)
去掉字符串两端的空白符(whitespace),如果变为null或"",则返回null
下面是示例(注意和trimToNull()的区别):
StringUtils.stripToNull(null) = null
StringUtils.stripToNull("") = null
StringUtils.stripToNull(" ") = null
StringUtils.stripToNull(" /b /t /n /f /r ") = "/b"
StringUtils.stripToNull(" /n/tss /b") = "ss /b"
StringUtils.stripToNull(" d d dd ") = "d d dd"
StringUtils.stripToNull("dd ") = "dd"
StringUtils.stripToNull(" dd ") = "dd"

10. public static String stripToEmpty(String str)
去掉字符串两端的空白符(whitespace),如果变为null或"",则返回""
下面是示例(注意和trimToEmpty()的区别):
StringUtils.stripToNull(null) = ""
StringUtils.stripToNull("") = ""
StringUtils.stripToNull(" ") = ""
StringUtils.stripToNull(" /b /t /n /f /r ") = "/b"
StringUtils.stripToNull(" /n/tss /b") = "ss /b"
StringUtils.stripToNull(" d d dd ") = "d d dd"
StringUtils.stripToNull("dd ") = "dd"
StringUtils.stripToNull(" dd ") = "dd"

Apache Commons BeanUtils 1.9.3 发布

Apache Commons BeanUtils 1.9.3 发布

高春辉、王春生、朱峰:关于开源创业的 15 件小事

Apache Commons BeanUtils 1.9.3 发布了。

主要更新内容:

Fixed Bugs:

  • BEANUTILS-477: Changed log level in FluentPropertyBeanIntrospector

  • BEANUTILS-492: Fixed exception when setting indexed properties on DynaBeans.

     Thanks to Bernhard Seebass.
  • BEANUTILS-470: Precision lost when converting BigDecimal Thanks to Tommy

     Tynjä.
  • BEANUTILS-465: Indexed List Setters fixed. Thanks to Daniel Atallah.

Changes:

  • BEANUTILS-433: Update dependency from JUnit 3.8.1 to 4.12. 

    Thanks to Benedikt Ritter, Gary Gregory.
  • BEANUTILS-469: Update commons-logging from 1.1.1 to 1.2. 

    Thanks to Gary Gregory.
  • BEANUTILS-474: FluentPropertyBeanIntrospector does not use the same naming 

    algorithm as DefaultBeanIntrospector.  Thanks to Michael Grove.
  • BEANUTILS-490: Update Java requirement from Java 5 to 6. 

    Thanks to Gary Gregory.
  • BEANUTILS-482: Update commons-collections from 3.2.1 to 3.2.2 

    (CVE-2015-4852). Thanks to Gary Gregory.
  • BEANUTILS-490: Update java requirement to Java 6. Thanks to Gary Gregory.

  • BEANUTILS-492: IndexedPropertyDescriptor tests now pass on Java 8. 

    Thanks to Stian Soiland-Reyes.
  • BEANUTILS-495: DateConverterTestBase fails on M/d/yy in Java 9. 

    Thanks to Stian Soiland-Reyes.
  • BEANUTILS-496: testGetDescriptorInvalidBoolean fails on Java 9. 

    Thanks to Stian Soiland-Reyes.

下载地址:

  • Source code (zip)

  • Source code (tar.gz)

Apache Commons DbUtils 1.5 发布

Apache Commons DbUtils 1.5 发布

DbUtils 可是难得更新一次啊,刚发布的 1.5 版本改进记录包括:

Bug
  [DBUTILS-73] - .BasicRowProcessor.CaseInsensitiveHashMap uses default Locale for toLowerCase
  [DBUTILS-77] - "drop view" does not work from QueryRunner.update with SQLServer JDBC drivers. Same SQL works with a PreparedStatement just fine.
  [DBUTILS-93] - Source assembly artifact fails to build a site because of missing pmd-ruleset.xml

改进
  [DBUTILS-66] - ScalarHandler, ColumnHandler and KeyedHandler are missing generics
  [DBUTILS-84] - BeanProcessor method processColumn should take SQLXML in consideration
  [DBUTILS-91] - Enhance BasicRowProcessor to have row mapping easier to configure

新特性
  [DBUTILS-67] - Add a BeanMapHandler
  [DBUTILS-76] - New handler StringColumnListHandler

任务
  [DBUTILS-88] - Make AsyncQueryRunner be a decorator around a QueryRunner

测试
  [DBUTILS-94] - Provide test coverage for org.apache.commons.dbutils.DbUtils

原则上这不能说是一个持久层框架,它提供了一些Jdbc的操作封装来简化数据查询和记录读取操作。本站就是采用这个项目来读写数据库,代码非常简洁,如果你厌烦了Hibernate的庞大,不妨可以试试——DbUtils。

目前 OSCHINA 正在使用 dbutils 做数据库访问层。

Apache Commons DbUtils 1.6 发布

Apache Commons DbUtils 1.6 发布

Apache Commons DbUtils 1.6 发布,主要改进内容包括:

  • ArrayHandler should return an empty array when handle has no rows Fixes DBUTILS-110.

  • Order of columns not retained in BasicRowProcessor with HashMap Fixes DBUTILS-114.

  • BeanProcessor not returning nanoseconds Fixes DBUTILS-118.

  • Add support for conversion of ResultSet strings to enums in the BeanProcessor Fixes DBUTILS-113.

  • In BeanProcessor#isCompatibleType, can Integer.class.isInstance(value) be replaced by value instanceof Integer (etc)?        Simplified code by using instanceof. Fixes DBUTILS-85.

  • DBUtils can''t build using JDK 1.7 - DriverProxy needs to implement getParentLogger()        Add dynamic invocation. Fixes DBUTILS-106.

  • Create functionality to return auto-generated keys in batches of SQL inserts Fixes DBUTILS-108.

  • Patch QueryLoader to also load from XML properties files Fixes DBUTILS-107.

  • Updated the use of getColumnName to try getColumnLabel first Fixes DBUTILS-100.

  • Add missing JavaDoc to QueryRunner#insert Fixes DBUTILS-98.

  • Add an Abstract ResultSetHandler implementation in order to reduce redundant ''resultSet'' variable invocation Fixes DBUTILS-97.

  • DbUtils#loadDriver(ClassLoader,String) makes DriverManager throwing "No suitable driver found for jdbc"        if ClassLoader is not the System''s one Fixes DBUTILS-96.

  • Added insert methods to QueryRunner and AsyncQueryRunner that return the generated key. Fixes DBUTILS-87.

此版本源代码和二进制包都已提供下载。

Maven:
  <groupId>commons-dbutils</groupId>
  <artifactId>commons-dbutils</artifactId>
  <version>1.6</version>

更多更新内容请看发行说明。

原则上这不能说是一个持久层框架,它提供了一些Jdbc的操作封装来简化数据查询和记录读取操作。本站就是采用这个项目来读写数据库,代码非常简洁,如果你厌烦了Hibernate的庞大,不妨可以试试——DbUtils。

给出一小段代码看看DbUtils是怎么用的:

QueryRunner run = new QueryRunner(dataSource); // Use the BeanHandler implementation to convert the first
// ResultSet row into a Person JavaBean. ResultSetHandler h = new BeanHandler(Person.class); // Execute the SQL statement with one replacement parameter and
// return the results in a new Person object generated by the BeanHandler. Person p = (Person) run.query("SELECT * FROM Person WHERE name=?", "John Doe", h);

JavaDoc:http://tool.oschina.net/apidocs/apidoc?api=commons-dbutils

本站对 dbutils 做了一个改进,下载地址:http://www.oschina.net/uploads/app/commons-dbutils-1.1.fixed.jar
主要解决了dbutils无法处理类似 SELECT userid AS id FROM osc_users 诸如此类的问题,因为 dbutils 使用的方法是 getColumnName 而不是 getColumnLabel (此问题已经在官方的1.3版本中得以解决)。

apache commons StringUtils介绍

apache commons StringUtils介绍

常用的方法

  • isNumeric() 方法:public static boolean isNumeric(CharSequence cs) 含义:判断传入的字符序列Unicode是否是数字,如果是则return true,否则return false。
  • equals 方法:public static boolean equals(CharSequence str1,CharSequence str2) 含义:比较传入的两个字符序列,如果相等则return true,否则return false。在该方法中,不会抛出null空指针异常,如果传入的两个字符都为null,将return true。
  • isEmpty,isNotEmpty,isBlank,isNotBlank 和前面一样,这些方法相对于jdk提供的isEmpty方法来说,多了一个“空指针安全”,即不用考虑传递参数的空值问题。

Blank和empty的区别 :isBlank将在字符串含有空白字符的时候,返回true。

  • split 方法:public static String[] split(String str, char separatorChar) 含义:传入一个字符串和一个分割符,将返回一个字符串数组。 相比于String.split,有两点优势:
    • 相对于String.split是空指针安全的。当你尝试split一个null字符串的时候,将返回Null,一个Null的分隔符将按照空白字符分隔字符串。
    • jdk自带的String.split由于支持正则表达式分离,所以可能会带来意想不到的结果,例如,分割符为".",jdk理解的“.”是正则表达式的任意字符,导致字符串内任意字符都匹配,将返回一个size=0的字符串数组。需要传递"\." 转义一次字符。

今天关于apache commons StringUtils的讲解已经结束,谢谢您的阅读,如果想了解更多关于Apache Commons BeanUtils 1.9.3 发布、Apache Commons DbUtils 1.5 发布、Apache Commons DbUtils 1.6 发布、apache commons StringUtils介绍的相关知识,请在本站搜索。

本文标签: