【spring-boot②】mybatis配置以及分页查询

本文介绍了如何在Spring Boot项目中配置MyBatis,包括添加相关依赖、配置数据源、使用MyBatis Generator生成Mapper文件,以及编写接口、Service和Controller。同时,文章还提到了Swagger的配合使用,以及解决运行时的错误,如添加Mapper扫描注解和配置文件中的Mapper配置。
摘要由CSDN通过智能技术生成

本次学习结合了swagger,swagger配置教程看【spring-boot】swagger配置

https://blog.csdn.net/nangu0673/article/details/82587268

1. 创建子模块zxw-mybatis,添加必要的依赖

<dependencies>

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-web</artifactId>

</dependency>

<dependency>

<groupId>io.springfox</groupId>

<artifactId>springfox-swagger-ui</artifactId>

</dependency>

<dependency>

<groupId>io.springfox</groupId>

<artifactId>springfox-swagger2</artifactId>

</dependency>

 

<!--添加lombok依赖-->

<dependency>

<groupId>org.projectlombok</groupId>

<artifactId>lombok</artifactId>

</dependency>

 

<!-- mybatis以及mysql依赖-->

<dependency>

<groupId>org.mybatis.spring.boot</groupId>

<artifactId>mybatis-spring-boot-starter</artifactId>

</dependency>

<dependency>

<groupId>mysql</groupId>

<artifactId>mysql-connector-java</artifactId>

</dependency>

</dependencies>

 

2. 在resources文件夹下创建文件application.properties,并在此配置数据源信息

spring.datasource.url=jdbc:mysql://localhost:3306/xxxxx?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false

spring.datasource.username= 数据库名

spring.datasource.password= 数据库密码

spring.datasource.driverClassName=com.mysql.jdbc.Driver

此配置与数据库相对应

 

3. 为了让mybatis自动生成mapper等文件,需要引入mybatis-generator插件。回到父模块zhangxianwen-test的pom文件中添加插件依赖(在父模块中添加后,所有子模块不用重新写依赖直接使用了)

<build>

<plugins>

<plugin>

<groupId>org.mybatis.generator</groupId>

<artifactId>mybatis-generator-maven-plugin</artifactId>

<version>1.3.2</version>

<configuration>

<verbose>true</verbose> //打印详细信息

<overwrite>true</overwrite>

</configuration>

</plugin

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值