标签:clipboard title height delete info etl 老师 strong 用法
1、EntityWrapper_Condition简介
Mybatis-Plus 通过 EntityWrapper(MP 封装的一个查询条件构造器)或者 Condition(继承Wrapper) 来让用户自由的构建查询条件,简单便捷,没有额外的负担, 能够有效提高开发效率
2、selectPage方法
@Test public void testEntityWrapperSelect(){ //分页查询 tbl_employee 表中,年龄在 18~50 之间性别为男且 姓名为 xx 的所有用户 List<Employee> employees = employeeMapper.selectPage(new Page<>(1, 3), new EntityWrapper<Employee>() .between("age", 18, 50) .eq("gender", 1) .eq("last_name", "Tom") ); for(Employee e:employees){ System.out.println(e); } }
3、selectList方法
List<Employee> emps = employeeMapper.selectList( new EntityWrapper<Employee>() .eq("gender", 0) .like("last_name", "老师") //.or() // SQL: (gender = ? AND last_name LIKE ? OR email LIKE ?) .orNew() // SQL: (gender = ? AND last_name LIKE ?) OR (email LIKE ?) .like("email", "a") );
4、update()
@Test public void testEntityWrapperUpdate() { Employee employee = new Employee(); employee.setLastName("苍老师"); employee.setEmail("cls@sina.com"); employee.setGender(0); employeeMapper.update(employee, new EntityWrapper<Employee>() .eq("last_name", "Tom") .eq("age", 44) ); }
5、delete方法
@Test public void testEntityWrapperDelete() { employeeMapper.delete( new EntityWrapper<Employee>() .eq("last_name", "Tom") .eq("age", 22) );
6、EntityWrapper其他常用方法
7、Condition的用法
List<Employee> userListCondition = employeeMapper.selectPage(new Page<Employee>(2, 3), Condition.create() .eq("gender", 1) .eq("last_name", "MyBatisPlus") .between("age", 18, 50));
标签:clipboard title height delete info etl 老师 strong 用法
原文地址:https://www.cnblogs.com/houchen/p/13511491.html