1. 程式人生 > >mybatis常用技巧(mapper檔案)

mybatis常用技巧(mapper檔案)


<select id="getPlanByFilter" parameterType="com.navinfo.imp.task.framework.bean.search.TskPlanFilterBean" resultType="com.navinfo.imp.task.bean.TskPlan">
	select 
		p.ID AS id,
		p.NAME AS name,
		p.PLAN_TYPE AS planType,
		p.PLAN_TYPE_NAME AS planTypeName,
		p.EST_START_TIME AS estStartTime,
		p.EST_END_TIME AS estEndTime,
		p.START_TIME AS startTime,
		p.END_TIME AS endTime,
		p.EST_WORKLOAD AS estWorkload,
		p.WORKLOAD AS workLoad,
		p.WORKLOAD_UNIT AS workloadUnit,
		p.CREATE_USER_ID AS createUserId,
		p.CREATE_USER_NAME AS createUserName,
		p.CREATE_TIME AS createTime,
		p.UPDATE_TIME AS updateTime,
		p.STATUS AS status,
		p.STATUS_NAME AS statusName,
		p.REMARK AS remark,
		p.PID AS pid
	from TSK_PLAN p left join TSK_TASK tt on tt.PLAN_ID = p.ID left join TSK_TASK_ASSIGN tta on tta.TASK_ID = tt.ID
	<where>
		<if test="bean.planStatus != null and bean.planStatus != ''">
			AND p.STATUS = '${bean.planStatus}'
		</if>
		<if test="bean.taskStatus != null and bean.taskStatus != ''">
			AND tt.STATUS LIKE '%${bean.taskStatus}%'
		</if>
		<if test="bean.taskType != null and bean.taskType != ''">
			AND tt.TASK_TYPE LIKE '%${bean.taskType}%'
		</if>
		<if test="bean.assigneeId != null">
			AND tta.ASSIGNEE_ID = ${bean.assigneeId}
		</if>
	</where>
	ORDER BY p.ID,p.START_TIME ASC
	</select>
在<where>元素中,bean被視為一個物件,可以用bean.xxx獲取其中的欄位的值。