这是修改之后的<select id="findod" parameterType="map" resultMap="odMap"> select * from order_day where 1 = 1 <if test="start != null and start != ''"> and date >= #{start} </if> <if test="end != null and end != ''"> and #{end} > date </if> <if test="appid != null and appid != ''"> and appid=${appid} </if> <if test="operators != null and operators != ''"> and operators=${operators} </if> limit ${Page.startPos},${Page.pageSize}; </select> 就把parameterType="java.lang.Map" 改成="map"了,不过好像这个没关系然后if判断的条件直接就写map里边的key值,不管它是不是POJO类里边的,反正写KEY值就是了。不知道我理解的对不对,反正是行得通了。
MyBatis,数据库映射这一块。 <if test="end != null and end != ''">and #{end} > date </if>参数是你方法里面传过来参数的实体解析,或者键值对的解析。parameterType是参数类型。可以是map,也可以是你的实体类(完整的包名)
啊。我说的是if判断的条件,不是sql的部分。我知道sql使用 #{key}或者${key}来获取。 我说的是
<if test="** != null">这里的**怎么获取map中的值
select * from order_day where 1 = 1
<if test="start != null and start != ''">
and date >= #{start}
</if>
<if test="end != null and end != ''">
and #{end} > date
</if>
<if test="appid != null and appid != ''">
and appid=${appid}
</if>
<if test="operators != null and operators != ''">
and operators=${operators}
</if>
limit ${Page.startPos},${Page.pageSize};
</select>
就把parameterType="java.lang.Map" 改成="map"了,不过好像这个没关系然后if判断的条件直接就写map里边的key值,不管它是不是POJO类里边的,反正写KEY值就是了。不知道我理解的对不对,反正是行得通了。
哦~~了解了。3Q