Spring Boot JPA 使用 @Index 为字段添加索引
Spring Boot JPA 大约 566 字需求
使用JPA
创建:唯一索引、普通索引、联合索引。
代码
使用@Table
中的indexes
属性,指定@Index
索引。
@Setter
@Getter
@Entity
@Table(name = "user", indexes = {
@Index(name = "uk_id_card", columnList = "id_card", unique = true),
@Index(name = "idx_name", columnList = "name"),
@Index(name = "idx_name_id_card", columnList = "name, id_card"), // 组合索引
})
public class User extends CommonEntity {
@Column(length = 50, nullable = false)
private String name;
@Column(name = "id_card")
private String idCard;
}
说明
@Index
:name
指定索引名称,columnList
指定添加索引的列,联合索引使用,
逗号隔开,unique
为true
表示唯一索引。
阅读 1142 · 发布于 2023-02-26
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb扫描下方二维码关注公众号和小程序↓↓↓

昵称:
随便看看
换一批
-
PHP 字段对应 MySQL 字段阅读 1895
-
Maven java: The type of parameter "xxx" has no property named "id".阅读 2124
-
走进 Rust:函数阅读 2031
-
软考-系统架构设计师:进程管理 - PV 操作阅读 4776
-
Docker CMD ENTRYPOINT 区别阅读 1097
-
Spring Boot 移除错误页面 /error 节点阅读 235
-
Android WebView 启用安全浏览模式阅读 3389
-
GitHub 访问慢解决方案阅读 2495
-
Windows 后台启动 Nginx、Redis、MongoDB、php-fpm阅读 2954
-
Spring Boot Thymeleaf 获取 Bean 等容器中的对象阅读 89