mybatis一個怪異的問題:
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. 我檢查了半天也沒看出什么問題來,后來把mapper的xml select 語句重寫。問題竟然好了。出了這種問題:
<mapper namespace="cn.com.dao.UserDao">
mapper的namespace寫的不對!
<insert id="insert" parameterType="com.test.pojo.User" >
parameterType沒有寫對。
2. UserDao的方法在UserDao.xml中沒有,然后執行UserDao的方法會報此錯
3. 刪除配置文件里中文的注釋,保存.
4. Mybatis的自動掃描 錯誤
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!-- 自動掃描mapping.xml文件 -->
<property name="mapperLocations" value="classpath:com/test/mapping/*.xml"></property>
</bean>
value="classpath:com/test/mapping/*.xml"沒有寫對
<!-- DAO接口所在包名,Spring會自動查找其下的類 -->
<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" /> 沒有寫對