mybaitis 排序筛选,按参数指定
<choose> <when test="sort != null and sort.trim() != ''"> order by ${sort} ${order} </when> <otherwise> order by a.id desc </otherwise> </choose>
choose标签里是sort 是排序字段,order是 排序类型desc 或者 asc,此标签放在where标签后面
贴一段实战sql
<select id="searchSettlePage" resultType="org.springblade.edo.settle.vo.SettleAccountPageVO"> <include refid="search_settle"/> -- ORDER BY s.create_date DESC <choose> <when test="request.orderBy != null and request.orderBy != '' and request.orderBy == 'voucher_no'"> ORDER BY s.voucher_no ${request.orderRule} </when> <otherwise> ORDER BY COALESCE(o.reference_code_mark, s.reference_code_mark) IS NULL, COALESCE(o.reference_code_mark, s.reference_code_mark,s.create_date) </otherwise> </choose> </select>
下班记得打卡