在springboot中整合mybatis-plus

  按照官方文档进行的配置:快速开始|mybatis-plus

  引入依赖:

 1 <!-- 引入mybatisPlus -->
 2        <dependency>
 3             <groupId>com.baomidou</groupId>
 4             <artifactId>mybatis-plus-boot-starter</artifactId>
 5             <version>3.2.0</version>
 6         </dependency>
 7         <!-- 引入mysql驱动包 -->
 8         <dependency>
 9             <groupId>mysql</groupId>
10             <artifactId>mysql-connector-java</artifactId>
11             <version>5.1.27</version>
12         </dependency>
13         <!-- 引入Druid依赖,阿里巴巴所提供的数据源 -->
14         <dependency>
15             <groupId>com.alibaba</groupId>
16             <artifactId>druid</artifactId>
17             <version>1.0.29</version>
18     </dependency>

  在application.yml配置

1 spring:
2   datasource:
3     type: com.alibaba.druid.pool.DruidDataSource
4     driver-class-name: com.mysql.jdbc.Driver
5     url: jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF-8
6     username: root
7     password: 123456

  在启动类上面添加@MapperScan注解,扫描mapper包

1 @SpringBootApplication
2 @MapperScan("com.qiao.demo02.mapper")
3 public class SpringbootDemo02Application {
4 
5     public static void main(String[] args) {
6         SpringApplication.run(SpringbootDemo02Application.class, args);
7     }
8 
9 }

  新建User和UserMapper

mybatis-plus分页查询

    user类

1 @Data
2 public class User {
3     @TableId
4     private Integer userId;
5     private String userName;
6     private Integer userAge;
7     private String userEmail;
8 }
View Code

相关文章:

  • 2022-12-23
  • 2021-06-20
  • 2021-09-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-26
猜你喜欢
  • 2022-12-23
  • 2021-07-06
  • 2021-07-05
  • 2022-12-23
  • 2021-07-17
  • 2021-12-29
  • 2022-12-23
相关资源
相似解决方案