/*---------------------------模糊查询需要注意接收结果方式----------------------*/
//当有多个结果时 如果使用selectOne查询 使用单个变量接收 会报TooManyResultException
/*Category cs=session.selectOne("selectByName","手动设置");
System.out.println(cs.getId()+" "+cs.getName());*/ //报错!!!!!
//有多个结果 使用selectOne查询 使用集合接收 报错
//List<Category> test=session.selectOne("selectByName", "手动设置");
//可能有多个结果 但是本次查询只有一个结果 成功通过
/* Category c1=session.selectOne("selectByName","开始");
System.out.println(c1.getId()+" "+c1.getName());*/
//可能有多个结果 但是本次插叙只有一个结果 编译无法通过
/* Category c2=session.selectList("selectByName", "开始");*/
//多个结果需要使用集合 正确写法
/*List<Category> result=session.selectList("selectByName", "手动设置");
for(Category c:result)
{
System.out.println(c.getId()+" "+c.getName());
}*/
/***---------------------多参数查询问题------------------*/
Map<String,Object> map=new HashMap<>();
map.put("id", 101);
map.put("name", "手动");
Category cs=session.selectOne("selectByIN", map);
System.out.println(cs.getId()+" "+cs.getName());
session.close();
<!-- 模糊查询 -->
<select id="selectByName" parameterType="string" resultType="Category">
select * from category where name like concat("%",#{0},"%")
</select>
<select id="selectByIN" parameterType="map" resultType="Category">
select * from category where id = #{id} and name like concat("%",#{name},"%")
</select>
关于映射文件中的paramterType和parameterType
paramterType用于传入单个参数,这个参数可以是JAVA支持的各种类型,包括基本数据类型和引用类型
paramterMap用于传入多个参数,一般不支持使用