修改下面mybatis语句select <choose> <when test="laborCostCity != null and laborCostCity !=''"> ${laborCostCity} as laborCost </when> <when test="serveCostType == null and serveCostType !=''"> ${serveCostType} as serveCost </when> </choose> from t_grading_new
时间: 2024-02-10 14:18:29 浏览: 29
这段 MyBatis 语句存在一些问题,可以尝试如下修改:
```
<select>
<choose>
<when test="laborCostCity != null and laborCostCity !=''">
SELECT ${laborCostCity} AS laborCost
</when>
<when test="serveCostType != null and serveCostType !=''">
SELECT ${serveCostType} AS serveCost
</when>
<otherwise>
SELECT * <!-- 如果没有上述两种情况,则查询所有列 -->
</otherwise>
</choose>
FROM t_grading_new
</select>
```
修改后的语句添加了 `<select>` 标签,同时在 `<choose>` 标签中添加了 `<otherwise>` 标签,以处理没有满足 `<when>` 条件的情况。此外,还修改了 `<when>` 条件判断中的 `serveCostType == null`,将其改为 `serveCostType != null`,避免出现语法错误。
相关问题
修改下面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
根据你的需求,我修改了下面的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的记录。
<select id="pageQueryAllShouLiDanRecordNew" resultType="java.util.Map"> SELECT ${param} ,B.FLOWID,B.YYWORKSEQ,B.KDWORKSEQ FROM WF_BASE_FORM_INFO B where B.STATUS_ID < 100 AND B.PRODUCTID='0' ${where} <if test="FGSCode != '' and FGSCode != null"> AND B.FGS_Code in (#{FGSCode}) </if> <if test="ZHWGID != '' and ZHWGID != null"> AND B.ZHWGID in (#{ZHWGID}) </if> <choose> <when test="KDCompany == 3"> AND B.KDCOMPANY = '3' </when> <otherwise> AND B.KDCOMPANY in ('1','4','99') </otherwise> </choose> <if test="orderBy !=null and orderBy != ''"> ${orderBy} </if> <if test="orderBy ==null or orderBy == ''"> ORDER BY B.RECEIVE_TIME DESC </if> </select> 这段代码是什么意思
这段代码是一个 MyBatis 的 SQL 映射语句。它的作用是从 WF_BASE_FORM_INFO 表中查询符合条件的记录,并返回一个包含流程ID、YYWORKSEQ、KDWORKSEQ等字段的 Map 对象列表。
具体来说,它会根据传入的参数 ${param}、${where}、#{FGSCode}、#{ZHWGID}、${orderBy} 等条件进行筛选,其中:
- STATUS_ID < 100 且 PRODUCTID='0' 是筛选条件的一部分;
- 如果传入的 FGSCode 不为空,则会额外筛选 FGS_Code 列;
- 如果传入的 ZHWGID 不为空,则会额外筛选 ZHWGID 列;
- 如果传入的 KDCompany 等于 3,则会额外筛选 KDCOMPANY = '3',否则会筛选 KDCOMPANY in ('1', '4', '99');
- 如果传入的 orderBy 不为空,则按照该字段进行排序,否则按照 RECEIVE_TIME 倒序排列。
最后,符合条件的记录会被封装成一个 Map 对象列表并返回。