ssm整合mybatisplus
时间: 2023-06-28 11:13:45 浏览: 148
SSM框架整合Mybatis-Plus的步骤如下:
1. 引入Mybatis-Plus依赖
在pom.xml文件中添加以下依赖:
```
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.x.x</version>
</dependency>
```
2. 配置Mybatis-Plus
在application.properties文件中添加以下配置:
```
# 数据库连接配置
spring.datasource.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.username=root
spring.datasource.password=root
# Mybatis-Plus配置
mybatis-plus.mapper-locations=classpath:mapper/*.xml
mybatis-plus.type-aliases-package=com.example.demo.entity
mybatis-plus.global-config.id-type=auto
mybatis-plus.global-config.db-config.logic-delete-value=1
mybatis-plus.global-config.db-config.logic-not-delete-value=0
```
3. 配置Mapper扫描器
在启动类中添加以下注解:
```
@MapperScan("com.example.demo.mapper")
```
4. 编写Mapper接口
使用Mybatis-Plus可以省略Mapper接口的编写,直接使用Mybatis-Plus提供的BaseMapper接口即可。如果需要自定义查询方法,可以继承BaseMapper并添加自定义方法。
5. 编写Service层
Service层可以直接调用Mapper层提供的方法,也可以自定义方法进行封装。
6. 编写Controller层
Controller层调用Service层提供的方法,处理请求返回结果。
以上就是SSM框架整合Mybatis-Plus的步骤。
阅读全文
相关推荐













