ibatis批量添加 参数实体类列表
异常信息:
org.springframework.jdbc.UncategorizedSQLException: SqlMapClient operation; uncategorized SQLException for SQL []; SQL state [null]; error code [0];
--- The error occurred in com/wandafilm/api/model/conf/demo/DEMO_USER_SqlMap.xml.
--- The error occurred while preparing the mapped statement for execution.
--- Check the DEMO_USER.insertNumber.
--- Check the parameter map.
--- Cause: com.ibatis.common.beans.ProbeException: Error getting ordinal list from JavaBean. Cause java.lang.StringIndexOutOfBoundsException: String index out of range: -1; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred in com/wandafilm/api/model/conf/demo/DEMO_USER_SqlMap.xml.
--- The error occurred while preparing the mapped statement for execution.
--- Check the DEMO_USER.insertNumber.
--- Check the parameter map.
--- Cause: com.ibatis.common.beans.ProbeException: Error getting ordinal list from JavaBean. Cause java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:83)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
at com.shtao.ext.springframework.orm.ibatis.ExtSqlMapClientTemplate.execute(ExtSqlMapClientTemplate.java:170)
at com.shtao.ext.springframework.orm.ibatis.ExtSqlMapClientTemplate.insert(ExtSqlMapClientTemplate.java:357)
sqlmap.xml 错误案例:
<insert id="insertNumber" parameterClass="java.util.List">
<![CDATA[
INSERT ALL
]]>
<iterate conjunction=" " property="mapList">
INTO wandafilm.send_active_user_phone_number
(ACTIVE_ID,USER_PHONE,USER_ID)
VALUES
(#mapList[].userNme:VARCHAR#,#mapList[].nickName:VARCHAR#,#mapList[].mobileNo:VARCHAR#)
</iterate>
<![CDATA[
SELECT * FROM dual
]]>
</insert>
sqlmap.xml 正确案例:
<insert id="insertNumber" parameterClass="java.util.List">
<![CDATA[
INSERT ALL
]]>
<iterate conjunction=" ">
INTO wandafilm.send_active_user_phone_number
(ACTIVE_ID,USER_PHONE,USER_ID)
VALUES
(#[].userNme:VARCHAR#,#[].nickName:VARCHAR#,#[].mobileNo:VARCHAR#)
</iterate>
<![CDATA[
SELECT * FROM dual
]]>
</insert>
sqlmap.xml 正确模板:
<insert id="标示" parameterClass="参数类型">
<![CDATA[
INSERT ALL
]]>
<iterate conjunction="空格">
INTO 表名
(字段名)
VALUES
(#[].实体类对应的属性名:数据库字段类型#)
</iterate>
<![CDATA[
SELECT * FROM dual
]]>
</insert>
daoimpl.java部分代码:
List<User> list = null;
省略部分代码
getSqlMapClientTemplate().insert("DEMO_USER.insertNumber", list);
总结:
org.springframework.jdbc.UncategorizedSQLException: SqlMapClient operation; uncategorized SQLException for SQL []; SQL state [null]; error code [0]
sql配置文件错误,仔细检查自己的配置文件
批量添加只要不报异常就可以视为成功,他返回值是一个null,或许自己初次解决的原因吧