package com.example.demo.Entity;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.ToString;
import java.util.Date;
@Data
@ToString
public class UserEntity {
private long id;
private String name;
private String passwd;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date create_time;
@JsonFormat(shape= JsonFormat.Shape.STRING,pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
private Date update_time;
private String is_delete;
}
在实体类字段上加上注解
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
在控制器里添加操作时这样直接new Date()传入
@PostMapping("/add_user")
@ResponseBody
public long add_user(String name, String passwd){
UserEntity userEntity = new UserEntity();
userEntity.setName(name);
userEntity.setPasswd(passwd);
userEntity.setCreate_time(new Date());
userEntity.setUpdate_time(new Date());
userEntity.setIs_delete("0");
return userService.AddUser(userEntity);
}