第一步:导入插件坐标:
<!-- mybatis-plus插件依赖 -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus</artifactId>
<version>3.1.1</version>
</dependency>
第二步:在mapper接口上继承BaseMapper:
public interface UserMapper extends BaseMapper<User> {
}
第三步:修改sqlSessionFactory:
<bean id="sqlSessionFactory" class="com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="plugins">
<array><!--分页插件-->
<bean class="com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor"></bean>
</array>
</property>
</bean>
第四步:测试:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:applicationContext.xml")
public class TestSpringMP {
@Autowired
private UserMapper userMapper;
/**
* 查询所有
*/
@Test
public void testSelectList() {
List<User> users = this.userMapper.selectList(null);
for (User user : users)
System.out.println(user);
}
测试结果:
![](https://i-blog.csdnimg.cn/blog_migrate/225ace0f834213ae16a1b1ce3bac7453.png)