关于更新商品信息sql的疑问

来源:8-7 商品编辑之后端开发上

荒小北158

2021-02-08

<update id="updateProduct" parameterType="com.my.o2o.entity.Product"
            keyProperty="product_id" useGeneratedKeys="true">
        UPDATE tb_product
        <set>
            <if test="productName != null">product_name=#{productName},</if>
            <if test="productDesc != null">product_desc=#{productDesc},</if>
            <if test="imgAddr != null">img_addr=#{imgAddr},</if>
            <if test="normalPrice != null">normal_price=#{normalPrice},</if>
            <if test="promotionPrice != null">promotion_price=#{promotionPrice},</if>
            <if test="priority != null">priority=#{priority},</if>
            <if test="lastEditTime != null">last_edit_time=#{lastEditTime},</if>
            <if test="enableStatus != null">enable_status=#{enableStatus},</if>
            <if test="productCategory != null
				 and productCategory.productCategoryId != null">
                product_category_id=#{productCategory.productCategoryId}
            </if>
        </set>
        WHERE product_id = #{productId}
        AND shop_id=#{shop.shopId}
    </update>

对于WHERE的条件,shop_id = #{shop.shopId} ,老师在课里说是为了避免操作到其他店铺下的商品,可是在前端,当前店铺的商品不就只能显示出属于当前shopId下面的商品么? 怎么会修改到其他店铺底下的商品呢?我还是觉得这里的shop_id = #{shop.shopId} 有点多余

写回答

2回答

翔仔

2021-02-08

同学好,如果用户只是通过界面去修改,那肯定是没问题的,但是如果绕开界面,直接发请求呢,这样如果不加店铺的话,就是非店铺的owner也能修改商品信息了。而如果加上shopId,后面就可以从Session里面取shopId来做判断,看看具不具备对这个店铺进行操作

0
3
荒小北158
非常感谢!
2021-02-10
共3条回复

荒小北158

提问者

2021-02-09

1111

0
0

Java双版本(SSM到SpringBoot)校园商铺全栈开发

SSM商铺V1.0,解决毕设痛点;SpringBoot商铺V2.0,满足工作刚需

5127 学习 · 8148 问题

查看课程