Mybatis-Plus中实现使用xml文件来写复杂sql

一、前言

我们一般的sql语句使用Mabatis-Plus可以满足,但是到了连表和复杂的需求时,还是需要像Mybatis那样在xml中来书写sql语句,但是一个项目中只能有一个,所以我们在使用Mybatis-Plus时,就不需要在导入Mybatis的依赖,Mybatis-Plus也可以直接在xml文件中写,不过是yml文件中的配置不一样!

二、具体配置

  • Mybatis-Plus所需依赖
	<!-- mybatis-plus -->
      <dependency>
          <groupId>com.baomidou</groupId>
          <artifactId>mybatis-plus-boot-starter</artifactId>
          <version>3.1.0</version>
      </dependency>
  • yml文件配置
#原来mybatis的配置,我们删除就行
mybatis:
 mapper-locations: classpath:mapper/*.xml
 type-aliases-package: com.wang.test.demo.entity

#直接用这个,在xml文件中也可以书写sql
mybatis-plus:
  mapper-locations: classpath:mapper/*.xml
  type-aliases-package: com.wang.test.demo.entity
  • 额外的yml文件配置
#执行的sql会在控制台打印
logging:
 level:
  com.wang.test.demo: DEBUG #写自己的包路径就行

三、总结

其实就和Mybatis的匹配一样,Mybatis换成了Mybatis-Plus,自己在使用时,遇到的问题,在这里分享给大家!

你可能感兴趣的:(mybatis-plus,java)