mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix bugs
This commit is contained in:
parent
3f8699f7e9
commit
3ebd7d9ce0
@ -3,12 +3,15 @@
|
|||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
# 5.8.2.M1 (2022-05-18)
|
# 5.8.2.M1 (2022-05-20)
|
||||||
|
|
||||||
### 🐣新特性
|
### 🐣新特性
|
||||||
|
* 【core 】 BeanUtil拷贝对象增加空检查(issue#I58CJ3@Gitee)
|
||||||
### 🐞Bug修复
|
### 🐞Bug修复
|
||||||
* 【extra 】 修复SshjSftp初始化未能代入端口配置问题(issue#2333@Github)
|
* 【extra 】 修复SshjSftp初始化未能代入端口配置问题(issue#2333@Github)
|
||||||
* 【core 】 修复Convert.numberToSimple转换问题(issue#2334@Github)
|
* 【core 】 修复Convert.numberToSimple转换问题(issue#2334@Github)
|
||||||
|
* 【core 】 修复TemporalAccessorConverter导致的转换问题(issue#2341@Github)
|
||||||
|
* 【core 】 修复TemporalAccessorConverter导致的转换问题(issue#2341@Github)
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -728,6 +728,9 @@ public class BeanUtil {
|
|||||||
* @return 目标对象
|
* @return 目标对象
|
||||||
*/
|
*/
|
||||||
public static <T> T copyProperties(Object source, Class<T> tClass, String... ignoreProperties) {
|
public static <T> T copyProperties(Object source, Class<T> tClass, String... ignoreProperties) {
|
||||||
|
if(null == source){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
T target = ReflectUtil.newInstanceIfPossible(tClass);
|
T target = ReflectUtil.newInstanceIfPossible(tClass);
|
||||||
copyProperties(source, target, CopyOptions.create().setIgnoreProperties(ignoreProperties));
|
copyProperties(source, target, CopyOptions.create().setIgnoreProperties(ignoreProperties));
|
||||||
return target;
|
return target;
|
||||||
@ -765,6 +768,9 @@ public class BeanUtil {
|
|||||||
* @param copyOptions 拷贝选项,见 {@link CopyOptions}
|
* @param copyOptions 拷贝选项,见 {@link CopyOptions}
|
||||||
*/
|
*/
|
||||||
public static void copyProperties(Object source, Object target, CopyOptions copyOptions) {
|
public static void copyProperties(Object source, Object target, CopyOptions copyOptions) {
|
||||||
|
if(null == source){
|
||||||
|
return;
|
||||||
|
}
|
||||||
BeanCopier.create(source, target, ObjectUtil.defaultIfNull(copyOptions, CopyOptions::create)).copy();
|
BeanCopier.create(source, target, ObjectUtil.defaultIfNull(copyOptions, CopyOptions::create)).copy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package cn.hutool.core.bean.copier;
|
package cn.hutool.core.bean.copier;
|
||||||
|
|
||||||
|
import cn.hutool.core.lang.Assert;
|
||||||
import cn.hutool.core.lang.copier.Copier;
|
import cn.hutool.core.lang.copier.Copier;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
@ -62,6 +63,8 @@ public class BeanCopier<T> implements Copier<T>, Serializable {
|
|||||||
* @param copyOptions 拷贝属性选项
|
* @param copyOptions 拷贝属性选项
|
||||||
*/
|
*/
|
||||||
public BeanCopier(Object source, T target, Type targetType, CopyOptions copyOptions) {
|
public BeanCopier(Object source, T target, Type targetType, CopyOptions copyOptions) {
|
||||||
|
Assert.notNull(source, "Source bean must be not null!");
|
||||||
|
Assert.notNull(target, "Target bean must be not null!");
|
||||||
Copier<T> copier;
|
Copier<T> copier;
|
||||||
if (source instanceof Map) {
|
if (source instanceof Map) {
|
||||||
if (target instanceof Map) {
|
if (target instanceof Map) {
|
||||||
|
@ -84,6 +84,12 @@ public class TemporalAccessorConverter extends AbstractConverter<TemporalAccesso
|
|||||||
this.format = format;
|
this.format = format;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
public Class<TemporalAccessor> getTargetType() {
|
||||||
|
return (Class<TemporalAccessor>) this.targetType;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected TemporalAccessor convertInternal(Object value) {
|
protected TemporalAccessor convertInternal(Object value) {
|
||||||
if (value instanceof Long) {
|
if (value instanceof Long) {
|
||||||
|
@ -567,6 +567,11 @@ public class BeanUtilTest {
|
|||||||
Assert.assertNull(newFood.getCode());
|
Assert.assertNull(newFood.getCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void copyNullTest() {
|
||||||
|
Assert.assertNull(BeanUtil.copyProperties(null, Food.class));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void copyBeanPropertiesFilterTest() {
|
public void copyBeanPropertiesFilterTest() {
|
||||||
Food info = new Food();
|
Food info = new Food();
|
||||||
|
@ -15,6 +15,8 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@ -383,4 +385,11 @@ public class ConvertTest {
|
|||||||
float b = Convert.toFloat(a);
|
float b = Convert.toFloat(a);
|
||||||
Assert.assertEquals(a, b, 5);
|
Assert.assertEquals(a, b, 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void localDateTimeToLocalDateTest(){
|
||||||
|
final LocalDateTime localDateTime = LocalDateTime.now();
|
||||||
|
final LocalDate convert = Convert.convert(LocalDate.class, localDateTime);
|
||||||
|
Assert.assertEquals(localDateTime.toLocalDate(), convert);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -439,6 +439,9 @@ public class NumberUtilTest {
|
|||||||
Assert.assertFalse(NumberUtil.isEven(a[4]));
|
Assert.assertFalse(NumberUtil.isEven(a[4]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void divIntegerTest(){
|
||||||
|
Assert.assertEquals(1001013, NumberUtil.div(100101300, (Number) 100).intValue());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user