注意事项:
1. <select id=“名字” 名字必须跟对应的mapper的方法名一致".参数类型也要一致!>
以下是对应的mapper方法名
<!--工单列表展示-->
<select id="getVirtualTaskDetailAndInfo" parameterType="map" resultType="map">
SELECT
t.id,
t.task_num,
t.apply_num,
t.province,
t.city,
t.`status`,
t.create_time,
t.enable_time,
t.end_time,
t.task_type,
p.attribution_number,
d.real_name
FROM
gkshop_virtual_task t
LEFT JOIN gkshop_virtual_phone p ON t.id = p.task_id
LEFT JOIN gkshop_phone_library l ON l.phone_number = p.attribution_number
LEFT JOIN gkshop_users_directories d ON d.`id` = l.`directories_id`
WHERE 1=1
<if test="taskStatus != null">
and t.`status` = #{taskStatus}
</if>
<if test="taskType != null">
AND t.task_type =#{taskType}
</if>
<if test="taskNum != null">
AND t.task_num = #{taskNum}
</if>
<if test="city != null">
AND t.city=#{city}
</if>
<if test="realName != null">
AND d.real_name = #{realName}
</if>
<if test="attributionNumber != null">
AND p.attribution_number = #{attributionNumber}
</if>
<if test="startTime != null and endTime != null ">
AND t.create_time BETWEEN #{startTime} and #{endTime}
</if>
<if test="orderBy != null ">
ORDER BY ${orderBy}
</if>
</select>
2. parameterType=“是什么类型的参数就给什么类型,对象就给对象”.封装成map也可以,但是map的key需要跟#{大括号里面一致}
比如你传了多个参数,这些参数你可以这样:
Map<String, Object> map = new HashMap<>();
if (!StringUtil.isEmpty(taskStatus)) {
map.put("taskStatus", taskStatus);
}
if (!StringUtil.isEmpty(city) && !("城市".equals(city))) {
map.put("city", city);
}
if (!StringUtil.isEmpty(city) && !("省份".equals(province))) {
map.put("province", province);
}
if (!StringUtil.isEmpty(realName)) {
map.put("realName", realName);
}
if (!StringUtil.isEmpty(attributionNumber)) {
map.put("attributionNumber", attributionNumber);
}
if (!StringUtil.isEmpty(taskNum)) {
map.put("taskNum", taskNum);
}
if (!StringUtil.isEmpty(taskType)) {
map.put("taskType", taskType);
}
if (!StringUtil.isEmpty(startTime) && !StringUtil.isEmpty(endTime)) {
map.put("startTime", startTime);
map.put("endTime", endTime);
}
//根据页面选择排序条件进行排序处理
if (StringUtil.isEmpty(orderBy)) {
orderBy = "t.create_time DESC";
map.put("orderBy", orderBy);
} else {
map.put("orderBy", orderBy);
}
List<Map<String, Object>> detailAndInfo = taskDOMapper.getVirtualTaskDetailAndInfo(map);
这样与之对应即可!