BeanUtils和PropertyUtils工具类

本文介绍了BeanUtils和PropertiesUtils两个工具类的功能及区别。BeanUtils的copyProperties方法可以将源对象的属性值复制到目标对象,支持一定范围内的类型转换;而PropertiesUtils相似的方法不支持类型转换但执行效率更高。值得注意的是,对于日期类型的处理,应使用java.sql.Date以避免异常。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

BeanUtils提供对反射和自省API的包装

这里只介绍他的copyProperties()方法

public static void copyProperties(java.lang.Object dest,java.lang.Object orig)  
         throws java.lang.IllegalAccessException,  
                     java.lang.reflect.InvocationTargetException  

 它的作用是将dest和orig具有相同名称的字段的值从orig复制到dest中

 

PropertiesUtils的同名方法作用十分类似,主要区别在于,BeanUtils支持同名字段一定范围的类型转换,PropertiesUtils不支持但是速度会快点

 

需要注意的是,java.util.Date不支持转换,它的子类java.sql.Date支持,因此如果对象包含时间类型且希望被转换时,一定要使用java.sql.Date,否则会抛出argument mistype异常

 

这两个工具类很方便但成本也很昂贵

 

 

一个简单的开源Android工具类库,提供许多常用的类帮助我们开发程序。 AndroidCommon 一个简单的开源Android工具类库,提供许多常用的类帮助我们开发程序。 These are the Android Common Utils. Class Introduction AnimationUtils Animation Unility Class AppUtils App Unility Class ArrayUtils Array Unility Class AssetsUtils Assets Unility Class BASE64Utils Base64 Unility Class BitmapUtils Bitmap Unility Class BlurUtils Blur Unility Class ByteUtils Byte Unility Class CalendarUtils Calendar Unility Class ClipboardUtils Clipboard Unility Class CollectionUtils Collection Unility Class CommonUtils Common Unility Class CpuUtils Cpu Unility Class DeviceUtils Device Unility Class DisplayUtils Display Unility Class FileUtils File Unility Class FragmentUtils Fragment Unility Class HandlerUtils Handler Unility Class IOUtils IO Unility Class ImageUtils Image Unility Class InputMethodUtils InputMethod Unility Class IntentUtils Intent Unility Class JsonUtils Json Unility Class LogUtils Log Unility Class MD5Utils Md5 Unility Class MapUtils Map Unility Class MemoryUtils Memory Unility Class NetworkUtils Network Unility Class NumberUtils Number Unility Class ObjectUtils Object Unility Class PackageUtils Package Unility Class PropertyUtils Property Unility Class RandomUtils Random Unility Class ResourceUtils Resource Unility Class SHA1Utils Sha1 Unility Class SerializableUtils Serializable Unility Class SharedPreferencesUtils SharedPreferences Unility Class ShellUtils Shell Unility Class StringUtils String Unility Class SystemUtils System Unility Class TelephonyUtils Telephony Unility Class ThreadUtils Thread Unility Class TimeUtils Time Unility Class ToastUtils Toast Unility Class UrlUtils Url Unility Class VibratorUtils Vibrator Unility Class ViewUtils View Unility Class Permission <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" /> <uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> Proguard -keep class com.wx.android.common.** { *; } -keepclassmembers class com.wx.android.common.** { *; } -dontwarn com.wx.android.common.** Setup Download the project from GitHub Import it to your Eclipse workspace or IntelliJ IDEA project Set your project properties, then add a android project library, and select AndroidCommon Usage Gradle: compile 'com.wx.android.common:common:1.0.1' Author venshine venshine.cn@gmail.com License Copyright (C) 2015 venshine.cn@gmail.com Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值