账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    mybatis批量insert出错
    49
    0
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE mapper
            PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
            "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
    <mapper namespace="com.qtay.gls.dao.TeacherLabelDao">
        <sql id="key">
            <trim suffixOverrides=",">
                <if test="item.id!=null">
                    id,
                </if>
                <if test="item.teacherId != null">
                    teacher_id,
                </if>
                <if test="item.name!=null">
                    name,
                </if>
            </trim>
        </sql>
        <sql id="value">
            <trim suffixOverrides=",">
                <if test="item.id!=null">
                    #{item.id},
                </if>
                <if test="item.teacherId!=null">
                    #{item.teacherId},
                </if>
                <if test="item.name!=null">
                    #{item.name},
                </if>
            </trim>
        </sql>
        <insert id="saveTeacherLabels" keyProperty="id" parameterType="java.util.List">
            <foreach collection="list" item="item" index="index" separator=";">
                insert into teacher_labels(<include refid="key"/>) values(<include refid="value"/>)
            </foreach>
        </insert>
    </mapper>
    ### Error updating database.  Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 'insert into teacher_labels( 
             id,
                
                
                ' at line 19
    ### The error may involve com.qtay.gls.dao.TeacherLabelDao.saveTeacherLabels-Inline
    ### The error occurred while setting parameters
    ### SQL: insert into teacher_labels(           id,                                           teacher_id,                                           name       ) values(           ?,                                           ?,                                           ?       )          ;              insert into teacher_labels(           id,                                           teacher_id,                                           name       ) values(           ?,                                           ?,                                           ?       )
    ### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 'insert into teacher_labels( 
             id,
                
                
                ' at line 19
    ; bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 'insert into teacher_labels( 
             id,
                
                
                ' at line 19, path=/teacher/save}] as "application/json;charset=utf-8" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@39023dbf]
    2017-11-20 14:22:55.547 DEBUG [http-nio-9090-exec-4] o.s.web.servlet.DispatcherServlet - Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling
    2017-11-20 14:22:55.547 DEBUG [http-nio-9090-exec-4] o.s.web.servlet.DispatcherServlet - Successfully completed request

    只单个添加一条数据是正确的,当添加2个及以上就报上面的错,请问如何解决?

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部