mybatis一個(gè)怪異的問(wèn)題:
Invalid bound statement (not found): cn.com.dao.UserDao.selectByUser at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:178) at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:38) at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:49) at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:42) at $Proxy22.selectByUser(Unknown Source)
Caused by: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for cn.com.dao.UserDao.selectByUser
at org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:775) at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:615) at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:608) at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:176)
... 34 more
1. 我檢查了半天也沒(méi)看出什么問(wèn)題來(lái),后來(lái)把mapper的xml select 語(yǔ)句重寫(xiě)禁舷。問(wèn)題竟然好了。出了這種問(wèn)題:
<mapper namespace="cn.com.dao.UserDao">
mapper的namespace寫(xiě)的不對(duì)!
<insert id="insert" parameterType="com.test.pojo.User" >
parameterType沒(méi)有寫(xiě)對(duì)裆馒。
2. UserDao的方法在UserDao.xml中沒(méi)有,然后執(zhí)行UserDao的方法會(huì)報(bào)此錯(cuò)
3. 刪除配置文件里中文的注釋,保存.
4. Mybatis的自動(dòng)掃描 錯(cuò)誤
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!-- 自動(dòng)掃描mapping.xml文件 -->
<property name="mapperLocations" value="classpath:com/test/mapping/*.xml"></property>
</bean>
value="classpath:com/test/mapping/*.xml"沒(méi)有寫(xiě)對(duì)
<!-- DAO接口所在包名丐怯,Spring會(huì)自動(dòng)查找其下的類(lèi) -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.test.dao" />
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
</bean>
<property name="basePackage" value="com.test.dao" /> 沒(méi)有寫(xiě)對(duì)