springboot集成mybatis

1.添加mybatis依賴

<dependency>
    <groupId>org.mybatis.spring.boot</groupId>
    <artifactId>mybatis-spring-boot-starter</artifactId>
    <version>${mybatis.version}</version>
</dependency>

<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-boot-starter</artifactId>
    <version>3.0.5</version>
</dependency>

2.添加mysql依賴

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.14</version>
</dependency>

3.配置

3.1 SpringbootApplition.java

類上添加註解 @MapperScanjava

@SpringBootApplication
@MapperScan("com.dylan.dylanmybatisstarter.pre")
public class DylanMybatisStarterApplication {

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

}

3.2 application.xml

#mysql鏈接
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8
spring.datasource.username=root
spring.datasource.password=root

mybatis.type-aliases-package=com.dylan.dylanmybatisstarter.pre # 掃描實體類
mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl #打印sql

3.3 配置dao層

實現 BaseMappermysql

@Repository
public interface LogDao extends BaseMapper<DylanLog>{
}
相關文章
相關標籤/搜索