一.传递简单类型
参考mybatis_mapper的例子。
二.传递pojo类型
参考mybatis_sql中的需求1。
三.传递pojo包装类型
一般包含多个对象的综合查询。
参考mybatis_sql中的需求2。
四.传递HashMap
1.mapper接口
List<User> findUserByName(HashMap<String,String> map) throws Exception;
2.sql映射文件
<select id="findUserByName" parameterType="HashMap" resultType="user">
select * from user
<where>
<include refid="whereAndIf"/>
</where>
</select>
<sql id="whereAndIf">
<if test="user.username!=null and user.username!=''">
and username like '%${user.username}%'
</if>
</sql>
3.测试
//......
HashMap<String,String> map = new HashMap<>();
map.put("username","rr");
UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
List<User> list = (List<User>) userMapper.findUserByName(map);
System.out.println(list.size());
sqlSession.close();