java.lang.IllegalArgumentException: Mapped Statements collection does not....
2015-09-19 17:11
519 查看
<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>
相关文章推荐
- android4.x 增加一个新按键&&修改android默认语言
- windos8.1 GNUstep环境搭建,objective-c
- scala apply方法 笔记
- 如何避免在Block里用self造成循环引用
- Android禁止横屏竖屏切换
- swift 类继承
- iOS开发脚踏实地学习day10-PickerView
- Android Studio的Gradle工程导入第三方源代码类库
- android greendao的外部封装不太友好。
- 小程序-----Java代码产生6个随机数,其中第一个不能为0
- Objective-C——类、方法、属性、成员变量
- swift 静态方法
- Android性能分析工具介绍
- 转:【Objective-C】第一个OC的类
- Xcode6以后mac中iOS模拟器安装路径以及程序沙箱路径
- 【android基础】——Android布局相关
- iOS9.0适配
- Objective-C中的self和super
- Android中Activity之间切换动画的修改
- android socket通信