更新商品信息失败

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

慕粉8429964

2019-11-10

调试了一下发现是updataProduct方法的问题更新不了,而且控制台没有报错图片描述
我到这里又去了dao层做ut 更新,发现也是在这个方法上出了问题,
图片描述
图片描述
,难道是mapper里 的sql语句有问题?但是也没有报该方面的错误,调试了好几次了.
贴一下我updataProduct方法

<update id="updateProduct" parameterType="com.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>

.

写回答

2回答

紫堇闻过

2022-09-08

刚刚我也碰到这个问题了,然后我解决了。数据库和代码都没问题,问题就出在,我们是要去update这个商品的信息,修改条件product_id 和 shop_id 的值 要和数据库已存在的信息要吻合。如果不一致就会导致更新失败。


0
0

翔仔

2019-11-10

接下来把控制台输出的update语句,配合控制台输出的值,拼接成真正的sql,在mysql客户端执行一下,就知道错误在哪里了。或者也可以看mybatis究竟返回的是什么异常,上面那个已经是封装过的异常了,需要看具体当时抛的那个异常是什么信息

0
0

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

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

5127 学习 · 8148 问题

查看课程