From 0f4dea2c50bab1ce5a8edad277f88809216a822b Mon Sep 17 00:00:00 2001 From: gyl <1554863190@qq.com> Date: Mon, 21 Aug 2023 11:31:37 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E7=BC=96=E8=A7=A3=E7=A0=81):=20=E6=95=B0?= =?UTF-8?q?=E5=AD=97=E7=BC=96=E8=A7=A3=E7=A0=81=E5=99=A8=E6=94=AF=E6=8C=81?= =?UTF-8?q?BigDecimal=E5=8F=8ABigInteger=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ezorm/rdb/codec/NumberValueCodec.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/codec/NumberValueCodec.java b/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/codec/NumberValueCodec.java index 8eecbd8f..0fc81501 100644 --- a/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/codec/NumberValueCodec.java +++ b/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/codec/NumberValueCodec.java @@ -8,6 +8,7 @@ import java.lang.reflect.Constructor; import java.math.BigDecimal; +import java.math.BigInteger; import java.time.LocalDateTime; import java.time.ZoneId; import java.time.ZonedDateTime; @@ -38,7 +39,25 @@ public NumberValueCodec(Class javaType) { converter = Number::shortValue; } else if (javaType == boolean.class || javaType == Boolean.class) { converter = num -> num.byteValue() != 0; - } else if (Date.class.isAssignableFrom(javaType)) { + } else if (javaType == BigDecimal.class ) { + converter = num -> { + if (num instanceof BigDecimal) { + return (BigDecimal) num; + } else { + return new BigDecimal(num.toString()); + } + }; + } else if (javaType == BigInteger.class ) { + converter = num -> { + if (num instanceof BigInteger) { + return (BigInteger) num; + } else if (num instanceof BigDecimal) { + return ((BigDecimal) num).toBigInteger(); + } else { + return new BigInteger(num.toString()); + } + }; + }else if (Date.class.isAssignableFrom(javaType)) { Constructor constructor = javaType.getConstructor(); converter = num -> { try {