mybatis-字符串判断

来源:互联网 发布:vscode 代码提示 编辑:程序博客网 时间:2024/06/05 07:20
<select id="pageQueryAu"
parameterType="com.test.vo.PubParams"
resultMap="auVoResult">
SELECT 
a.au_id, a.au_name_cn, l.language, a.release_company,
        p.publisher_id, p.publisher_cn, 
<choose>
<when test="codeType == '2'.toString()">
a.i_status as mpr_status, 
2 as code_type, 
</when>
<otherwise>
a.m_status, 
1 as code_type, 
</otherwise>
</choose>
        a.create_time apply_code_time, a.app_time send_code_time 
        FROM 
        t_au a
  INNER JOIN 
  t_pub p ON a.publisher_id = p.publisher_id 
  LEFT JOIN 
  t_lang l ON a.language = l.lang_id 
  WHERE 
  p.group_id = #{groupId} 
<if test="publicationName != null and publicationName != ''">
AND LOWER(a.audio_name_cn) LIKE '%' || LOWER(TRIM(#{publicationName})) || '%'
</if>
  <if test="publisherCn != null and publisherCn != ''">
AND LOWER(p.publisher_cn) LIKE '%' || LOWER(TRIM(#{publisherCn})) || '%'
</if>
<if test="status != null and status != '' and codeType == '2'.toString()">
AND a.i_status = #{status}
</if>
<if test="status != null and status != '' and codeType == '1'.toString()">
AND a.m_status = #{status}
</if>
<!-- 
某个隐藏的SQL会将这个code_type的值由2改成了1,因此不用这个字段判断

<if test="codeType != null and codeType != ''">
AND a.code_type = #{codeType}
</if>
-->
<if test="codeType == '2'.toString()">
AND a.i_status is not null 
</if>
<if test="codeType == '1'.toString()">
AND a.m_status is not null 
</if>
ORDER BY
<choose>
<when test="order != null and order != ''">
${order} ${sort}
</when>
<otherwise>
a.create_time DESC
</otherwise>
</choose>
  limit #{rows} offset (#{page} - 1) * #{rows}

</select>



<resultMap id="auVoResult"
type="com.test.vo.AuVo"
extends="baseVoRsult">
<id property="auId" column="au_id" />
<result property="auNameCn" column="au_name_cn" />
<result property="language" column="language" />
<result property="releaseCompany" column="release_company" />
</resultMap>

0 0
原创粉丝点击