1. 编写接口多参数方法
/** * 多参数查询,注意要和Employeer.xml的方法名对应 */ public ListfindEmployeerByNameandDep(String employeer_name,String employeer_department);
2. 编写resultMap
3. 编写sql语句
由于是多参数那么就不能使用parameterType, 改用#{index}是第几个就用第几个的索引,索引从0开始
4. 编写查询方法
/** * 多参数查询列表 */ public static ListgetEmployeerList(String employeer_name,String employeer_department){ SqlSession session = null; List employeers=null; try { session = sqlSessionFactory.openSession(); EmployeerMapper employeerMapper=session.getMapper(EmployeerMapper.class); employeers = employeerMapper.findEmployeerByNameandDep(employeer_name, employeer_department); session.commit() ; } finally { session.close(); } return employeers; }
5. 编写测试类
public static void main(String[] args) { System.out.println("=========================使用多单参数查询==========================="); Listemployeers1=getEmployeerList("张三","产品二部"); for(Employeer employeer1:employeers1){ System.out.println(employeer1); }