org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):


org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.dao.mapper.UserInfoMapper.countByExample
        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.$Proxy93.countByExample(Unknown Source)
        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:498)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
        at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java

報錯原因是Mapper.xml文件中沒有id為countByExample的語句

 

如果出現:

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)

一般的原因是Mapper interfacexml文件的定義對應不上,需要檢查包名namespace函數名稱等能否對應上,需要比較細致的對比,
我經常就是寫錯了一兩個字母搞的很長時間找不到錯誤

按以下步驟一一執行:

1:檢查xml文件所在的package名稱是否和interface對應的package名稱一一對應

2:檢查xml文件的namespace是否和xml文件的package名稱一一對應

3:檢查函數名稱能否對應上

4:去掉xml文件中的中文注釋

5:隨意在xml文件中加一個空格或者空行然后保存
6: mapper.xml文件沒有被掃描到

一般來說到此就可以排除錯誤了

http://blog.csdn.net/softwarehe/article/details/8889206

 

mybatis Mapper插件中,updateByPrimaryKey 方法在使用時,入參必須包含id,
實際使用的sql如下:

2016-11-14 11:23:18.885 DEBUG 640 --- [ main] t.m.s.m.U.updateByPrimaryKey : ==> Preparing: UPDATE user_info SET username = ?,password = ?,usertype = ?,enabled = ?,qq = ?,email = ?,tel = ? WHERE Id = ?
2016-11-14 11:23:18.915 DEBUG 640 --- [ main] t.m.s.m.U.updateByPrimaryKey : ==> Parameters: test1(String), 12345678(String), 1(String), null, null, null, null, null
2016-11-14 11:23:18.924 DEBUG 640 --- [ main] t.m.s.m.U.updateByPrimaryKey : <== Updates: 0

 

如果只想更新指定字段的值,可以使用api:   userInfoMapper.updateByPrimaryKeySelective

    /**
     * 根據主鍵更新屬性不為null的值
     *
     * @param record
     * @return
     */
    @UpdateProvider(type = BaseUpdateProvider.class, method = "dynamicSQL")
    int updateByPrimaryKeySelective(T record);

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM