1 引入场景启动器
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.3.1</version>
</dependency>
2 配置
配置数据源:导入数据库的驱动
<!-- mysql连接驱动-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.17</version>
</dependency>
在yml文件中配置连接mysql数据库
#配置数据源
spring:
datasource:
username: root
password: root
url: jdbc:mysql://192.168.56.10:3306/shopmail_pms
driver-class-name: com.mysql.jdbc.Driver
配置mybatis-plus:
1 使用@MapperScan("com.fengbao.shop.shopproduct.dao"), @MapperScan 指定要变成实现类的接口所在的包,然后包下面所有的接口在编译之后都会变成相应的实现类*/
@MapperScan("com.fengbao.shop.shopproduct.dao")
@SpringBootApplication
@EnableDiscoveryClient
public class ShopProductApplication {
public static void main(String[] args) {
SpringApplication.run(ShopProductApplication.class, args);
}
}
2 告诉mybatis-plus Sql映射文件的位置
#配置mybatisplus的sql映射的文件位置
mybatis-plus:
mapper-locations: classpath*:/mapper/**/*.xml
global-config:
db-config:
# 主键自增
id-type: auto