package com.rehome.mqttclienttemperature.entity; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import org.hibernate.annotations.Proxy; import org.springframework.data.jpa.domain.support.AuditingEntityListener; import javax.persistence.*; import java.io.Serializable; import java.util.Date; @EntityListeners(AuditingEntityListener.class) @Proxy(lazy = false) @Data @Entity //普通索引,不指定索引名,表自动创建索引名 //@Table(indexes = {@Index(columnList = "dataDate"),@Index(columnList = "locationDesc")}) //普通索引,指定索引名,创建单个索引 //在这个例子中,Temperature实体类通过@Table注解的indexes属性定义了一个名为idx_dataDate的索引,它覆盖了dataDate字段。这意味着在数据库层面,针对dataDate字段的查询将会利用这个索引,从而提高查询效率。 //@Table(indexes = {@Index(name = "idx_dataDate", columnList = "dataDate")}) //同时创建多个普通索引,注意每个索引名都不同 //@Table(indexes = {@Index(name = "idx_dataDate", columnList = "dataDate"),@Index(name = "idx_locationDesc", columnList = "locationDesc")}) //@Table(indexes = {@Index(name = "idx_dataDate", columnList = "dataDate"),@Index(name = "idx_locationDesc", columnList = "locationDesc"),@Index(name = "idx_dataHour", columnList = "dataHour"),@Index(name = "idx_dataMinute", columnList = "dataMinute")}) //创建组合索引,注意每个索引名都相同 //@Table(indexes = {@Index(name = "data_date_location_desc", columnList = "dataDate"),@Index(name = "data_date_location_desc", columnList = "locationDesc")}) //同时创建普通索引和组合索引,注意普通索引每个索引名都不同,注意组合索引每个索引名都相同 @Table(indexes = {@Index(name = "idx_dataDate", columnList = "dataDate"),@Index(name = "idx_locationDesc", columnList = "locationDesc"),@Index(name = "idx_dataHour", columnList = "dataHour"),@Index(name = "idx_dataMinute", columnList = "dataMinute"),@Index(name = "data_date_location_desc", columnList = "dataDate"),@Index(name = "data_date_location_desc", columnList = "locationDesc")}) public class Temperature implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @ApiModelProperty(value = "主键") private Long id; @ApiModelProperty(value = "温度") private Double temperature; @ApiModelProperty(value = "湿度") private Double humidity; @ApiModelProperty(value = "日期") @Column(length=20) private String dataDate; @ApiModelProperty(value = "时") @Column(length=20) private String dataHour; @ApiModelProperty(value = "分") @Column(length=20) private String dataMinute; @ApiModelProperty(value = "主题") @Column(length=60) private String topic; @ApiModelProperty(value = "位置描述") @Column(length=80) private String locationDesc; @ApiModelProperty(value = "时间") @Temporal(TemporalType.TIMESTAMP) private Date createDate; }