mybatis-plus 表名添加前綴

1、使用mybatis-plus自身的查詢構造去,只需要在全局配置中添加如下配置

mybatis-plus:
  mapper-locations: classpath:mappers/*Mapper.xml    # mapper映射文件
  global-config:
    db-config:
      table-prefix: tr_

2、自定義sql語句中添加表名前綴

在yml文件中添加如下配置

mybatis-plus:
  mapper-locations: classpath:mappers/*Mapper.xml    # mapper映射文件
  global-config:
    db-config:
      table-prefix: tr_
  configuration-properties: 
    prefix: tr_ # 自定義sql中表名帶前綴

然後在自定義sql語句如下

select * from ${prefix}user 

編譯後的sql語句

select * from tr_user

mybaits-plus功能還是很強大的,官網地址:https://mp.baomidou.com/guide/

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章