Solve the problem that mybatis query date and time data to get long type data

 

 Reprinted from: http://blog.csdn.net/qq_29216083/article/details/77678981

 

When using mybatis to query data, if the database stores time types such as timestamp, datetime, date, time, etc., and the Java bean also uses the date type, mybatis will automatically convert the date type to unix long time eg: 1503912320000, not time Format. 
There are two solutions: 
1. Change the type in the Java bean to String type. 
2. Add the annotation @JsonFormat to the get method of the date type in the java bean 
There is a @JsonFormat annotation in jackson. After configuring it on the get method of the Date type, jackson will convert the date type according to the configured format

    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    public Date getEnddate() {
        return enddate;
    }

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326434178&siteId=291194637