接口:
public List<FuZhuang> showalldescdesc1(@Param("offset") int offset, @Param("limit") int limit,@Param("price") String price,@Param("xiaoliang") String xiaoliang,@Param("str") String str);
对应的XML映射文件:
<select id="showalldescdesc1" resultType="FuZhuang">
SELECT * FROM fuzhuang
<choose>
<when test="str=='1'">
<if test="price== 'desc'">
ORDER BY price DESC
</if>
<if test="price== 'asc'">
ORDER BY price ASC
</if>
</when>
<when test="str=='2'">
<if test="xiaoliang== 'desc'">
ORDER BY yuexiaoliang DESC
</if>
<if test="xiaoliang== 'asc'">
ORDER BY yuexiaoliang ASC
</if>
</when>
<otherwise>
ORDER BY yuexiaoliang DESC
</otherwise>
</choose>
LIMIT #{offset},#{limit};
</select>
debug得出的个参数值:
理论上是执行ORDER BY price DESC可是还是执行otherwise里面的ORDER BY yuexiaoliang DESC,为什么啊?求解。。。在线等 。。。。
------最佳解决方案--------------------------------------------------------
把 str=='1' 改成str==1
------其他解决方案--------------------------------------------------------
把when里面的条件改成str!=null就可以了 可能是<when test="str=='1'">的问题 但是想要str=1时就执行里面的语句该怎么写 !!!!