Springboot整合mybatis-plus
mybatis-plus就是在mybatis上的只增不减,集成了jpa的那种,很多简单的crud只需要调用已经写好的方法就是了
mybatis-plus官网
具体实现
- 引入依赖(这里我还引入了阿里巴巴的连接池)
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.1</version>
</dependency>
<!-- 阿里巴巴的连接池 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.2.4</version>
</dependency>
- 写入配置
spring:
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/sxy_news?serverTimezone=Asia/Shanghai
username: root
password: 123123
- 在springboot的启动类上添加包扫描(或者是在每个mapper文件上加上@Mapper注解也行)
- 实体类
- Dao的编写
- 测试类的编写
@SpringBootTest
class MybatisplusApplicationTests {
@Autowired
SdtbunewDao sdtbunewDao;
@Test
void contextLoads() {
List list = sdtbunewDao.selectList(null);
list.forEach(System.out::println);
}
}