I. BACKGROUND
Building Projects with Ssm+maven
Where the date field in MySQL is a datetime type
The JSON data that the controller returns to the front end is a long type "Date": "1528324651545"
What I need is the YYYY-MM-DD format.
Second, the settlement
1. In the mapper file corresponding to the entity, modify the data type of the column in the Resultmap
1 <Mappernamespace= "Com.ssm.mapper.PeopleMapper">2 3 <Resultmaptype= "Com.ssm.model.people"ID= "Peoplerm">4 ... ..5 6 <result Property= "B_date"column= "Bir_date" javatype= "Java.sql.Date" />7 8 ... ..9 Ten </Resultmap>
2. Add annotations to the Getter method on the corresponding field of the entity class
1 Private Date b_date; 2 3 @DateTimeFormat (pattern= "Yyyy-mm-dd") 5 Public Date getb_date () {7return b_date; 9 }
2.1 Of course it can be written as follows:
1 Private Date b_date; 2 3 @DateTimeFormat (iso=ISO. Date)5 public Date getb_date () {7return b_date; 9 }
2.2 When the field in your entity class is of type time, the type of column in Resultmap should be java.sql.Time
Annotations are @datetimeformat (pattern= "HH:mm:ss")
3. Introducing Joda in Maven's Pom.xml
1 <!--Date Time Library -2 <Dependency>3 <groupId>Joda-time</groupId>4 <Artifactid>Joda-time</Artifactid>5 <version>2.3</version>6 </Dependency>
4. In the SPRINGMVC configuration file, add the note driver
1 <mvc:annotation-driven/>
Third, the above related knowledge, please check your own
Spring in date format conversion