MyBatis(一)select语句拼接方式
<select id="selectByForm" parameterType="com.xxx.controller.request.DeliveryQueryForm" resultMap="FullResultMap"> select <if test="distinct"> distinct </if> 'true' as QUERYID, ro.order_code as order_code, ro.code as code, ro.name as name, ro.reception_date as reception_date,r.status as status, d.driver_name as driver_name from tbl_order_drivers_relation r left join tbl_reservation_order ro on ro.order_code = r.order_code left join mst_drivers d on d.driver_id = r.driver_id <if test="_parameter != null"> <include refid="Example_Where_Clause_Form" /> </if> order by r.create_time </select> <sql id="Example_Where_Clause_Form"> <where> <if test="orderCode != null and orderCode != ''"> AND r.order_code = #{orderCode} </if> <if test="name != null and name != ''"> AND ro.name like CONCAT(CONCAT('%', #{name}), '%') </if> </where> </sql>