mybatics条件查询和条件更新举例

分页条件查询  page=(page-1)*limt   limit=limit

 <select id="FindAll" resultType="com.exerce.enty.Car" parameterType="com.exerce.enty.Carpage">
        select * from car
        <where>
            1=1
            <if test="carid != null and carid !=''">
                and carid = #{carid,jdbcType=INTEGER}
            </if>
            <if test="brand != null and brand !='' ">
                and brand=#{brand,jdbcType=VARCHAR}
            </if>
            <if test="type != null and type !=''">
                and type = #{type,jdbcType=VARCHAR}
            </if>
            <if test="color != null and color !=''">
                and color = #{color,jdbcType=VARCHAR}
            </if>
            <if test="retail != null and retail !=''">
                and retail = #{retail,jdbcType=VARCHAR}
            </if>
            <if test="buyprice != null and buyprice !=''">
                and buyprice = #{buyprice,jdbcType=DOUBLE}
            </if>
            <if test="saleprice != null and saleprice !=''">
                and  saleprice = #{saleprice,jdbcType=DOUBLE}
            </if>
            <if test="number != null and number !=''">
                and number = #{number,jdbcType=INTEGER}
            </if>
            <if test="discribe !=null and discribe !=''">
                and  discribe = #{discribe,jdbcType=VARCHAR}
            </if>

        </where>
        limit #{page,jdbcType=INTEGER},#{limit,jdbcType=INTEGER}
    </select>

  条件更新

<update id="update" parameterType="com.exerce.enty.Userinfo">
        update user
       <set>
           <if test="name != null">
               name = #{name,jdbcType=VARCHAR},
           </if>
           <if test="user != null">
               user = #{user,jdbcType=VARCHAR},
           </if>
           <if test="password != null">
               password = #{password,jdbcType=VARCHAR},
           </if>
           <if test="idCard != null">
               idCard = #{idCard,jdbcType=INTEGER},
           </if>
           <if test="gender != null">
               gender = #{gender,jdbcType=VARCHAR},
           </if>
           <if test="phone != null">
               phone = #{phone,jdbcType=VARCHAR},
           </if>
           <if test="email != null">
               email = #{email,jdbcType=VARCHAR},
           </if>
           <if test="address !=null">
               address = #{address,jdbcType=VARCHAR},
           </if>
           <if test="position != null">
               position = #{position,jdbcType=VARCHAR},
           </if>

       </set>
        where  id = #{id,jdbcType=INTEGER}
    </update>

  

posted @ 2019-09-28 16:19  ꧁༺红尘^_^有梦༻꧂  阅读(196)  评论(0)    收藏  举报