1. 程式人生 > 實用技巧 >springboot根據註解建立全文索引(springboot全文索引註解)

springboot根據註解建立全文索引(springboot全文索引註解)

springboot支援mysql5.7版本以上根據註解建立全文索引
使用方法:

1.拉取程式碼到本地工作空間

git clone https://gitee.com/light-zhang/springboot-fulltext.git

2.專案中引入依賴

<dependency>
    <groupId>skdapp.cn</groupId>
    <artifactId>springboot.mysql.fulltext</artifactId>
    <version>0.0.1-SNAPSHOT</version
> </dependency>

3.在專案中使用

//啟動類注入(scanPackages你的om掃描路徑)
@SpringbootFulltext(scanPackages
= { "skdapp.cn.xxx.xxx" }) @SpringBootApplication(scanBasePackages = { "skdapp.cn.xxx.xxx" })public class Application { public static void main(String[] args) { SpringApplication.run(Application.
class, args); } }

4.實體類使用

@Entity
@Table(name = "demo")
public class Demo implements Serializable {
    @Id
    @GeneratedValue(generator = "uuid")
    @GenericGenerator(name = "uuid", strategy = "uuid")
    @Column(name = "pk_id", nullable = false, unique = true, length = 32, columnDefinition = "varchar(32) COMMENT '主鍵ID,生成32位隨機字串' ")
    
private String pkId; @Fulltext(columnName = "spell") @Column(name = "content", columnDefinition = "text COMMENT '內容' ") private String content; }

啟動專案時,就可以根據Fulltext註解的配置自動掃描建立全文索引了,轉載請註明原處,謝謝!!