ibatis 批量插入!!!!?????

获得map

        String insertCompId = "a,b,c";
        String ttId = "a,b,c";
        String ticketCode = "a";

    String[] insertCompIdaa = insertCompId.split(",");
        String[] ttidaa = ttId.split(",");

        try{
            sqlMapClient.startTransaction();
            Map map = new HashMap();

            List<TestInsert> tilist = new ArrayList<TestInsert>();

            for (int i = 0; i < ttidaa.length; i++) {
                for (int j = 0; j < insertCompIdaa.length; j++) {
                    TestInsert ti =new TestInsert();
                    ti.setTicketTypeId(ttidaa[i]);
                    ti.setTicketCodeType(ticketCode);
                    ti.setComponentId(insertCompIdaa[j]);
                    tilist.add(ti);
                }
            }
            map.put("tilist", tilist);
            .........

将上面得到的map,传入

 <insert id="testInsertTicketCodeRelation" parameterClass="java.util.Map" >
        insert all
        <iterate property="tilist" conjunction=",">
        into TICKET_TYPE_TICKET_CODE
            (
            TICKET_TYPE_TICKET_CODE_ID,
            TICKET_TYPE_ID,
            TICKET_CODE_TYPE,
            COMPONENT_ID
            )
            values
            (
            TICKET_TYPE_AND_CODE_ID_SEQ.nextVal,
            #tilist[].ticketTypeId#,
            #tilist[].ticketCodeType#,
            #tilist[].componentId#
            )
        </iterate>
        select * from dual
    </insert>

出错(当ttId和insertCompId为单字符,例如ttId=“a”insertCompId=“b”,这样的,是不会报错,只有为上面的有逗号的字符串时,才会出现这个错误)

 ERROR [http-bio-8080-exec-4] LoggerFactory.invoke(38) | class com.hkt.engineering.oneoss.ticketing.dao.tickettype.impl.TicketTypeTicketCodeDAO.testInsertTicketCodeRelation() invoke error
ERROR [http-bio-8080-exec-4] LoggerFactory.invoke(39) | error info: 
com.ibatis.common.jdbc.exception.NestedSQLException:   
--- The error occurred while applying a parameter map.  
--- Check the EFT_TICKET_TYPE_TICKET_CODE.testInsertTicketCodeRelation-InlineParameterMap.  
--- Check the statement (update failed).  
--- Cause: java.sql.SQLException: ORA-00928: 缺失 SELECT 关键字

请问,问题出在哪里了?

1个回答

应该是这样的吧

 <insert id="testInsertTicketCodeRelation" parameterClass="java.util.Map" >
        insert into TICKET_TYPE_TICKET_CODE
            (
            TICKET_TYPE_TICKET_CODE_ID,
            TICKET_TYPE_ID,
            TICKET_CODE_TYPE,
            COMPONENT_ID
            )
            values
        <iterate property="tilist" conjunction=",">
            (
            TICKET_TYPE_AND_CODE_ID_SEQ.nextVal,
            #tilist[].ticketTypeId#,
            #tilist[].ticketCodeType#,
            #tilist[].componentId#
            )
        </iterate>

    </insert>
qq_24534807
qq_24534807 不行,还是原本的错误
大约 3 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐