请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

更新商品信息失败

调试了一下发现是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>

.

正在回答 回答被采纳积分+3

2回答

紫堇闻过 2022-09-08 17:54:54

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


0 回复 有任何疑惑可以回复我~
翔仔 2019-11-10 20:04:24

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

0 回复 有任何疑惑可以回复我~
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号