Mybatis-plus一般的なマッパー呼び出しエラー:無効なバインドされたステートメント

springbootを使用してmybatis-plusを統合した後、カスタムメソッドの呼び出しは正常であり、BaseMapperの組み込みメソッドを呼び出すと次のようなエラーが報告されます。

org.apache.ibatis.binding.BindingException:無効なバインドされたステートメント(見つかりません):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]
    atcom.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]
    com.baomidou.mybatisplus.extension.service.IService.getOne(IService.java:192)〜[mybatis-plus-extension-3.1.1.jar:3.1.1]
    atcom.baomidou.mybatisplus.extension.service。 IService $$ 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 $$ 7e12f21b.getOne(<generated>)〜[classes /:na]

ソースコードをフォローアップすると、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

パッケージcn.rkang.enterprise.common.config; 

インポートcom.baomidou.mybatisplus.core.MybatisConfiguration; 
インポートcom.baomidou.mybatisplus.core.MybatisXMLLanguageDriver; 
インポートcom.baomidou.mybatisplus.core.toolkit.ObjectUtils; 
インポートcom.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; 
インポート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; 

インポートjavax.sql.DataSource; 

@Configuration 
public class MybatisPlusConfig { 

    @Autowired 
    private DataSource dataSource; 

    @Autowired
    プライベートMybatisPropertiesプロパティ; 

    @Autowired 
    private ResourceLoader resourceLoader = new DefaultResourceLoader(); 

    @Autowired(必須= false)
    プライベートインターセプター[]インターセプター; 

    @Autowired(必須= false) 
    private DatabaseIdProvider databaseIdProvider; 

    / ** 
     * mybatis-plusページングプラグイン
     * / 
    @Bean 
    public PaginationInterceptor paginationInterceptor(){ 
        PaginationInterceptor page = new PaginationInterceptor(); 
        page.setDialectType( "mysql"); 
        return page; 
    } 
    / ** 
     * mybatis-autoconfigureによって自動的にロードされたすべてのリソースがここで使用されます。手動で指定しないでください
     *構成ファイルはmybatis-bootの構成ファイルと同期されます
     * @ return 
     * / 
    @Bean 
    public MybatisSqlSessionFactoryBean mybatisSqlSessionFactoryBean(){
        MybatisSqlSessionFactoryBean mybatisPlus = new MybatisSqlSessionFactoryBean(); 
        mybatisPlus.setConfiguration(mc);を 
        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); 
        //データベースフィールドはハンプ命名で設計されており、下線を引くデフォルトのオープンハンプはエラーフィールド
        mcを報告します。見つかりません。setMapUnderscoreToCamelCase(false); 
            mybatisPlus.setDatabaseIdProvider(this.databaseIdProvider); 
        }
        if(this.databaseIdProvider!= null){
        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; 
    } 

}问题解决

おすすめ

転載: blog.csdn.net/noob9527/article/details/90229837