SpringBoot整合MybatisPlus
1.新建工程
2.添加依赖
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.0.4</version>
</dependency>
3.配置文件
spring:
datasource:
driver-class-name: org.postgresql.Driver
url: jdbc:postgresql://localhost:5432/geowincongig
username: postgres
password: password
mybatis-plus:
# configuration:
# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl #mybatis\u65E5\u5FD7
mapper-locations: classpath:cn/casm/geowinconfig/mapper/xml/*.xml
4.启动类
@SpringBootApplication
@MapperScan("cn.casm.geowinconfig.mapper")//MapperScan注解
public class GeowinconfigApplication {
public static void main(String[] args) {
SpringApplication.run(GeowinconfigApplication.class, args);
}
}
5.创建包
entity
mapper
mapper下创建xml,ServerMapper,ServerMapper.xml,还需要编写service层
6.Maven配置
这一步一定要配,这样在target类路径下才会有xml文件
否则Mybatis会报绑定异常
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>
7.原理
转载:https://blog.csdn.net/Shaun_luotao/article/details/87094700