使用mybatis-plus整合springboot时,因为需要连表操作但是mybatisplus不支持,所以自己写了xml来映射
<update id="update" parameterType="cn.azh.entity.Product">
update t_product
<set>
<if test="name!=null and name!=''">
name=#{name},
</if>
<if test="price!=null">
price=#{price},
</if>
<if test="stock!=null">
stock=#{stock},
</if>
<if test="type!=null and type.id!=null">
typeId=#{type.id},
</if>
<if test="description!=null and description!=''">
description=#{description},
</if>
<if test="productIntroImgs!=null and productIntroImgs!=''">
productIntroImgs=#{productIntroImgs},
</if>
<if test="productParaImgs!=null and productParaImgs!=''">
productParaImgs=#{productParaImgs},
</if>
</set>
where id=#{id}
</update>
但是测试发现报错product实体中的et属性没有getter方法,哥们直接愣住了,因为我的product中根本没有属性,甚至连带et两个字母的属性都没有,在仔细检查sql语句和实体类后确定没有问题但还是报错后上网寻求结果,在看了几个帖子后发现好像是因为BaseMapper中本身就有方法名为update的方法,在xml中可能他是反射到了原有的方法中导致报错
不知道如何解决不如从根本上解决问题,那就把从controller到xml从头到尾修改方法名改为updateProduct,改完运行,成功,问题解决
看帖子时发现另一个大佬遇到了同样的问题,他是通过重写方法解决的 加了个注解 下面带上他的原帖
使用注解解决