mybatis-plus在springmvc中的配置 java
时间: 2024-01-06 10:16:40 浏览: 46
好的,以下是在 Spring MVC 中配置 MyBatis-Plus 的步骤:
1. 首先,需要在项目的 pom.xml 文件中添加 MyBatis-Plus 的依赖:
```xml
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.3.1</version>
</dependency>
```
2. 在 Spring MVC 的配置文件中添加 MyBatis-Plus 的配置,例如在 applicationContext.xml 中添加:
```xml
<!-- MyBatis-Plus 配置 -->
<bean id="mybatisPlusConfig" class="com.baomidou.mybatisplus.core.MybatisConfiguration">
<property name="mapUnderscoreToCamelCase" value="true" />
</bean>
<!-- 数据源配置 -->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<!-- MyBatis-Plus SqlSessionFactory 配置 -->
<bean id="sqlSessionFactory" class="com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configuration" ref="mybatisPlusConfig" />
<property name="mapperLocations" value="classpath*:mapper/**/*.xml" />
</bean>
<!-- MyBatis-Plus MapperScannerConfigurer 配置 -->
<bean class="com.baomidou.mybatisplus.extension.spring.MybatisPlusAutoConfiguration">
<property name="basePackage" value="com.example.mapper" />
</bean>
```
注意:其中的 dataSource 配置需要根据实际情况进行修改。
3. 在 Spring MVC 的配置文件中添加 MyBatis-Plus 的插件配置,例如在 applicationContext.xml 中添加:
```xml
<!-- MyBatis-Plus 插件配置 -->
<bean class="com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor">
<property name="overflow" value="false" />
</bean>
```
至此,MyBatis-Plus 在 Spring MVC 中的配置就完成了。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)