List<User> selectUserListByType(Map map);
以这个方法为例:其中参数map的键里面存储的是根据什么类型代码查询假设三个值(100,101,102),而值是list类型的数组,或者一些String,那么相对应的xml的文件实现的话就类似下面的这些代码(这个只是给我做记忆的不为了其他):
<?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.mapper.UserMapper">
<!--其他的类型UserResultMap以及sql这些省略-->
<select id="selectUserListByType" resultMap="UserResultMap"
parameterType="Map">
SELECT
<include refid="Base_Column_List" />
FROM account,profile
<where>
<!-- 下面if判断中的type为查询的类型, 其中100为根据id集合查询, 101为根据profile的name属性模糊查询, 102为根据根据手机号(account的username属性,profile的phone属性)查询,
目前需求只是单个手机号,不过也适用 -->
<if test="type==100">
account.id IN (
<foreach item="p" collection="params" separator=",">
#{p}
</foreach>
)
</if>
<if test="type==101">
profile.name like '%${params}%'
</if>
<if test="type==102">
account.username IN (
<foreach item="p" collection="params" separator=",">
#{p}
</foreach>
)
</if>
</where>
AND account.id=profile.uid;
</select>
</mapper>