#{}中可以放的值
1.1.对象属性
1.2.任意值
1.3.map的key值(key对应的value类型是基本数据类型或者是字符串)
1.4.如果map的key对应的value是一个对象,则放对象的属性
1.5.索引号
public interface StudentMapper {
List<Student> selectByCondition(String name,int age);
List<Student> selectByCondition1(Map<String, Object> stuMap);
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bjsxt.mapper.StudentMapper">
<select id="selectByCondition1" resultType="Student">
select id,name,age,score from student
where name like '%' #{nameCon} '%'
and age >#{ageCon}
and score >#{stu.score}
</select>
<!-- #{}中可以放的值
1.对象属性
2.任意值
3.map的key值(key对应的value类型是基本数据类型或者是字符串)
4.如果map的key对应的value是一个对象,则放对象的属性
5.索引号
-->
</mapper>
@Test
public void testSeletcByName1(){
Map<String, Object> stuMap = new HashMap<String,Object>();
stuMap.put("nameCon", "三");
stuMap.put("ageCon", 25);
List<Student> list=mapper.selectByCondition1(stuMap);
for (Student student : list) {
System.out.println(student);
}
}
@Test
public void testSeletcByName2(){
Student stu = new Student("赵六",26,97.4);
Map<String, Object> stuMap = new HashMap<String,Object>();
stuMap.put("nameCon", "三");
stuMap.put("ageCon", 25);
stuMap.put("stu",stu);
List<Student> list=mapper.selectByCondition1(stuMap);
for (Student student : list) {
System.out.println(student);
}
}