使用Map集合和索引号
接口:
/** * 多条件查询Map集合 * @param map * @return */ public ListfindByManyCondition(Map map); /** * 多参数查询使用索引 * @param name * @param age * @return */ public List findStudentByCondition(String name,int age); xml文件(小配置)
测试类
/** * 多条件查询Map集合 */ @Test public void findByManyCondition(){ SqlSession session = MyBatisUtil.getSession(); IStudentDAO mapper = session.getMapper(IStudentDAO.class); Mapmap=new HashMap (); map.put("name","张"); map.put("age",20); List list = mapper.findByManyCondition(map); for (Student item:list){ System.out.println(item.getName()); } session.commit(); session.close(); }
/** * 多条件查询使用索引号 */ @Test public void findStudentByCondition(){ SqlSession session = MyBatisUtil.getSession(); IStudentDAO mapper = session.getMapper(IStudentDAO.class); Listlist = mapper.findStudentByCondition("张", 20); for (Student item:list){ System.out.println(item.getName()); } session.commit(); session.close(); }