mybatis 动态查询
一、子查询与动态条件查询
select pa.id, pa.dept_id, pa.vehicle_id, pa.maint_apply_time, pa.valid_flag,
pa.repair_depot_id, pa.maint_items, pa.total_price, pa.remark, pa.mileage_now,pa.cost_level,pa.maint_type,
pa.maint_mode,pa.reporter_name,pa.apply_remark, pa.first_flag, pa.driver_id,pa.reporter_id,pa.gmt_modified,
m.repair_depot_id as modifyRepairDepotId,m.maint_type as modifyMaintType,m.apply_remark as modifyApplyRemark,
m.cost_level as modifyCostLevel
from process_maint_apply_outside pa
left JOIN (SELECT apply_id,repair_depot_id,maint_type,cost_level,apply_remark, MAX(gmt_create) AS max_createdate
FROM process_maint_apply_outside_modify
GROUP BY apply_id) m on m.apply_id =pa.id
where pa.reporter_id = #{map.userId}
<!--动态条件查询 -->
<if test="map.maintType!=null and map.maintType!=''">
and ((m.maint_type is not null and m.maint_type = #{map.maintType}) or (m.maint_type is null and pa.maint_type= #{map.maintType}))
</if>
浙公网安备 33010602011771号