way1:参数类型封装到map中#{参数}--->map的键(此时参数类型为java.util.Map或map)
*若xml文件中出现了特殊字符
way1:使用转义字符
way2:使用<![CDATA[ ]]>
*映射文件UserMapper.xml:
1 <select id="selectway1" parameterType="map" 2 resultType="com.zhiyou.clg.bean.User"> 3 <![CDATA[select * from user where age>=#{min} and age<=#{max}]]> 4 <!-- select *from user where age between #{min} and #{max} --> 5 </select> 1 @Test 2 void testselectway1() throws IOException { 3 Map<String, Integer> map=new HashMap<String, Integer>(); 4 map.put("min", 18); 5 map.put("max", 19); 6 7 List<User> list=session.selectList(str+".selectway1",map); 8 System.out.println(list); 9 }
*若xml文件中出现了特殊字符
way1:使用转义字符
way2:使用<![CDATA[ ]]>
way2:封装一个实体类