首先要在SpringBootApplication启动类加上注解@EnableMongoAuditing
import lombok.Data;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.LastModifiedDate;
@Data
public class BaseMongoObject {
@Id
private String id;
@CreatedDate
private Long createdAt;
@LastModifiedDate
private Long updatedAt;
}