package com.bkybk.util;
import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.Time;
import java.sql.Timestamp;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.beanutils.converters.BigDecimalConverter;
import org.apache.commons.beanutils.converters.BigIntegerConverter;
import org.apache.commons.beanutils.converters.BooleanConverter;
import org.apache.commons.beanutils.converters.DateConverter;
import org.apache.commons.beanutils.converters.DoubleConverter;
import org.apache.commons.beanutils.converters.FloatConverter;
import org.apache.commons.beanutils.converters.IntegerConverter;
import org.apache.commons.beanutils.converters.LongConverter;
import org.apache.commons.beanutils.converters.ShortConverter;
import org.apache.commons.beanutils.converters.SqlDateConverter;
import org.apache.commons.beanutils.converters.SqlTimeConverter;
import org.apache.commons.beanutils.converters.SqlTimestampConverter;
import org.apache.commons.beanutils.converters.StringConverter;
public class BeanUtil extends BeanUtils {
static {
SqlTimestampConverter dtConverter = new SqlTimestampConverter(null);
dtConverter.setPatterns(new String[]{"yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd","MM/dd/yyyy","MM/dd/yyyy HH:mm:ss"});
ConvertUtils.register(new StringConverter(), String.class);
// date
ConvertUtils.register(new DateConverter(null), java.util.Date.class);
ConvertUtils.register(new SqlDateConverter(null), java.sql.Date.class);
ConvertUtils.register(new SqlTimeConverter(null), Time.class);
//ConvertUtils.register(dtConverter, Timestamp.class);
ConvertUtils.register(dtConverter, Timestamp.class);
// number
ConvertUtils.register(new BooleanConverter(null), Boolean.class);
ConvertUtils.register(new ShortConverter(null), Short.class);
ConvertUtils.register(new IntegerConverter(null), Integer.class);
ConvertUtils.register(new LongConverter(null), Long.class);
ConvertUtils.register(new FloatConverter(null), Float.class);
ConvertUtils.register(new DoubleConverter(null), Double.class);
ConvertUtils.register(new BigDecimalConverter(null), BigDecimal.class);
ConvertUtils.register(new BigIntegerConverter(null), BigInteger.class);
}
public static void copyProperties(Object target, Object source) {
try {
BeanUtils.copyProperties(target, source);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
/**
* 两个值进行比较
* @param oldObj
* @param newObj
* @return 相同返回true 不同返回false
*/
@SuppressWarnings("unused")
private static Boolean compareValue(Object oldObj,Object newObj){
if(null == oldObj && null == newObj){
return true;
//属性类型为bigdecimal时
}else if(
//防止旧值为null
(oldObj == null ? newObj.getClass() : oldObj.getClass() ).equals(BigDecimal.class) &&
//如果旧值为null时给一个0
( oldObj == null ? new BigDecimal(0) : (BigDecimal)oldObj ).compareTo(
//新值为null时给一个0
newObj == null ? new BigDecimal(0) : (BigDecimal)newObj
)==0
){
return true;
//属性类型为Timestamp
}else if((oldObj == null ? newObj.getClass() : oldObj.getClass() ).equals(Timestamp.class)
//避免出现null.eal的情况
&& (oldObj == null ? newObj.equals(oldObj) : oldObj.equals(newObj)) ){
return true;
}else{
oldObj = oldObj==null?"":oldObj;
newObj = newObj==null?"":newObj;
if((oldObj).equals(newObj)){
return true;
}
return false;
}
}
}
idea14+maven+struts+spring+mybatis框架
1星 需积分: 16 9 浏览量
2016-07-15
16:17:58
上传
评论
收藏 67KB ZIP 举报
qqhr_czy
- 粉丝: 0
- 资源: 5
最新资源
- 前端开发-什么是前端开发-关于前端开发的一些相关介绍
- Sora AI-关于文生视频的使用场景说明
- suno AI文生视频的相关教程和介绍使用
- 什么是后端开发-关于后端开发的一些小介绍分享
- Jurassic Pack Vol. II Dinosaurs 侏罗纪包卷恐龙二号Unity游戏模型资源unitypackage
- Jurassic Pack Vol. III Dinosaurs 侏罗纪包卷恐龙三号Unity游戏模型资源unitypackag
- Ultimate Seating Controller 终极座椅控制器Unity游戏开发插件资源unitypackage
- 什么是人工智能-关于人工智能的相关介绍说明
- Figma Converter for Unity适用Unity的Figma转换器Unity游戏开发插件unitypackage
- Creepy Animatronic Anims 令人毛骨悚然的电子动画Unity游戏动画插件资源unitypackage
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈