Paging query



    <!-- Pagination-->
    <sql id="paging">
        <if test="isPage != null and isPage != '' ">
        <!-- start start page length to display a total of several records (starting from length=start+1, take out length records)-->
            limit #{start}, #{length}
        </if>        
    </sql>
    
    <!-- In this way, you can avoid the sql statement error if the where condition is empty-->
    <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>    
    
    <!--There are two types of parameter parameterType passed in the sql statement (basic data type (int, string, long, Date), complex data type (class and Map))
            Get the value of the parameter Basic data type: #{parameter} Get the value in the parameter
                        Complex data types: #{attribute name}, #{key} in map
     -->
    <!-- The return parameters of the sql statement are divided into 2, resultMap (result set) and resultType (int, string, long, class)
        
        Note: When MyBatis performs query mapping, in fact, each attribute queried is placed in a corresponding Map
                where the key is the property name and the value is its corresponding value
        
     -->
    
    <!-- Paging query -->
    <select id="selectPerson" parameterType="Person" resultType="Person">
        select * from person
        <include refid="pageWhere"></include>
        <include refid="paging"></include>
    </select>
        
        
    <!-- Query the total number of qualified personnel-->    
    <select id="selectPersonCount" parameterType="Person">
        selecte count(personcname) from person
        <include refid="pageWhere"></include>
        <!-- Determine the total number under the page of the number of all personnel within the range of the input conditions by adding a conditional statement-->
    </select>


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325565284&siteId=291194637