mybatis/mybatis plus 设置全局参数,表前缀使用
mybaits的配置 (主要观察表前缀)
# MyBatis配置 mybatis: # 搜索指定包别名 typeAliasesPackage: com.qiqi.**.domain # 配置mapper的扫描,找到所有的mapper.xml映射文件 mapperLocations: classpath*:mapper/**/*Mapper.xml # 加载全局的配置文件 configLocation: classpath:mybatis/mybatis-config.xml # MyBatis Plus配置 mybatis-plus: global-config: # 设置表前缀 db-config: # 配置MyBatis-Plus操作表的默认前缀 table-prefix: tb1_ # id生成策略自动增长 id-type: auto # sql日志打印 log-impl: org.apache.ibatis.logging.stdout.StdOutImpl configuration: variables: # 自定义表前缀 tablePrefix: test1_
配置了,table-prefix后 mybatis-plus的操作都会加上tb1前缀,并且实体类如果也想用这个前缀,需使用注解,keepGlobalPrefix=true
@TableName(value = "user", keepGlobalPrefix = true)
之后mybatisplus自带的查询操作方法,都会加表前缀.
如果在mapper文件中使用table-prefix变量,还不知道怎么获取(暂时获取是空白)。暂时用了另外一个变量configuration.variables.tablePrefix,先声明这个变量.
mapper.xml
<select id="queryOneById" resultType="com.qiqi.domain.entity.MyUser"> select * from ${tablePrefix}users where id = #{id} </select>
转 : https://blog.csdn.net/mashangzhifu/article/details/122845644