OYCSDSB 2024-06-03 15:59 采纳率: 0%
浏览 2

idea的修改mysql语句问题

用代码块功能插入代码,请勿粘贴截图。 不用代码块回答率下降 50%
<update id="updateByUserId" parameterType="com.easypan.entity.po.UserInfo">
    UPDATE user_info
    <trim prefix="SET" suffixOverrides=",">
        <if test="bean.nickName != null">
             nick_name = #{bean.nickName},</if>
        <if test="bean.email != null">
             email = #{bean.email},</if>
        <if test="bean.qqOpenId != null">
             qq_open_id = #{bean.qqOpenId},</if>
        <if test="bean.qqAvatar != null">
             qq_avatar = #{bean.qqAvatar},</if>
        <if test="bean.password != null">
             password = #{bean.password},</if>
        <if test="bean.joinTime != null">
             join_time = #{bean.joinTime},</if>
        <if test="bean.lastLoginTime != null">
             last_login_time = #{bean.lastLoginTime},</if>
        <if test="bean.status != null">
             status = #{bean.status},</if>
        <if test="bean.userSpace != null">
             user_space = #{bean.userSpace},</if>
        <if test="bean.totalSpace != null">
             total_space = #{bean.totalSpace},</if>
      </trim>
      where user_id=#{userId}
</update>
运行结果及详细报错内容

Error updating database. Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE user_id='5975107971'' at line 3

The error may involve com.easypan.mappers.UserInfoMapper.updateByUserId-Inline

The error occurred while setting parameters

SQL: UPDATE user_info WHERE user_id=?

Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE user_id='5975107971'' at line 3

; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE user_id='5975107971'' at line 3

img

我的解答思路和尝试过的方法,不写自己思路的,回答率下降 60%

网上试过好几种方法都没用,不知道怎么解决了 问问大家 麻烦了

我想要达到的结果,如果你需要快速回答,请尝试 “付费悬赏”
  • 写回答

2条回答 默认 最新

  • 专家-赤兔[在线] 全栈领域优质创作者 2024-06-03 15:59
    关注

    引自免费微信小程序:皆我百晓生

    看起来你的问题是由于 MyBatis 的 XML 映射文件中的标签位置错误导致的。在 <update> 标签内,<trim> 标签应该包含所有要更新的字段,而 where 子句应该紧跟在 set 子句之后,并且不需要放在任何其他标签内。

    以下是修复后的 SQL 语句:

    <update id="updateByUserId" parameterType="com.easypan.entity.po.UserInfo">
        UPDATE user_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="bean.nickName != null">nick_name = #{bean.nickName}</if>
            <if test="bean.email != null">email = #{bean.email}</if>
            <if test="bean.qqOpenId != null">qq_open_id = #{bean.qqOpenId}</if>
            <if test="bean.qqAvatar != null">qq_avatar = #{bean.qqAvatar}</if>
            <if test="bean.password != null">password = #{bean.password}</if>
            <if test="bean.joinTime != null">join_time = #{bean.joinTime}</if>
            <if test="bean.lastLoginTime != null">last_login_time = #{bean.lastLoginTime}</if>
            <if test="bean.status != null">status = #{bean.status}</if>
            <if test="bean.userSpace != null">user_space = #{bean.userSpace}</if>
            <if test="bean.totalSpace != null">total_space = #{bean.totalSpace}</if>
        </trim>
        WHERE user_id = #{userId}
    </update>
    

    确保你在传递给这个方法的 UserInfo 对象中的属性值是正确的,并且 userId 参数也是有效的整数类型。这样应该可以解决 SQL 语法错误的问题。运行这段修正后的代码,看是否还有错误。如果仍然存在问题,请提供更多的上下文信息或者具体的异常堆栈跟踪,以便更深入地分析问题。

    评论 编辑记录

报告相同问题?

问题事件

  • 创建了问题 6月3日

悬赏问题

  • ¥15 软件供应链安全是跟可靠性有关还是跟安全性有关?
  • ¥15 电脑蓝屏logfilessrtsrttrail问题
  • ¥20 关于wordpress建站遇到的问题!(语言-php)(相关搜索:云服务器)
  • ¥15 【求职】怎么找到一个周围人素质都很高不会欺负他人,并且未来月薪能够达到一万以上(技术岗)的工作?希望可以收到写有具体,可靠,已经实践过了的路径的回答?
  • ¥15 Java+vue部署版本反编译
  • ¥100 对反编译和ai熟悉的开发者。
  • ¥15 带序列特征的多输出预测模型
  • ¥15 Python 如何安装 distutils模块
  • ¥15 关于#网络#的问题:网络是从楼上引一根网线下来,接了2台傻瓜交换机,也更换了ip还是不行
  • ¥15 资源泄露软件闪退怎么解决?