mybatis中sql语句怎么写
1个回答
展开全部
<select id="queryUsers" parameterType="map" resultType="xx.xx.xx.bean.UserBean">
<![CDATA[
select
ID,
LOGIN_NAME AS loginName,
PASSWORD,
REAL_NAME AS realName,
POSITION,
(SELECT D.POSITION_NAME FROM UNIT_POSITION D WHERE D.POSITION_CODE=T.POSITION) POSITIONNAME,
USER_TYPE AS userType,
SEX,
PID,
TO_CHAR(T.BIRTHDAY,'YYYY-MM-DD') BIRTHDAY,
EMAIL,
CONTACT_TEL AS contactTel,
CONTACT_MOBILE AS contactMobile,
CONTACT_FAX AS contactFax,
CONTACT_ZIP AS contactZip,
CONTACT_ADDR AS contactAddr,
STATUS,
EDUCATION,
(SELECT D.EDUCATION_NAME FROM UNIT_EDUCATION D WHERE D.EDUCATION_CODE=T.EDUCATION AND D.STATUS=0) EDUCATIONNAME,
NATION,
POLITICAL,
REMARK,
TO_CHAR(T.CREATE_DATE,'YYYY-MM-DD HH24:MI:SS') createDate,
(SELECT D.REAL_NAME FROM UNIT_USER D WHERE D.ID= T.CREATE_USER_ID) createUserId,
TO_CHAR(T.UPDATE_DATE,'YYYY-MM-DD HH24:MI:SS') updateDate,
(SELECT D.REAL_NAME FROM UNIT_USER D WHERE D.ID= T.UPDATE_USER_ID) updateUserId
from UNIT_USER T
]]>
<where>
T.STATUS='1'
<if test="realName !=null and realName !=''">
and T.REAL_NAME like '%${realName}%'
</if>
<if test="nexusDpartment !=null">
AND T.ID IN (SELECT DISTINCT D.USER_ID FROM UNIT_USER_DEPT D WHERE D.DEPT_CODE IN (${nexusDpartment}))
</if>
<if test="deptCode !=null and deptCode !=''">
AND T.ID IN (SELECT DISTINCT D.USER_ID FROM UNIT_USER_DEPT D WHERE D.DEPT_CODE = #{deptCode})
</if>
</where>
<if test="sort != null and sort != ''">
order by ${sort}
<if test="direction != null and direction != ''">
${direction}
</if>
</if>
</select>
<![CDATA[
select
ID,
LOGIN_NAME AS loginName,
PASSWORD,
REAL_NAME AS realName,
POSITION,
(SELECT D.POSITION_NAME FROM UNIT_POSITION D WHERE D.POSITION_CODE=T.POSITION) POSITIONNAME,
USER_TYPE AS userType,
SEX,
PID,
TO_CHAR(T.BIRTHDAY,'YYYY-MM-DD') BIRTHDAY,
EMAIL,
CONTACT_TEL AS contactTel,
CONTACT_MOBILE AS contactMobile,
CONTACT_FAX AS contactFax,
CONTACT_ZIP AS contactZip,
CONTACT_ADDR AS contactAddr,
STATUS,
EDUCATION,
(SELECT D.EDUCATION_NAME FROM UNIT_EDUCATION D WHERE D.EDUCATION_CODE=T.EDUCATION AND D.STATUS=0) EDUCATIONNAME,
NATION,
POLITICAL,
REMARK,
TO_CHAR(T.CREATE_DATE,'YYYY-MM-DD HH24:MI:SS') createDate,
(SELECT D.REAL_NAME FROM UNIT_USER D WHERE D.ID= T.CREATE_USER_ID) createUserId,
TO_CHAR(T.UPDATE_DATE,'YYYY-MM-DD HH24:MI:SS') updateDate,
(SELECT D.REAL_NAME FROM UNIT_USER D WHERE D.ID= T.UPDATE_USER_ID) updateUserId
from UNIT_USER T
]]>
<where>
T.STATUS='1'
<if test="realName !=null and realName !=''">
and T.REAL_NAME like '%${realName}%'
</if>
<if test="nexusDpartment !=null">
AND T.ID IN (SELECT DISTINCT D.USER_ID FROM UNIT_USER_DEPT D WHERE D.DEPT_CODE IN (${nexusDpartment}))
</if>
<if test="deptCode !=null and deptCode !=''">
AND T.ID IN (SELECT DISTINCT D.USER_ID FROM UNIT_USER_DEPT D WHERE D.DEPT_CODE = #{deptCode})
</if>
</where>
<if test="sort != null and sort != ''">
order by ${sort}
<if test="direction != null and direction != ''">
${direction}
</if>
</if>
</select>
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询