关于使用IDEA工具进行ssm框架整合时候突然报出的这个错误记录:
首先确保 mapper .xml中的 namespace 配置是你的接口全类名,而不是包名!
这里是使用mybatis的逆向工程生成的 mapper.xml文件(mapper接口具体的实现语句))
<?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" >
<!--namespace: 该名称空间写的是 mapper接口的类的全路径.-->
<mapper namespace="com.ssm.dao.UploadfileMapper" >
<!--这里定义的是返回结果.
id: 在这个xml文件的各种sql语句中如果返回一个实体类(Uploadfile),则用id - BaseResultMap替代-->
<resultMap id="BaseResultMap" type="com.ssm.dto.Uploadfile" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="path" property="path" jdbcType="VARCHAR" />
</resultMap>
<!--定义可复用的字段-->
<sql id="Base_Column_List" >
id, path
</sql>
<!--
id: 自定义的名称, 这个名称需要和mapper接口中的方法名称对应上.
resultMap: 返回值. 返回一个实体类. BaseResultMap就是上面我们定义的实体类的简写
parameterType:传入的参数类型.
from ..: 后面跟的是数据库表名称.
#{..} : 这样的写法类似一个占位符. 在{这里面就是接受外面调用方法传入的参数}
-->
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
from uploadfile
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from uploadfile
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.ssm.dto.Uploadfile" >
insert into uploadfile (id, path)
values (#{id,jdbcType=INTEGER}, #{path,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="com.ssm.dto.Uploadfile" >
insert into uploadfile
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
id,
</if>
<if test="path != null" >
path,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="id != null" >
#{id,jdbcType=INTEGER},
</if>
<if test="path != null" >
#{path,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.ssm.dto.Uploadfile" >
update uploadfile
<set >
<if test="path != null" >
path = #{path,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.ssm.dto.Uploadfile" >
update uploadfile
set path = #{path,jdbcType=VARCHAR}
where id = #{id,jdbcType=INTEGER}
</update>
</mapper>
确认dao接口中的方法,和xml中一一对应,返回类型,参数都正确.
eclipse工具和intellij idea这个工具在mybatis的使用上不同.
在eclipse中把mapper的xml文件放到src代码目录下是可以一起打包进classes的.
而在新版intellij idea中是不会一起打包,就会导致找不到xml报错。
也会报错: mybatis “org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)”.
第一种,由于idea默认是不打包src中的xml文件,所以在eclipse中你可以把xml放到src中没有问题,但是在idea中,你把mapper的xml文件放到resources资源中就可以正常访问!
当mapper.xml文件和mapper接口不在同一个包下的时候, 最好在配置文件中指定以下这个xml文件的位置:
<!-- 配置 Mybatis的工厂 -->
<bean class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 数据源 -->
<property name="dataSource" ref="dataSource" />
<!-- 配置Mybatis的核心 配置文件所在位置 -->
<property name="configLocation" value="classpath:SqlMapConfig.xml" />
<!-- 配置pojo别名,用于mapper.xml文件中的传参以及接收返回值. -->
<!--<property name="" value="com.ssm.dto.Uploadfile"></property>-->
<!--这是指明 mapper.xml文件的具体位置.-->
<property name="mapperLocations">
<list>
<!--在resource文件夹下.-->
<value>classpath*:UploadfileMapper.xml</value>
<!--如果是在src某个包里面,则需要这样写:
com/ssm/** :表示包名.
*Mapper.xml : 表示以 Mapper.xml结尾
-->
<value>classpath*:com/ssm/**/*Mapper.xml</value>
</list>
</property>
</bean>
还有其他一些错误, 这里只列举这一些, 以及这一种解决在IDEA中出现的这种问题的解决方法.
转载:http://blog.csdn.net/daoshud1/article/details/77646311