1.引入依賴:java
1 <dependency> 2 <groupId>org.mybatis.spring.boot</groupId> 3 <artifactId>mybatis-spring-boot-starter</artifactId> 4 <version>2.0.0</version> 5 </dependency> 6 <dependency> 7 <groupId>mysql</groupId> 8 <artifactId>mysql-connector-java</artifactId> 9 </dependency> 10 <dependency> 11 <groupId>com.alibaba</groupId> 12 <artifactId>druid</artifactId> 13 <version>1.1.10</version> 14 </dependency>
2.application.propertiesmysql
#DB Configation spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.datasource.url=jdbc:mysql://127.0.0.1:3306/springboot?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC spring.datasource.username=root spring.datasource.password=root # JPAConfiguration spring.jpa.database=mysql spring.jpa.show-sql=true spring.jpa.generate-ddl=true spring.freemarker.suffix=.ftl
或application.ymlspring
spring: datasource: driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://127.0.0.1:3306/springboot?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC username: root password: root jpa: database: mysql show-sql: true generate-ddl: true freemarker: suffix: .ftl
3.在SpringBoot上增長啓動類sql
@SpringBootApplication
@MapperScan(basePackages = "com.feiyu.user.dao")
public class JpaApplication {
public static void main(String[] args) {
SpringApplication.run(JpaApplication.class, args);
}
}
便可正常使用springboot