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();
    }
}
发布了71 篇原创文章 · 获赞 0 · 访问量 1566

猜你喜欢

转载自blog.csdn.net/qq_42977003/article/details/104377554