spring boot 集成 tk.mybatis

依赖jar


    tk.mybatis
    mapper-spring-boot-starter
    2.0.0


yml 配置

# mybatis 配置
mybatis:
  typeAliasesPackage: com.share.jdbc.entity
  mapperLocations: classpath*:mapper/*.xml
mapper:
  mappers: com.share.jdbc.core.CommonMapper
  not-empty: false
  identity: mysql

启动类

import tk.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@MapperScan(basePackages = "com.share.jdbc.mapper")
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
}

导入时这个包

tk.mybatis.spring.annotation.MapperScan;

而不是

org.mybatis.spring.annotation.MapperScan;

否则会产生

java.lang.NoSuchMethodException: tk.mybatis.mapper.provider.base.BaseSelectProvider.()

你可能感兴趣的:(spring,boot)