转载:https://blog.51cto.com/u_3631118/3121347
https://blog.csdn.net/weixin_38192427/article/details/122270716
spring除了@DateTimeFormat之外,还提供了一个@NumberFormat注解,作用也是用来数据输入时适配入参的数据格式
比如下面的salary字段,输入时就可以接受11,000,00这种类型的数字
public class Student { private String name; private Integer gender; @DateTimeFormat(pattern="yyyy-MM-dd") private Date birth; @NumberFormat(pattern="#,###") private Integer salary; public Student(String name, Integer gender, Date birth, Integer salary) { super(); this.name = name; this.gender = gender; this.birth = birth; this.salary = salary; } } ----------------------------------- ©著作权归作者所有:来自51CTO博客作者YourBatman的原创作品,请联系作者获取转载授权,否则将追究法律责任 【小家Spring】@DateTimeFormat和@NumberFormat以及@JsonFormat的使用 https://blog.51cto.com/u_3631118/3121347
public class User { @NumberFormat(style=Style.NUMBER,pattern="#,###") private int total; @NumberFormat(style=Style.PERCENT) private double discount; @NumberFormat(style=Style.CURRENCY) private double money; }
输入:
输出:
标签:salary,name,NumberFormat,spring,private,birth,gender,注解 From: https://www.cnblogs.com/wangbin2188/p/17191769.html