Data Formatting of Spring MVC
describe
Spring3 introduces a format converter (Formatter SPI) and a format service API (FormattingConversionService) to support formatting and display of data.
The core of Formatter SPI is to complete parsing and formatting conversion logic. It is used when parsing, printing/displaying localized object values in web applications/client projects. For example, java.util.Date---- >java.lang.String print/display, java.lang.String---->java.util.Date, etc.
Spring's built-in format converters are as follows
Format with annotations
package cn.javass.chapter7.model; public class FormatterModel { @NumberFormat(style=Style.NUMBER, pattern="#,###") private int totalCount; @NumberFormat(style=Style.PERCENT) private double discount; @NumberFormat(style=Style.CURRENCY) private double sumMoney; @DateTimeFormat(iso=ISO.DATE) private Date registerDate; @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") private Date orderDate; // Abbreviated getter / setter }