MyBatisPlus查询方法selectById、selectOne、selectBatchIds、selectByMap、selectPage的使用
程序员文章站
2022-03-26 16:52:05
...
场景
项目搭建专栏:
https://blog.csdn.net/BADAO_LIUMANG_QIZHI/column/info/37194
基础搭建:
https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/89407994
实现
selectById查询
/***
* 通用查询操作 通过ID查询
*/
@Test
public void testCommomSelectById() {
Employee employee=employeeMapper.selectById(1);
System.out.println("*******************"+employee);
}
selectOne查询
/***
* 通用查询操作 selectOne 最多只能查到一个
*/
@Test
public void testCommomSelectOne() {
Employee employee = new Employee();
employee.setId(3);
employee.setName("气质");
Employee employeeresult=employeeMapper.selectOne(employee);
System.out.println("*******************"+employeeresult);
}
selectBatchIdsvc查询
/***
* 通用查询操作 selectBatchIds 通过多个ID进行查询
*/
@Test
public void testCommomSelectBatchIds() {
List<Integer> idList = new ArrayList<Integer>();
idList.add(1);
idList.add(2);
idList.add(3);
List<Employee>employeeList=employeeMapper.selectBatchIds(idList);
System.out.println("*******************"+employeeList);
for (Employee employee : employeeList) {
System.out.println(employee.getName());
}
}
selectbyMap查询
/***
* 通用查询操作 selectByMap map要写列名条件 不能是实体属性名
*/
@Test
public void testCommomSelectByMap() {
Map<String, Object> columnMap = new HashMap<String, Object>();
columnMap.put("name", "气质");
columnMap.put("gender", "0");
List<Employee> employeeList=employeeMapper.selectByMap(columnMap);
System.out.println("*******************"+employeeList);
for (Employee employee : employeeList) {
System.out.println(employee.getName());
}
}
selectByPage查询
分页查询,第二个参数为条件构造器这里置为空。
/***
* 通用查询操作 selectByPage
*/
@Test
public void testCommomSelectByPage() {
List<Employee> employeeList=employeeMapper.selectPage(new Page<Object>(2, 2), null);
System.out.println("*******************"+employeeList);
for (Employee employee : employeeList) {
System.out.println(employee.getName());
}
}
源码下载
https://download.csdn.net/download/badao_liumang_qizhi/11133873
上一篇: POJ 3614 贪心