金额自动转换工具
This commit is contained in:
1 parent
d7b7a1dafb
commit
d857d9fad0
6 files changed
+258
-1
No files matched your search
+21
@@ -0,0 +1,21 @@
|
||||
package com.bsd.pjcloud.common.core.util;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class MoneyDeserializer extends JsonDeserializer<Integer> {
|
||||
@Override
|
||||
public Integer deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
String text = p.getText();
|
||||
if (text == null || text.isEmpty()) {
|
||||
return 0; // 默认值
|
||||
}
|
||||
BigDecimal yuan = new BigDecimal(text);
|
||||
return yuan.multiply(new BigDecimal(100)).intValue();
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package com.bsd.pjcloud.common.core.util;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
|
||||
public class MoneySerializer extends JsonSerializer<Integer> {
|
||||
@Override
|
||||
public void serialize(Integer value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
|
||||
if (value == null) {
|
||||
gen.writeString("0.00"); // 默认值
|
||||
return;
|
||||
}
|
||||
BigDecimal yuan = new BigDecimal(value).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP);
|
||||
gen.writeString(yuan.toString());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user