mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
add method
This commit is contained in:
parent
72a33201eb
commit
a5f757679e
@ -18,6 +18,7 @@
|
|||||||
* 【core 】 增加Interner和InternUtil(issue#I1TU1Y@Gitee)
|
* 【core 】 增加Interner和InternUtil(issue#I1TU1Y@Gitee)
|
||||||
* 【core 】 增加Calculator(issue#1090@Github)
|
* 【core 】 增加Calculator(issue#1090@Github)
|
||||||
* 【core 】 IdcardUtil增加getIdcardInfo方法(issue#1092@Github)
|
* 【core 】 IdcardUtil增加getIdcardInfo方法(issue#1092@Github)
|
||||||
|
* 【core 】 改进ObjectUtil.equal,支持BigDecimal判断
|
||||||
|
|
||||||
### Bug修复
|
### Bug修复
|
||||||
* 【core 】 修复Dict.of错误(issue#I1UUO5@Gitee)
|
* 【core 】 修复Dict.of错误(issue#I1UUO5@Gitee)
|
||||||
|
@ -13,6 +13,7 @@ import java.io.ObjectInputStream;
|
|||||||
import java.io.ObjectOutputStream;
|
import java.io.ObjectOutputStream;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.lang.reflect.Array;
|
import java.lang.reflect.Array;
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -22,14 +23,33 @@ import java.util.*;
|
|||||||
*/
|
*/
|
||||||
public class ObjectUtil {
|
public class ObjectUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 比较两个对象是否相等,此方法是 {@link #equal(Object, Object)}的别名方法。<br>
|
||||||
|
* 相同的条件有两个,满足其一即可:<br>
|
||||||
|
* <ol>
|
||||||
|
* <li>obj1 == null && obj2 == null</li>
|
||||||
|
* <li>obj1.equals(obj2)</li>
|
||||||
|
* <li>如果是BigDecimal比较,0 == obj1.compareTo(obj2)</li>
|
||||||
|
* </ol>
|
||||||
|
*
|
||||||
|
* @param obj1 对象1
|
||||||
|
* @param obj2 对象2
|
||||||
|
* @return 是否相等
|
||||||
|
* @see #equal(Object, Object)
|
||||||
|
* @since 5.4.3
|
||||||
|
*/
|
||||||
|
public static boolean equals(Object obj1, Object obj2) {
|
||||||
|
return equal(obj1, obj2);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 比较两个对象是否相等。<br>
|
* 比较两个对象是否相等。<br>
|
||||||
* 相同的条件有两个,满足其一即可:<br>
|
* 相同的条件有两个,满足其一即可:<br>
|
||||||
* <ol>
|
* <ol>
|
||||||
* <li>obj1 == null && obj2 == null</li>
|
* <li>obj1 == null && obj2 == null</li>
|
||||||
* <li>obj1.equals(obj2)</li>
|
* <li>obj1.equals(obj2)</li>
|
||||||
|
* <li>如果是BigDecimal比较,0 == obj1.compareTo(obj2)</li>
|
||||||
* </ol>
|
* </ol>
|
||||||
* 1. obj1 == null && obj2 == null 2. obj1.equals(obj2)
|
|
||||||
*
|
*
|
||||||
* @param obj1 对象1
|
* @param obj1 对象1
|
||||||
* @param obj2 对象2
|
* @param obj2 对象2
|
||||||
@ -37,7 +57,9 @@ public class ObjectUtil {
|
|||||||
* @see Objects#equals(Object, Object)
|
* @see Objects#equals(Object, Object)
|
||||||
*/
|
*/
|
||||||
public static boolean equal(Object obj1, Object obj2) {
|
public static boolean equal(Object obj1, Object obj2) {
|
||||||
// return (obj1 != null) ? (obj1.equals(obj2)) : (obj2 == null);
|
if(obj1 instanceof BigDecimal && obj2 instanceof BigDecimal){
|
||||||
|
return NumberUtil.equals((BigDecimal)obj1, (BigDecimal)obj2);
|
||||||
|
}
|
||||||
return Objects.equals(obj1, obj2);
|
return Objects.equals(obj1, obj2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package cn.hutool.db;
|
package cn.hutool.db;
|
||||||
|
|
||||||
import cn.hutool.core.collection.ArrayIter;
|
import cn.hutool.core.collection.ArrayIter;
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.convert.Convert;
|
import cn.hutool.core.convert.Convert;
|
||||||
import cn.hutool.core.lang.Assert;
|
import cn.hutool.core.lang.Assert;
|
||||||
import cn.hutool.core.util.ArrayUtil;
|
import cn.hutool.core.util.ArrayUtil;
|
||||||
@ -13,8 +13,19 @@ import cn.hutool.db.sql.SqlUtil;
|
|||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.sql.*;
|
import java.sql.CallableStatement;
|
||||||
import java.util.*;
|
import java.sql.Connection;
|
||||||
|
import java.sql.ParameterMetaData;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Statement;
|
||||||
|
import java.sql.Types;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Statement和PreparedStatement工具类
|
* Statement和PreparedStatement工具类
|
||||||
@ -191,7 +202,7 @@ public class StatementUtil {
|
|||||||
//null参数的类型缓存,避免循环中重复获取类型
|
//null参数的类型缓存,避免循环中重复获取类型
|
||||||
final Map<Integer, Integer> nullTypeMap = new HashMap<>();
|
final Map<Integer, Integer> nullTypeMap = new HashMap<>();
|
||||||
for (Entity entity : entities) {
|
for (Entity entity : entities) {
|
||||||
fillParams(ps, CollectionUtil.valuesOfKeys(entity, fields), nullTypeMap);
|
fillParams(ps, CollUtil.valuesOfKeys(entity, fields), nullTypeMap);
|
||||||
ps.addBatch();
|
ps.addBatch();
|
||||||
}
|
}
|
||||||
return ps;
|
return ps;
|
||||||
|
@ -101,7 +101,7 @@ public class SqlBuilder implements Builder<String>{
|
|||||||
* 插入会忽略空的字段名及其对应值,但是对于有字段名对应值为{@code null}的情况不忽略
|
* 插入会忽略空的字段名及其对应值,但是对于有字段名对应值为{@code null}的情况不忽略
|
||||||
*
|
*
|
||||||
* @param entity 实体
|
* @param entity 实体
|
||||||
* @param dialectName 方言名
|
* @param dialectName 方言名,用于对特殊数据库特殊处理
|
||||||
* @return 自己
|
* @return 自己
|
||||||
*/
|
*/
|
||||||
public SqlBuilder insert(Entity entity, DialectName dialectName) {
|
public SqlBuilder insert(Entity entity, DialectName dialectName) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user