mybatis-plus之简单查询 *** 作、分页查询

mybatis-plus之简单查询 *** 作、分页查询,第1张

查询 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 users = userMapper.selectBatchIds(Arrays.asList(1, 2, 3));
		users.forEach(System.out::println);
	}

3. 测试条件查询
//测试条件查询 map
	@Test
	public void testselectmap(){
		HashMap map1 = new HashMap<>();
		//自定义查询
		map1.put("name","左小妹");
		List users = userMapper.selectByMap(map1);
		users.forEach(System.out::println);
	}

 

//测试条件查询 map
	@Test
	public void testselectmap(){
		HashMap map1 = new HashMap<>();
		//自定义查询
		map1.put("name","左小妹");
		map1.put("age",18);
		List 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 page = new Page<>(2,3);//当前页、页面大小
		userMapper.selectPage(page,null);
		page.getRecords().forEach(System.out::println);
	}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/734179.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-27
下一篇 2022-04-27

发表评论

登录后才能评论

评论列表(0条)

保存