mapper文件报错:corresponds to your MySQL server version for the right syntax to use near ‘)VALUES( ‘

错误描述: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 ')VALUES( ‘audit02’, ‘audit流程’, ‘—’ at line 18

将报错信息里的语句复制到SQLyog里执行一遍发现,会爆出同样的错,在这里插入图片描述
mapper中的代码

<insert id="save" parameterType="ProcInstance" >
	INSERT INTO proc_task_instance(
            <if test="processId != null and processId != ''">process_id,</if>
            <if test="processKey != null and processKey != ''">process_key,</if>
            <if test="processName != null and processName != ''">process_name,</if>
            <if test="processTitle != null and processTitle != ''">process_title,</if>
            <if test="processDefinitionId != null and processDefinitionId != ''">process_definition_id,</if>
            <if test="processState != null and processState != ''">process_state,</if>
            <if test="userId != null and userId != 0">user_id,</if>
            <if test="username != null and username != ''">username,</if>
            <if test="procApplyTime != null and procApplyTime != ''">proc_apply_time,</if>
            proc_curr_node_user_id,proc_curr_node_user_name,proc_curr_task_name,
            <if test="procEndTime != null and procEndTime != ''">proc_end_time,</if>
            <if test="procData != null and procData != ''">proc_data,</if>
            <if test="departmentId != null and departmentId != 0">department_id,</if>
            <if test="departmentName != null and departmentName != ''">department_name,</if>
            <if test="timeOfEntry != null and timeOfEntry != ''">time_of_entry,</if>
            <if test="procBusstyle != null and procBusstyle != ''">proc_busstyle</if>
        )VALUES(
            <if test="processKey != null and processKey != ''">#{processKey},</if>
            <if test="processName != null and processName != ''">#{processName},</if>
            <if test="processTitle != null and processTitle != ''">#{processTitle},</if>
            <if test="processDefinitionId != null and processDefinitionId != ''">#{processDefinitionId},</if>
            <if test="processState != null and processState != ''">#{processState},</if>
            <if test="userId != null and userId != 0">#{userId},</if>
            <if test="username != null and username != ''">#{username},</if>
            <if test="procApplyTime != null and procApplyTime != ''">#{procApplyTime},</if>
            #{procCurrNodeUserId},#{procCurrNodeUserName},#{procCurrTaskName},
            <if test="procEndTime != null and procEndTime != ''">#{procEndTime},</if>
            <if test="procData != null and procData != ''">#{procData},</if>
            <if test="departmentId != null and departmentId != 0">#{departmentId},</if>
            <if test="departmentName != null and departmentName != ''">#{departmentName},</if>
            <if test="timeOfEntry != null and timeOfEntry != ''">#{timeOfEntry},</if>
            <if test="procBusstyle != null and procBusstyle != ''">#{procBusstyle}</if>
        )
    </insert>

原因是传参数时传入的是一个实例,但是实例的最后三个值:departmentName 、timeOfEntry 、procBusstyle 我并没有传值进去,判空之后直接不传了。但是这就导致SQL语句的最后多了一个departmentId 后面的逗号,所以会报错。

解决办法1:

将肯定会传入的值放到最后,这样会就不会多逗号
在这里插入图片描述

解决方法2:

   <insert id="save" parameterType="ProcInstance" >
        insert into proc_instance
        <trim prefix="(" suffix=")" suffixOverrides=",">
                    <if test="processId != null and processId != ''">process_id,</if>
                    <if test="processKey != null and processKey != ''">process_key,</if>
                    <if test="processName != null and processName != ''">process_name,</if>
                    <if test="processTitle != null and processTitle != ''">process_title,</if>
                    <if test="processDefinitionId != null and processDefinitionId != ''">process_definition_id,</if>
                    <if test="processState != null and processState != ''">process_state,</if>
                    <if test="userId != null and userId != 0">user_id,</if>
                    <if test="username != null and username != ''">username,</if>
                    <if test="procApplyTime != null and procApplyTime != ''">proc_apply_time,</if>
                    proc_curr_node_user_id,proc_curr_node_user_name,proc_curr_task_name,
                    <if test="procEndTime != null and procEndTime != ''">proc_end_time,</if>
                    <if test="procData != null and procData != ''">proc_data,</if>
                    <if test="departmentId != null and departmentId != 0">department_id,</if>
                    <if test="departmentName != null and departmentName != ''">department_name,</if>
                    <if test="timeOfEntry != null and timeOfEntry != ''">time_of_entry,</if>
                    <if test="procBusstyle != null and procBusstyle != ''">proc_busstyle</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="processId != null and processId != ''">#{processId},</if>
                    <if test="processKey != null and processKey != ''">#{processKey},</if>
                    <if test="processName != null and processName != ''">#{processName},</if>
                    <if test="processTitle != null and processTitle != ''">#{processTitle},</if>
                    <if test="processDefinitionId != null and processDefinitionId != ''">#{processDefinitionId},</if>
                    <if test="processState != null and processState != ''">#{processState},</if>
                    <if test="userId != null and userId != 0">#{userId},</if>
                    <if test="username != null and username != ''">#{username},</if>
                    <if test="procApplyTime != null and procApplyTime != ''">#{procApplyTime},</if>
                    #{procCurrNodeUserId},#{procCurrNodeUserName},#{procCurrTaskName},
                    <if test="procEndTime != null and procEndTime != ''">#{procEndTime},</if>
                    <if test="procData != null and procData != ''">#{procData},</if>
                    <if test="departmentId != null and departmentId != 0">#{departmentId},</if>
                    <if test="departmentName != null and departmentName != ''">#{departmentName},</if>
                    <if test="timeOfEntry != null and timeOfEntry != ''">#{timeOfEntry},</if>
                    <if test="procBusstyle != null and procBusstyle != ''">#{procBusstyle}</if>
        </trim>
    </insert>

用这个trim标签,会自动判定最后面多不多逗号,多的话会去掉。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值