#
18516761980
2022-07-22 b743b62c7d57c84d16422841b0b51e85fe53a891
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.slcf.dao.UserDao">
 
<resultMap type="com.slcf.pojo.UserBean" id="UserBeanResult"></resultMap>
 
<!-- mapper不支持sql语句嵌套时,采用sql片段包含方式,解决xml标签问题 -->
<sql id="userConditionSql">    
        <if test="userId!=null and userId!='' and userId!=0 ">
        and user_id=#{userId}
        </if>
        <if test="userName!=null and userName!=''">
        and user_name like '%' + #{userName} + '%'
        </if>
        <if test="deptId!=null and deptId!=0">
         and u.dept_id=#{deptId}
        </if>        
</sql>
 
<select id="getUserListByCon" parameterType="map" resultMap="UserBeanResult">
SELECT top (#{epage}) u.*,d.dept_name from tb_user u  left join tb_dept d  on u.dept_id=d.dept_id
<where>
    user_id not in (select top ((#{spage}-1)*#{epage}) user_id from tb_user u  left join tb_dept d  on u.dept_id=d.dept_id 
    <where>
        1=1
        <include refid="userConditionSql"></include>
        )        
    </where>    
    <include refid="userConditionSql"></include>    
</where>
</select>
 
 
<select id="getContByCon" parameterType="map"    resultType="Integer">
select count(1) from tb_user u left join tb_dept d on u.dept_id=d.dept_id  
<where>
<![CDATA[
    1=1
]]>
    <include refid="userConditionSql"></include>
</where>
</select>
</mapper>