最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

解決mybatis-plus通用mapper調(diào)用報錯:Invalid bound statement

 更新時間:2021年09月01日 10:24:30   作者:今夜月色很美  
這篇文章主要介紹了解決mybatis-plus通用mapper調(diào)用報錯:Invalid bound statement的問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教

mybatis-plus通用mapper調(diào)用報錯

使用springboot整合mybatis-plus后,調(diào)用自定義的方法正常,調(diào)用BaseMapper中自帶的方法報錯如下:

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): cn.rkang.enterprise.mapper.EmployeeInfoMapper.selectOne
    at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:227) ~[mybatis-3.4.6.jar:3.4.6]
    at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:49) ~[mybatis-3.4.6.jar:3.4.6]
    at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:65) ~[mybatis-3.4.6.jar:3.4.6]
    at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:58) ~[mybatis-3.4.6.jar:3.4.6]
    at com.sun.proxy.$Proxy70.selectOne(Unknown Source) ~[na:na]
    at com.baomidou.mybatisplus.extension.service.impl.ServiceImpl.getOne(ServiceImpl.java:259) ~[mybatis-plus-extension-3.1.1.jar:3.1.1]
    at com.baomidou.mybatisplus.extension.service.IService.getOne(IService.java:192) ~[mybatis-plus-extension-3.1.1.jar:3.1.1]
    at com.baomidou.mybatisplus.extension.service.IService
FastClassBySpringCGLIB
FastClassBySpringCGLIB
f8525d18.invoke(<generated>) ~[mybatis-plus-extension-3.1.1.jar:3.1.1]
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:684) ~[spring-aop-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at cn.rkang.enterprise.local.service.EmployeeInfoService
EnhancerBySpringCGLIB
EnhancerBySpringCGLIB
7e12f21b.getOne(<generated>) ~[classes/:na]

跟進源碼發(fā)現(xiàn)是methodProxy.invoke(target, argsToUse)報錯

if (chain.isEmpty() && Modifier.isPublic(method.getModifiers())) {
    Object[] argsToUse = AopProxyUtils.adaptArgumentsIfNecessary(method, args);
    retVal = methodProxy.invoke(target, argsToUse);
} else {
    retVal = (new CglibAopProxy.CglibMethodInvocation(proxy, target, method, args, targetClass, chain, methodProxy)).proceed();
}

在invoke方法組裝sqlmand的時候,MappedStatement沒有組裝成功,始終是null

public SqlCommand(Configuration configuration, Class<?> mapperInterface, Method method) {
    String methodName = method.getName();
    Class<?> declaringClass = method.getDeclaringClass();
    MappedStatement ms = this.resolveMappedStatement(mapperInterface, methodName, declaringClass, configuration);
    if (ms == null) {
        if (method.getAnnotation(Flush.class) == null) {
            throw new BindingException("Invalid bound statement (not found): " + mapperInterface.getName() + "." + methodName);
        }
 
        this.name = null;
        this.type = SqlCommandType.FLUSH;
    } else {
        this.name = ms.getId();
        this.type = ms.getSqlCommandType();
        if (this.type == SqlCommandType.UNKNOWN) {
            throw new BindingException("Unknown execution method for: " + this.name);
        }
    }
}

解決方法

將mybatis的sqlSessionFactory替換成mybatis-plusd的MybatisSqlSessionFactoryBean,添加配置類MybatisPlusConfig

package cn.rkang.enterprise.common.config;
import com.baomidou.mybatisplus.core.MybatisConfiguration;
import com.baomidou.mybatisplus.core.MybatisXMLLanguageDriver;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
import org.apache.ibatis.mapping.DatabaseIdProvider;
import org.apache.ibatis.plugin.Interceptor;
import org.mybatis.spring.boot.autoconfigure.MybatisProperties;
import org.mybatis.spring.boot.autoconfigure.SpringBootVFS;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.ResourceLoader;
import org.springframework.util.StringUtils;
import javax.sql.DataSource;

@Configuration
public class MybatisPlusConfig {

    @Autowired
    private DataSource dataSource;

    @Autowired
    private MybatisProperties properties;

    @Autowired
    private ResourceLoader resourceLoader = new DefaultResourceLoader();

    @Autowired(required = false)
    private Interceptor[] interceptors;

    @Autowired(required = false)
    private DatabaseIdProvider databaseIdProvider;

    /**
     *   mybatis-plus分頁插件
     */
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        PaginationInterceptor page = new PaginationInterceptor();
        page.setDialectType("mysql");
        return page;
    }
    /**
     * 這里全部使用mybatis-autoconfigure 已經(jīng)自動加載的資源。不手動指定
     * 配置文件和mybatis-boot的配置文件同步
     * @return
     */
    @Bean
    public MybatisSqlSessionFactoryBean mybatisSqlSessionFactoryBean() {
        MybatisSqlSessionFactoryBean mybatisPlus = new MybatisSqlSessionFactoryBean();
        mybatisPlus.setDataSource(dataSource);
        mybatisPlus.setVfs(SpringBootVFS.class);
        if (StringUtils.hasText(this.properties.getConfigLocation())) {
            mybatisPlus.setConfigLocation(this.resourceLoader.getResource(this.properties.getConfigLocation()));
        }
        if (!ObjectUtils.isEmpty(this.interceptors)) {
            mybatisPlus.setPlugins(this.interceptors);
        }
        MybatisConfiguration mc = new MybatisConfiguration();
        mc.setDefaultScriptingLanguage(MybatisXMLLanguageDriver.class);
        //數(shù)據(jù)庫字段設(shè)計為駝峰命名,默認開啟的駝峰轉(zhuǎn)下劃線會報錯字段找不到
        mc.setMapUnderscoreToCamelCase(false);
        mybatisPlus.setConfiguration(mc);
        if (this.databaseIdProvider != null) {
            mybatisPlus.setDatabaseIdProvider(this.databaseIdProvider);
        }
        if (StringUtils.hasLength(this.properties.getTypeAliasesPackage())) {
            mybatisPlus.setTypeAliasesPackage(this.properties.getTypeAliasesPackage());
        }
        if (StringUtils.hasLength(this.properties.getTypeHandlersPackage())) {
            mybatisPlus.setTypeHandlersPackage(this.properties.getTypeHandlersPackage());
        }
        if (!ObjectUtils.isEmpty(this.properties.resolveMapperLocations())) {
            mybatisPlus.setMapperLocations(this.properties.resolveMapperLocations());
        }
        return mybatisPlus;
    }
}

問題解決!

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • Spring?Boot詳解五種實現(xiàn)跨域的方式

    Spring?Boot詳解五種實現(xiàn)跨域的方式

    跨域指的是瀏覽器不能執(zhí)?其他?站的腳本。它是由瀏覽器的同源策略造成的,是瀏覽器對javascript施加的安全限制,這篇文章主要介紹了springboot實現(xiàn)跨域的5種方式,需要的朋友可以參考下
    2022-06-06
  • 關(guān)于maven項目中使用BCrypt加密方式

    關(guān)于maven項目中使用BCrypt加密方式

    BCrypt是一種基于Blowfish加密算法的密碼散列函數(shù),用于安全存儲和驗證用戶密碼,它通過引入鹽和工作因子增加計算復(fù)雜度,有效防止彩虹表攻擊和破解,BCrypt具備適應(yīng)性工作因子、成本參數(shù)調(diào)整、迭代哈希和密鑰擴展等特點,被廣泛應(yīng)用于Web應(yīng)用程序的安全性設(shè)計中
    2024-10-10
  • ZooKeeper入門教程二在單機和集群環(huán)境下的安裝搭建及使用

    ZooKeeper入門教程二在單機和集群環(huán)境下的安裝搭建及使用

    本文是ZooKeeper入門系列教程,涵蓋ZooKeeper的安裝使及單機集群環(huán)境搭建,通過實例和大量圖表,結(jié)合實戰(zhàn),幫助學(xué)習(xí)者理解和運用,有需要的朋友可以借鑒參考下
    2022-01-01
  • JAVA中HTTP基本認證(Basic Authentication)實現(xiàn)

    JAVA中HTTP基本認證(Basic Authentication)實現(xiàn)

    HTTP 基本認證是一種簡單的認證方法,本文主要介紹了JAVA中HTTP基本認證(Basic Authentication),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2024-07-07
  • Idea配置Maven阿里云鏡像加速的實現(xiàn)

    Idea配置Maven阿里云鏡像加速的實現(xiàn)

    這篇文章主要介紹了Idea配置Maven阿里云鏡像加速的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-04-04
  • Linux系統(tǒng)下安裝和卸載JDK8的方式

    Linux系統(tǒng)下安裝和卸載JDK8的方式

    這篇文章主要介紹了Linux安裝和卸載JDK8,第一種是使用yum命令一鍵安裝,默認安裝目錄在/usr/lib/jvm第二種是手動安裝,本文給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-09-09
  • springboot連接neo4j報錯的解決方案

    springboot連接neo4j報錯的解決方案

    這篇文章主要介紹了springboot連接neo4j報錯的解決方案,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-02-02
  • Java SpringBoot實現(xiàn)AOP

    Java SpringBoot實現(xiàn)AOP

    AOP包括連接點(JoinPoint)、切入點(Pointcut)、增強(Advisor)、切面(Aspect)、AOP代理(AOP Proxy),具體的方法和類型下面文章會舉例說明,感興趣的小伙伴和小編一起閱讀全文吧
    2021-09-09
  • 詳解SpringCloud Ribbon 負載均衡通過服務(wù)器名無法連接的神坑

    詳解SpringCloud Ribbon 負載均衡通過服務(wù)器名無法連接的神坑

    這篇文章主要介紹了詳解SpringCloud Ribbon 負載均衡通過服務(wù)器名無法連接的神坑,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-06-06
  • Java對接微信支付全過程

    Java對接微信支付全過程

    本文主要介紹了Java對接微信支付全過程,涵蓋注冊商戶、生成預(yù)支付訂單、處理回調(diào)和查詢訂單狀態(tài)等,具有一定的參考價值,感興趣的可以了解一下
    2025-03-03

最新評論

嘉善县| 虞城县| 朝阳区| 光泽县| 濉溪县| 彰武县| 孝感市| 上林县| 磐安县| 乌鲁木齐县| 宜宾市| 塔河县| 永定县| 永德县| 长白| 四会市| 高青县| 仁寿县| 新疆| 荣昌县| 盱眙县| 舞钢市| 从江县| 乌审旗| 阿拉尔市| 安多县| 冷水江市| 阳原县| 富锦市| 新龙县| 莱州市| 杭锦旗| 凤山市| 大厂| 资中县| 广德县| 托克逊县| 来宾市| 娄烦县| 公安县| 临汾市|