• 周二. 4月 23rd, 2024

5G编程聚合网

5G时代下一个聚合的编程学习网

热门标签

在controller写sql在mapper拼接

admin

11月 28, 2021

这是在controller里面:

String search = “”;
if(“null”.equals(start_time)||””.equals(start_time))
search += ” “;
else{
search += ” and to_char(A.create_time, ‘YYYY-MM-DD’) >= ‘”+start_time+”‘”;
}
if(“null”.equals(end_time)||””.equals(end_time))
search += ” “;
else{
search += ” and to_char(A.create_time, ‘YYYY-MM-DD’) <= ‘”+end_time+”‘”;
}

if(“null”.equals(followType)||””.equals(followType)){
search += ” “;
}else{
if(“0”.equals(followType)){
search += ” “;
}else{
search += ” and A.S_FORM_ID ='”+followType+”‘”;
}
}

conMap.put(“search”, search);
conMap.put(“userId”, userId);
conMap.put(“page”, page);
conMap.put(“pageSize”, pageSize);
followTypeList = followupService.searchfollowTypeMiList(conMap);

传到mapper

这是在mapper里面:

SELECT * FROM (
SELECT PATIENT_ID,
USER_NAME,
RECORD_ID,
S_FORM_ID,
S_FORM_NAME,
CREATE_TIME,
ROWNUM rn
FROM (select ROWNUM,
C.PATIENT_ID,
C.USER_NAME,
A.RECORD_ID,
A.S_FORM_ID,
B.S_FORM_NAME,
to_char(A.CREATE_TIME, ‘YYYY-MM-DD HH24:mi:ss’) as CREATE_TIME
from T_SELF_MEA_RECORD A, T_SELF_MEA_FORM B, T_PATIENT_INFO C
where A.S_FORM_ID = B.S_FORM_ID
AND A.PATIENT_ID = C.PATIENT_ID
AND A.PATIENT_ID = #{userId}
${search}
ORDER BY A.CREATE_TIME DESC)
WHERE ROWNUM &lt;= #{page} * #{pageSize,jdbcType=NUMERIC} )
WHERE rn &gt;= ((#{page} – 1) * #{pageSize,jdbcType=NUMERIC}) + 1

从而实现了拼接

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注