springboot集成Mybatis出现mapper层接口扫描不到的错误

springboot集成Mybatis出现mapper层接口扫描不到的错误_第1张图片

springboot中集成mybatis使用mapper.xml文件

  1. 主程序中要配置@MapperScan(“扫描的包名”)
@MapperScan("com.guigu.springboot.mapper")
@SpringBootApplication

public class Springboot06DataMybatisApplication {

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

}

  1. controller层用@Autowired注解进行自动注入
    @Autowired
    TeacherMapper mapper;
  1. springboot全局配置文件,配置了mapper.xml文件和mybatis配置文件的路径才会将这些属性和properties绑定

mybatis:
  config-location: classpath:mybatis-config.xml
  check-config-location: true
  mapper-locations: classpath:/mappers/*.xml

前面这几部分都必须要有.

如果想要设置驼峰式命名,在mybatis的全局配置文件中这样设置.
它其他的设置参数可以参考github上发布的文档
settings配置参数文档



<configuration>
  <settings>
      <setting name="mapUnderscoreToCamelCase" value="true"/>
  settings>

configuration>

你可能感兴趣的:(error)