springboot中配置日期格式的转换

springboot中配置日期格式的转换

  • 在application.yml配置
  #日期格式
  jackson:
    date-format: yyyy-MM-dd HH:mm:ss
    time-zone: GMT%2B8
  • 在实体类配置注解

// @JsonFormat(pattern = “yyyy-MM-dd HH:mm:ss”,timezone = “GMT+8”)
// @JsonFormat(pattern = “yyyy/MM/dd HH:mm:ss”, timezone = “GMT+8”)

package com.common.pojo;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;

import java.util.Date;

//员工表
@Data
public class Employee {
     
    private Integer id;

    private String lastName;

    private String email;

    private Integer gender;

    private String department;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
//    @JsonFormat(pattern = "yyyy/MM/dd HH:mm:ss", timezone = "GMT+8")
    private Date date;

    public Employee(Integer id, String lastName, String email, Integer gender, String department) {
     
        this.id = id;
        this.lastName = lastName;
        this.email = email;
        this.gender = gender;
        this.department = department;
        this.date = new Date();
    }
}

你可能感兴趣的:(springboot)