先在pom文件里添加相关依赖
<!--配置mybatis相关依赖--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.3.0</version> </dependency>
配置文件中加入相关配置
#配置数据源 spring.datasource.url=jdbc:mysql://localhost:3306/witkey spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.datasource.username=root spring.datasource.password=123 #mybatis相关配置 #mybatis映射文件的位置 mybatis.mapper-locations=classpath:mapping/*.xml #起别名 mybatis.type-aliases-package=com.buba.pojo #驼峰映射 mybatis.configuration.map-underscore-to-camel-case=true #打印mybatis的sql语句 logging.level.com.buba.mapper=debug
然后在springboot启动类上面加注解@MapperScan(basePackages = {"com.buba.mapper"})
在mapper的接口上必须写@Repository注解
打印的sql语句