Springboot接收和返回Date()参数
一、在实体类的属性中增加@JsonFormat
package com.hxh.model;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
public class CompetActi {
private Integer competactiId;
private Integer seedId;
@JsonFormat(timezone = "GMT+8", pattern = "HH:mm:ss")
private Date competactiBegin;
@JsonFormat(timezone = "GMT+8", pattern = "HH:mm:ss")
private Date competactiEnd;
private Integer competactiGram;
private Integer competactiMun;
private Integer competactiMax;
private Integer competactiOpen;
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
private Date competactiTime;
private Integer competactiNum;
二、前端接收后端数据
后端给前端的数据就会自动转成以下的形式
{
"competActis": [
{
"competactiId": 1,
"seedId": 1,
"competactiBegin": "11:11:11",
"competactiEnd": "11:11:12",
"competactiGram": 100,
"competactiMun": 2,
"competactiMax": 10,
"competactiOpen": 1,
"competactiTime": "2019-01-01",
"competactiNum": 18
}
}
三、后端接收Date()数据
前段只需要传一定格式的字符串就好
competactiId:1
seedId:1
competactiBegin:2019/01/01 11:11:11
competactiEnd:2019/01/02 11:11:12
competactiGram:100
competactiMun:2
competactiMax:10
competactiOpen:1
competactiTime:2019/01/01
competactiNum:18