我们先来看下表结构:
实体类:
package com.elq.product.entity;import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;import java.io.Serializable;
import java.util.Date;@Data
@TableName("elq_logs")
public class LogsEntity implements Serializable {@TableId(value = "snow_id",type = IdType.ASSIGN_ID)private String snowId;@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")private Date createTime;private String data;@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")private Date updateTime;
}
控制器:
@RequestMapping("/inserts")public String add(@RequestBody LogsEntity logsEntity){String indexList = indexService.inserts(logsEntity);return indexList;}
service实现类:
@Overridepublic String inserts(LogsEntity logsEntity) {Date createTime = logsEntity.getCreateTime();int insert = this.baseMapper.insert(logsEntity);return insert+"";}
POSTman 测试:
存储结果: