<!--查询姓名中包含“雨”,并且年龄>20的学生信息-->
public List<StudentInfo> findStudentsByCondition(Map<String,Object> map);
<!--多条件查询-->
<select id="findStudentsByCondition" resultType="StudentInfo">
select * from studentinfo where stuname like '%' #{stuName} '%' and stuAge>#{stuAge}
</select>
多条件查询
@Test
public void testSelectLike(){
SqlSession session= MyBatisUtil.getSession();
IStudentInfoDAO dao = session.getMapper(IStudentInfoDAO.class);
Map<String,Object> map=new HashMap<String,Object>();
map.put("stuName","雨");
map.put("stuAge",20);
List<StudentInfo> list = dao.findStudentsByCondition(map);
for (StudentInfo stu:list) {
System.out.println(stu.getStuName());
}
session.close();
}
}
<!--查询姓名中包含“雨”,并且年龄>20的学生信息-->
public List<StudentInfo> findStudentsByConditionMutliArgs(String stuName,int stuAge);
<!--多条件查询使用索引-->
<select id="findStudentsByConditionMutliArgs" resultType="StudentInfo">
select * from studentinfo where stuname like '%' #{0} '%' and stuAge>#{1}
</select>
//多条件查询
@Test
public void testSelectLikeMulti(){
SqlSession session= MyBatisUtil.getSession();
IStudentInfoDA
20的学生信息--> public List findStudentsByCondition(Map map); select * from studentinfo where stuname like '%' #{stuName} '%' and stuAge>#{stuAge} 多条件查询 @Test public void