mysql自动实现dao类, 报错Exception in thread "main" org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):
Exception in thread "main" org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):
先贴配置:
<!-- myBatis 配置 --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="configLocation" value="classpath:mybatis-config.xml"/> <property name="dataSource" ref="dataSource"/> <property name="mapperLocations" value="classpath*:com/haoyin/logic/dao/*.xml"/> </bean> <!-- 配置sqlSessionTemplate --> <bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate"> <constructor-arg index="0" ref="sqlSessionFactory" /> </bean> <!-- mybatis自动实现dao--> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.haoyin.logic.dao"/> </bean>
网上说上面最后错误,我这里是指定对的, sqlSessionFactory里的mapperLocations也是对的.
Exception in thread "main" org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.haoyin.logic.dao.UserLoginDao.getTokenByUid at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:196) at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:44) at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:59) at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52) at com.sun.proxy.$Proxy11.getTokenByUid(Unknown Source) at com.haoyin.logic.service.UserLoginServiceImpl.authenticate(UserLoginServiceImpl.java:20) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96) at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) at com.sun.proxy.$Proxy15.authenticate(Unknown Source) at com.haoyin.logic.service.UserLoginServiceTest.main(UserLoginServiceTest.java:19)
import com.haoyin.logic.bean.UserLogin; import org.apache.ibatis.annotations.Param; /** * Created by dong on 2016/1/23. */ public interface UserLoginDao { String getTokenByUid(@Param("uid")String uid); String update(@Param("userLogin")UserLogin userLogin); }
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.haoyin.logic.dao.UserLoginDao"> <select id="getTokenByUid" resultType="string"> SELECT token FROM v1_userLogin WHERE uid = (#{uid}) </select> <update id="update"> UPDATE v1_userLogin <set> <if test="token != null">token = (#{token}),</if> <if test="expire != null">expire = (#(expire)),</if> <if test="lastAccessTimestamp != null">lastAccessTimestamp = (#(lastAccessTimestamp)) </if> </set> WHERE uid = (#{uid}) </update> </mapper>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
引用来自“JuSole”的评论
没找到xml 文件,看看路径对不?
路径肯定是对的。我在想会不会是我分了模块的原因呢
回复
1、如果用的mvn,那就检查xml复制过去了没。2、这么配置: <property name="mapperLocations" value="classpath*:com/huaxin/**/*Mapper.xml"></property>
回复
还是一样.似乎没有找到mapper文件
回复
你确定这两个没问题呢,找不到mapper文件都是这两个造成的。
没找到xml 文件,看看路径对不?
<property
name="mapperLocations"
value="classpath*:com/haoyin/logic/dao/*.xml"/> 改为在
mybatis-config.xml 中清华手动的试试。
我流下来感动的泪水. 太感谢了. 真是这个原因. 定位问题和搜索的能力仍需加强, 感谢
你遇到的问题都是我走过的路。呵呵,慢慢来就行了。
回复
按照你的方法,我的问题也解决了,太感谢
引用来自“JuSole”的评论
没找到xml 文件,看看路径对不?