2007-07-20

妙用Commons良药 <六>

关键字: 基础知识
妙用Commons良药 <六> 1、定义toString(),hashCode(),equals()等内容 toString()方法举例: import org.apache.commons.lang.builder.ToStringBuilder; import org.apache.commons.lang.builder.ToStringStyle; public String toString( ) { return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) ...
2007-07-19

妙用Commons良药 <五>

关键字: 基础
这一篇文章主要是讲一下关于Commons开源项目中其Commons BeanUtils的一些相关的用法. 1、复制Bean属性 如果你有两个相同的Bean的实例,并需要将其中的一个bean属性复制到另一个中去,调用PropertyUtils.copyProperties()即可,这一个方法经常在使用struts,hibernate等框架的时候常常用到.举例: import org.apache.commons.beanutils.PropertyUtils; Book book = new Book( ); book.setName( "Prelude to Foundation" ...
2007-07-19

妙用Commons良药<四>

关键字: 基础
妙用Commons良药<四> 谈一谈Math包的一点内容,和怎样对属性文件,xml文件进行访问 1、关于org.apache.commons.lang.math的应用 可使用Commons Lang的NumberUtils.max()和NumberUtils.min()方法来从基本类型数组(如double[],float[],long[],int[],short[],byte[])中检索出最小或最大值.举例: import org.apache.commons.lang.math.NumberUtils; double[] array = {0.2, 0.4, 0.5, -3. ...
2007-07-19

妙用Commons良药<三>

关键字: 基础
这一篇文章主要是介绍怎样用Commons处理XMl文件 1、将XML文档转化为你想要的对象 可以使用org.apache.commons.digester.Digester来实现你想要的功能,其步骤如下:定义待匹配的模式,以及遇到之些模式时将执行的动作,通过Digester可以很容易地实现你自己的SAX解析器,并让你无须处理复杂的SAX API,即可完成你想要的功能。Digester只是SAX外面的一个轻量级外壳,其解析的速度差不多和SAX一样快的。 看一个XML文件: <?xml version="1.0"?> <plays> <play genre=" ...
2007-07-18

妙用Commons良药<二>

关键字: Commons 基础
妙用Commons良药<二> 谈谈怎么用org.apache.commons.lang.StringUtils这一个类,讲一下具体的几个常用的方法 使用StringUtils.isBlank(),该方法在收到空字符串,零长度字符串或全为空格的字符串时将返回true.它能通过返回true的方式优雅地处理null. String test = ""; String test2 = "\n\n\t"; String test3 = null; String test4 = "Test"; System.out.println( "test blank? " + StringUtils ...
2007-07-18

妙用Commons良药<一>

关键字: Commons IO基础
妙用commons良药<一> 这一篇文章主要是讲Commons IO的一些内容. Commons IO提供了org.apache.commons.io.CopyUtils类来将某个InputStream,Reader,byte[]数据或字符串的内容拷贝到OutputStream或Writer. Writer writer = new FileWriter( "test.dat" ); InputStream inputStream = getClass( ).getResourceAsStream("./test.resource"); ...