惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

F
Fortinet All Blogs
Attack and Defense Labs
Attack and Defense Labs
V2EX - 技术
V2EX - 技术
O
OpenAI News
S
Secure Thoughts
H
Heimdal Security Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Schneier on Security
Schneier on Security
H
Hacker News: Front Page
S
Security Affairs
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Vercel News
Vercel News
Microsoft Security Blog
Microsoft Security Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Proofpoint News Feed
The Register - Security
The Register - Security
GbyAI
GbyAI
Cloudbric
Cloudbric
MongoDB | Blog
MongoDB | Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
K
Kaspersky official blog
Forbes - Security
Forbes - Security
Y
Y Combinator Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
Scott Helme
Scott Helme
Hacker News - Newest:
Hacker News - Newest: "LLM"
The Cloudflare Blog
Recorded Future
Recorded Future
人人都是产品经理
人人都是产品经理
Cyberwarzone
Cyberwarzone
C
CERT Recently Published Vulnerability Notes
Webroot Blog
Webroot Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LangChain Blog
T
Tor Project blog
Microsoft Azure Blog
Microsoft Azure Blog
博客园_首页
Hacker News: Ask HN
Hacker News: Ask HN
Blog — PlanetScale
Blog — PlanetScale
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
B
Blog RSS Feed
N
News and Events Feed by Topic
阮一峰的网络日志
阮一峰的网络日志
I
Intezer
V
V2EX
T
Tailwind CSS Blog
SecWiki News
SecWiki News
NISL@THU
NISL@THU
C
Check Point Blog

博客园 - npe0

策略模式在项目中的应用 博文阅读密码验证 - 博客园 MyBatis-Plus 的动态SQL片段用法 EasyExcel的多级表头 docker镜像搬运命令 macbook绕过安全控制安装第三方软件 Python中使用列表、map和filter函数配合lambda表达式来操作集合 阿里通义千问大模型初探 java.io.IOException: Cannot run program “az”: CreateProcess error=2, 系统找不到指定的文件。 Git使用问题记录 seata的分布式事务处理机制 JVM常用命令 你可能不知道的Collectors用法 百万千万级Excel导出 arthas 常用命令 对find,xargs,grep和管道的一些深入理解 PlantUML 分库分表 jvm优化
easyexcel导出Bigdecimal数据格式问题
npe0 · 2023-03-20 · via 博客园 - npe0
//可以避免amount为0时,excel显示为.00的问题
@NumberFormat("#0.00")
private BigDecimal amount;

//设置千分位
@NumberFormat("#,##0.00"),即可设置千分位并保留两位小数。

// 也可以通过hutool工具包
NumberUtil.decimalFormat(",##0.00", number);

// 也可以通过自定义序列化器的方式来实现
@JsonSerialize(using = BigDecimalSerializer.class)
private BigDecimal payMoney

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.text.DecimalFormat;
public class BigDecimalSerializer extends JsonSerializer<BigDecimal> {
    // 千分位格式
    private static final DecimalFormat FORMAT = new DecimalFormat("#,##0.00");
    // 非千分位格式
    private static final DecimalFormat FORMAT = new DecimalFormat("#0.00");

    @Override
    public void serialize(BigDecimal value, JsonGenerator gen, SerializerProvider serializers)
            throws IOException {
        if (value != null) {
            gen.writeString(FORMAT.format(value));
        }
    }
}