查询
1.查询单个数据
	//测试查询
	@Test
	public void testSelect(){
		User user = userMapper.selectById(1L);
		System.out.println(user);
	}
2.批量查询
@Test
	public void testSelect(){
		//单个数据查询
		//User user = userMapper.selectById(1L);
		//System.out.println(user);
		//测试批量查询
		List<User> users = userMapper.selectBatchIds(Arrays.asList(1, 2, 3));
		users.forEach(System.out::println);
	}
3. 测试条件查询
//测试条件查询 map
	@Test
	public void testselectmap(){
		HashMap<String, Object> map1 = new HashMap<>();
		//自定义查询
		map1.put("name","左小妹");
		List<User> users = userMapper.selectByMap(map1);
		users.forEach(System.out::println);
	}
//测试条件查询 map
	@Test
	public void testselectmap(){
		HashMap<String, Object> map1 = new HashMap<>();
		//自定义查询
		map1.put("name","左小妹");
		map1.put("age",18);
		List<User> users = userMapper.selectByMap(map1);
		users.forEach(System.out::println);
	}
分页查询
1. 原始的limit分页查询
2.第三方插件(pagehelper)
3.MP中内置了分页插件
(1)配置拦截器

 //分页插件
    @Bean
    public PaginationInnerInterceptor paginationInnerInterceptor(){
        PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor();
        return paginationInnerInterceptor;
    }(2)直接使用Page对象即可
//测试分页插件
	@Test
	public void testPage(){
		Page<User> page = new Page<>(2,3);//当前页、页面大小
		userMapper.selectPage(page,null);
		page.getRecords().forEach(System.out::println);
	}版权声明:本文为weixin_43361166原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。

