2 steve yanrun steve_yanrun 于 2016.09.19 23:07 提问

mybatis无法删除数据,log4j显示如下异常

当使用mybatis删除数据时,log4j出现如下图异常:
图片说明
请问可能的原因是什么?
相关代码:

 <?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="Message"> 
  <resultMap type="model.Message" id="MessageResult">
    <id column="ID" jdbcType="VARCHAR" property="id"/> 
    <result column="COMMAND" jdbcType="VARCHAR" property="command"/>
    <result column="DESCRIPTION" jdbcType="VARCHAR" property="description"/>
    <result column="CONTENT" jdbcType="VARCHAR" property="content"/>
  </resultMap>

  <select id="Message.queryAll" resultMap="MessageResult">
    SELECT ID,COMMAND,DESCRIPTION,CONTENT FROM message WHERE 1=1
    <if test="command != null and !&quot;&quot;.equals(command.trim())">and COMMAND LIKE '%' #{command} '%'</if>
    <if test="description != null and !&quot;&quot;.equals(description.trim())">and DESCRIPTION LIKE '%' #{description} '%'</if>
  </select>

  <delete id="deleteOne" parameterType="int">
    DELETE FROM message WHERE ID=#{_parameter}
  </delete>
</mapper>

public void deleteOne(int id){
        DBAccess dbAccess = new DBAccess();
        SqlSession sqlSession = null;
        try{
            sqlSession = dbAccess.getSqlSession();//实例化并打开数据库会话
            sqlSession.delete("Message.deleteOne",id);//message.xml配置文件中对应ID号的SQL语句
        }catch(IOException e){
            e.printStackTrace();
        }finally{
            if(sqlSession!=null){
                sqlSession.close();
            }
        }
    }

    public class MaintainService {
    public void deleteOne(String id){
        if(id != null && !"".equals(id.trim())){
            MessageDAO messageDao = new MessageDAO();
            messageDao.deleteOne(Integer.valueOf(id));
        }

    }

}

1个回答

a719195733
a719195733   2016.09.20 08:46

xml中把类型 int换java.lang. Integer试试

steve_yanrun
steve_yanrun 试过了,没有用
大约一年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片