mybatisPlus-查询测试
1 根据id查询
src/test/java/com/lv/mybatis_plus/MybatisPlusApplicationTests.java
//测试查询
@Test
public void testSelectById(){
User user = userMapper.selectById(1L);
System.out.println(user);
}
控制台
2 根据id查询多个
src/test/java/com/lv/mybatis_plus/MybatisPlusApplicationTests.java
//根据id查询多个
@Test
public void selectByBatchId(){
List<User> users = userMapper.selectBatchIds(Arrays.asList(1, 2, 3));
users.forEach(System.out::println);
}
控制台
3 根据条件查询
src/test/java/com/lv/mybatis_plus/MybatisPlusApplicationTests.java
//按条件查询之一 使用map操作
@Test
public void testSelectByBatchIds(){
HashMap<String, Object> map = new HashMap<>();
//自定义要查询的内容
map.put("name","Jack");
map.put("age",20);
List<User> users = userMapper.selectByMap(map);
users.forEach(System.out::println);
}
控制台