在做[b]mybatis[/b]物理端分页的过程中遇到通过遍历page对象中的参数[b]map[/b]来拼写动态SQL,而传入的paramType类型是page对象,这个map中的key是数据库中的字段SQL的where条件是[b]key=value[/b]
<select id="getEmployeePage" resultType="Employee" parameterType="Page" >
SELECT * FROM t_employee
<if test="null != params and params.size()> 0"> WHERE '1'='1' </if>
<foreach collection="params" index="key" item="item" open="" close="" >
<choose>
<when test="key =='RealName' and item !=null and item !=''">
and ${key} LIKE CONCAT(CONCAT('%', #{params.${key}}), '%')
</when>
<when test=" item != null and item!=''">
and ${key} = #{params.${key}}
</when>
<otherwise>
</otherwise>
</choose>
</foreach>
</select>