分页查询

来源:互联网 发布:windows rt连接口 编辑:程序博客网 时间:2024/06/06 05:14


    <!-- 分页 -->    <sql id="paging">        <if test="isPage != null and isPage != '' ">        <!-- start 开始页  length 总共显示几条记录(    从 length=start+1开始, 取出length条记录     )-->            limit #{start}, #{length}        </if>            </sql>        <!-- 通过这种方式可以避免了where 条件中如果为空的话,sql语句出错 -->    <sql id="pageWhere">        <where>            <if test="personid != null and personid != '' ">                AND personid = #{personid}            </if>            <if test="personname != null and personname != '' ">                AND personname like concat( concat( '%', #{personname} ), '%' )            </if>            <if test="personcname != null and personcname != '' ">                AND personcname like concat ( concat('%', #{personcname} ), '%' )            </if>            <if test="persontelephone != null and persontelephone != '' ">                AND persontelephone like concat('%', #{persontelephone}, '%')            </if>                </where>    </sql>            <!--在sql语句中 传入的参数parameterType 类型有两种(基本数据类型(int,string,long,Date),复杂数据类型 (类和Map) )            获取参数的值   基本数据类型:     #{参数}     获取参数中的值                        复杂数据类型: #{属性名},  map中则是#{key}     -->    <!-- 在sql语句的返回参数分为2中 ,resultMap (结果集) 和resultType(int, string, long, class)                注意点: 在MyBatis 进行查询映射时,其实查询出来的每个属性都是放在一个对应的Map里面的                其中键是属性名, 值则是其对应的值             -->        <!-- 分页查询 -->    <select id="selectPerson" parameterType="Person" resultType="Person">        select * from person        <include refid="pageWhere"></include>        <include refid="paging"></include>    </select>                    <!-- 查询符合条件人员总数量  -->        <select id="selectPersonCount" parameterType="Person">        selecte count(personcname) from person         <include refid="pageWhere"></include>        <!-- 通过加条件语句判断出在输入条件范围内所有的人员数量  分页下面的总数 -->    </select>


原创粉丝点击