java.lang.IllegalArgumentException: Mapped Statements collection does not....

<span style="font-size:18px;">出现这个问题,是因为你的namespace命名问题:下面直接用代码来说吧!</span>
<pre name="code" class="html"><span style="font-size:18px;"><?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"></span>

<span style="font-size:24px;color:#ff0000;"><!-- 这里namespace的命名必须和对应的UserMapper.java文件的路径一样否则会报错 --></span>
<span style="font-size:18px;"><mapper namespace="MybatisTest2.dao.UserMapper">

    <cache eviction="FIFO" flushInterval="60000" size="512" readOnly="true">
    </cache>
	<!-- 根据id查询得到一个user对象 -->
	<select id="findById" parameterType="int" resultType="User">
		select * from user where id = #{id}
	</select>
	<!-- 添加user对象 -->
	<insert id="save" parameterType="User">
		insert into user(name,age) values(#{name},#{age})
	</insert>
	<!-- 删除user对象 -->
	<delete id="delete" parameterType="int">
		delete from user where id = #{id}
	</delete>
	<!--更新对象 -->
	<update id="update" parameterType="User">
		update user set name = #{name},age = #{age} where id = #{id}
	</update>
	<!-- 查询对象 -->
	<select id="findAll" resultType="User">
		select * from user
	</select>
	
</mapper></span>


 另外很多朋友对spring整合mybatis的配置文件整不明白,或者配置总是出错下面我给出一个简洁的配置代码,对各个参数有相应的注释,希望帮的到你: 
 
<pre name="code" class="html"><span style="font-size:18px;"><?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:tx="http://www.springframework.org/schema/tx" 
 xmlns:aop="http://www.springframework.org/schema/aop" 
xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd 
http://www.springframework.org/schema/tx 
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/aop 
http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
">

  <description>Spring公共配置</description>
  
  <!--1.配置数据源,这里用的是c3p0 -->
  <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
       <property name="driverClass" value="com.mysql.jdbc.Driver" />
       <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/test" />
       <property name="user" value="root" />
       <property name="password" value="root" />
  </bean>
     <!--2.mybatis的SqlsessionFactory: SqlsessionFactoryBean
           dataSource:引用数据源
           typeAliasesPackage:指定实体类的包名,自动将实体的简单类名映射成别名
           mapperLocations:扫描sql映射文件    
             -->
  <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
     <property name="dataSource" ref="dataSource"/>
     <property name="typeAliasesPackage" value="MybatisTest2.model"/>
     <property name="mapperLocations" value="classpath:MybatisTest2/mapping/*.xml" />
  </bean>
  <!-- 3.mybatis自动扫描加载sql的映射文件/接口(这里我扫描的是接口,映射文件在上面已经做了):MapperScannerConfigurer
     basePackage:指定sql映射文件/接口所在的包,能动自动扫描,对用了@Autowired标签的自动注入
     sqlSessionFactory:引用之前定义好的sqlsessionFactory
    -->
  <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
     <property name="basePackage" value="MybatisTest2.dao"/>
     <property name="sqlSessionFactory" ref="sqlSessionFactory"/>
  </bean>
  	<!--4. 配置事务管理器 :DataSourceTransactionManager-->
	<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource" />
	</bean>
	<!-- 5. 注解方式配置事务 -->
	<tx:annotation-driven transaction-manager="transactionManager" /> 
</beans></span>



                
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值