mybatis操作数据库是如果mapper文件中的id和java代码中的参数名字不同是报的错

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

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值