修改下面mybatis语句 select <choose> <when test="laborCostCity != null and laborCostCity !='' and serveCostType == null and serveCostType !=''"> ${laborCostCity} as laborCost,${serveCostType} as serveCost </when> </choose> from t_grading_new where `rank`=#{rank} and delFlag =0
时间: 2024-02-10 09:18:29 浏览: 57
MyBatis-03动态SQL-01.<if>元素的使用
根据你的需求,我修改了下面的MyBatis语句:
```
<select>
<choose>
<when test="laborCostCity != null and laborCostCity !='' and serveCostType != null and serveCostType !=''">
SELECT ${laborCostCity} AS laborCost, ${serveCostType} AS serveCost
</when>
<otherwise>
SELECT laborCost, serveCost
</otherwise>
</choose>
FROM t_grading_new
WHERE `rank` = #{rank}
AND delFlag = 0
</select>
```
这个语句可以根据条件动态选择要查询的字段,如果`laborCostCity`和`serveCostType`都非空,则查询这两个字段。否则,查询全部字段`laborCost`和`serveCost`。同时,筛选出`rank`等于参数`#{rank}`并且`delFlag`等于0的记录。
阅读全文