Mybatis的WHERE和IF动态

mapper.xml:

    <!--查询套餐产品 -->
    <select id="queryComboProducts" resultType="com.runmin.bajie.entity.ProductCombo">
        select id,name,price,specification,origin_price,image from product_combo  
          <where>
            <if test="type!=null">
                and type = ${type}
            </if>
        </where>
    </select>

dao:

    /**
     * 查询组合套餐
     * 
     * @return
     */
    List<ProductCombo> queryComboProducts(ProductCombo type);

也就是说如果直接传Integer type是不行的,必须放在对象里面。

posted @ 2017-12-05 16:50  虚极静笃  Views(812)  Comments(0)    收藏  举报