Java日期时间类型升级

Java8中日期时间类型与MySQL数据库中年日期时间类型对应

MySQL Java 描述
time java.time.LocalTime 时间
timestamp java.time.Instant 时间戳
date java.time.LocalDate 日期
datetime java.time.LocalDateTime 日期时间
year java.time.Year 年份

映射

    /**
     * 处理前端整数精度问题
     */
    @JsonSerialize(using = ToStringSerializer.class)
    @TableId(type = IdType.AUTO)
    private java.lang.Long id;

    @TableField("local_time")
    private java.time.LocalTime localTime;

    @TableField("local_date")
    private java.time.LocalDate localDate;

    /**
     * 指定输入时间格式
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @TableField("local_date_time")
    private java.time.LocalDateTime localDateTime;

    /**
     * 时间戳,可指定输入为年月日时分秒 或 整数
     */
    // @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @JsonFormat(shape = JsonFormat.Shape.NUMBER_INT)
    @TableField("timestamp")
    private java.time.Instant timestamp;

    /**
     * 默认输出年份为字符串,这里指定输入位数字
     */
    @JsonFormat(shape = JsonFormat.Shape.NUMBER_INT)
    @TableField("year")
    private java.time.Year year;
posted @ 2024-04-20 16:12  Bruce.Chang.Lee  阅读(18)  评论(0)    收藏  举报