mybatis怎么实现可以分页也可以不分页的sql啊

如何将分页放到if标签里呀,坐到可以分页查询也可以部分也查询。下面是我的代码


    <select id="findGdMessage" resultType="Map">
        select *from gdmessage
        <where>
            <if test="gdzt!=null and gdzt !=''">
                gdzt= #{gdzt}
            if>
            <if test="bdstart!=null and bdstart !=''">
                and bdsj >= #{bdstart}
            if>
            <if test="bdend!=null and bdend !=''">
                and bdsj <= #{bdend}
            if>
            <if test="pgstart!=null and pgstart !=''">
                and pgsj >= #{pgstart}
            if>
            <if test="pgend!=null and pgend !=''">
                and pgsj <= #{pgend}
            if>
            <if test="jdstart!=null and jdstart !=''">
                and jdsj >= #{jdstart}
            if>
            <if test="jdend!=null and jdend !=''">
                and jdsj <= #{jdend}
            if>
            <if test="wgstart!=null and wgstart !=''">
                and sjwgsj >= #{wgstart}
            if>
            <if test="wgend!=null and wgend !=''">
                and sjwgsj <= #{wgend}
            if>
            <if test="khfw!=null and khfw !=''">
                and khfw = #{khfw}
            if>
            <if test="khmc!=null and khmc !=''">
                and khmc = #{khmc}
            if>
            <if test="fwfs!=null and fwfs !=''">
                and fwfs = #{fwfs}
            if>
            <if test="fwlx!=null and fwlx !=''">
                and fwlx = #{fwlx}
            if>
            <if test="sf!=null and sf !=''">
                and sf like concat('%',#{sf},'%')
            if>
            <if test="gd_id!=null and gd_id !=''">
                and gd_id = #{gd_id}
            if>

        where>
        <where>
            <if test="begin !=null and begin !=''">
                limit #{begin},#{pageSize}
            if>
        where>
    select>

可以使用pagehelper去实现,或者这个改一下看看,后边的放上去

img