mapper.xml文件:
<p><?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "<a target=_blank href="http://mybatis.org/dtd/mybatis-3-mapper.dtd">http://mybatis.org/dtd/mybatis-3-mapper.dtd</a>">
<!-- 这是mybatis的sql映射文件 -->
<mapper namespace="com.better517na.LogCollection.dao.WriteExceptionDetailDao"></p><p> <insert id="writeExceptionLogToDB" parameterType="java.util.List">
INSERT INTO
${tableName}(
LogID,
TimeTicks,
TrackID,
TimePoint,
ExceptionLevel,
ProcessID,
ThreadID,
ErrorCode,
AppName,
MachineName,
LocalIP,
UserName,
UserIP,
Url,
Browser,
Message,
Context,
StackTrace,
OriginalMessage)
values
<foreach collection="logExceptionList" item="item" index="index" separator=",">
(
#{item.logID},
#{item.timeTicks},
#{item.trackID},
#{item.timePoint},
#{item.exceptionLevel},
#{item.processID},
#{item.threadID},
#{item.errorCode},
#{item.appName},
#{item.machineName},
#{item.localIP},
#{item.userName},
#{item.userIP},
#{item.url},
#{item.browser},
#{item.message},
#{item.context},
#{item.stackTrace},
#{item.originalMessage})
</foreach>
</insert></p><p></mapper></p>
下面是java代码:
package com.better517na.LogCollection.dao.impl;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.session.SqlSession;
import com.better517na.LogCollection.dao.WriteExceptionDetailDao;
import com.better517na.LogCollection.model.MLogException;
import com.better517na.LogCollection.service.base.LoadSpring;
import com.better517na.LogCollection.util.SqlUtil;
import com.better517na.logcompontent.util.ExceptionLevel;
public class WriteExceptionDetailDaoImpl implements WriteExceptionDetailDao {
@Override
public boolean writeExceptionLogToDB(List<MLogException> mLogExceptions) {
SqlSession session = null;
int result = -1;
try
{
session = SqlUtil.getExceptionSqlSessionFactory().openSession();
Map<String, Object> map = new HashMap<String, Object>();
map.put("logExceptionList", mLogExceptions);
map.put("tableName", mLogExceptions.get(0).getTableName());
result = session.insert("writeExceptionLogToDB", map);
//上面的writeExceptionLogToDB如果和mapper里面insert后面的id不同,就会报下面的错误。
} catch (Exception e)
{
LoadSpring.getLogBusiness().writeExceptionLog(new com.better517na.logcompontent.model.MLogException(ExceptionLevel.Error, "123", e));
return false;
} finally
{
session.close();
}
return result > 0 ? true : false;
}
}
org.apache.ibatis.exceptions.PersistenceException:
### Error updating database. Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for writeDebugLogToDB
### Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for writeDebugLogToDB