1.导入mybatis-plus包
<dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus</artifactId> <version>2.1-gamma</version> </dependency> <dependency> <groupId>org.apache.velocity</groupId> <artifactId>velocity</artifactId> <version>1.7</version> </dependency>
2.替换 spring.xml 配置文件中的 sqlSessionFactory
<!-- MyBatis SqlSessionFactoryBean 配置 --> <bean id="sqlSessionFactory" class="com.baomidou.mybatisplus.spring.MybatisSqlSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="configLocation" value="/WEB-INF/classes/mybaties/mybatis-config.xml" /> <property name="typeAliasesPackage" value="com.entity" /> <property name="mapperLocations" value="/WEB-INF/classes/mapper/xml/*.xml" /> <property name="plugins"> <array> <!-- 分页插件配置 --> <bean id="paginationInterceptor" class="com.baomidou.mybatisplus.plugins.PaginationInterceptor"> <property name="dialectType" value="mysql" /> </bean> </array> </property> <!-- MP 全局配置注入 --> <property name="globalConfig" ref="globalConfig"/> </bean> <!-- 定义 MP 全局策略 --> <bean id="globalConfig" class="com.baomidou.mybatisplus.entity.GlobalConfiguration"> <!-- 主键策略配置 --> <!-- 可选参数 AUTO->`0`("数据库ID自增") INPUT->`1`(用户输入ID") ID_WORKER->`2`("全局唯一ID") UUID->`3`("全局唯一ID") --> <property name="idType" value="0"/> <!-- 数据库类型配置 --> <!-- 可选参数(默认mysql) MYSQL->`mysql` ORACLE->`oracle` DB2->`db2` H2->`h2` HSQL->`hsql` SQLITE->`sqlite` POSTGRE->`postgresql` SQLSERVER2005->`sqlserver2005` SQLSERVER->`sqlserver` --> <!--<property name="dbType" value="oracle"/>--> <!-- 全局表为下划线命名设置 true --> <property name="dbColumnUnderline" value="true"/> </bean>