需求:分页查询tbl_employee表中,年龄在18~50之间,性别为男,姓名为Tom的所有用户。
注意:**两个条件不添加 and或 or之类的连接符,默认是 and。
package com.wzy;import com.baomidou.mybatisplus.mapper.EntityWrapper;import com.baomidou.mybatisplus.plugins.Page;import com.wzy.mapper.EmployeesMapper;import com.wzy.pojo.Employees;import org.junit.Test;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;import javax.sql.DataSource;import java.sql.Connection;import java.sql.SQLException;import java.util.List;public class TestS {//1.读取配置文件private ApplicationContext applicationContext =new ClassPathXmlApplicationContext("applicationContext.xml");private EmployeesMapper employeesMapper =applicationContext.getBean("employeesMapper", EmployeesMapper.class);@Testpublic void test3() throws SQLException {List<Employees> employees = employeesMapper.selectPage(new Page<Employees>(1, 2),new EntityWrapper<Employees>().between("age", 18, 50).and().//可不写。不写默认也是and连接eq("gender", 1).and().//可不写。不写默认也是and连接eq("last_name", "Tom"));employees.forEach(employees1 -> System.out.println(employees1));}}
