打卡7

平安喜乐×發表於2024-06-16
所花時間(包括上課) 2h
程式碼量(行) 約150行
部落格量(篇) 1
瞭解到的知識 spring boot
備註

<!--
mybatis對springboot的支援
不需要額外引入 mybatis的依賴
-->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.0</version>
</dependency>
<!-- 資料來源 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.20</version>
</dependency>
<!-- mysql相關依賴 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0</version>
</dependency>

server:
port: 8989
servlet:
context-path: /springboot
spring:
datasource:
username: root #資料庫使用者名稱
password: 20223959 #資料庫密碼
type: com.alibaba.druid.pool.DruidDataSource #type
url: jdbc:mysql://localhost:3306/test #url
driver-class-name: com.mysql.jdbc.Driver #驅動
mybatis:
#掃描對映檔案
mapper-locations: classpath:com/bz/mapper/**/*Mapper.xml
#實體類定義別名
type-aliases-package: com.bz.entity

<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
</build>

@SpringBootApplication
//dao 掃描
@MapperScan("com.bz.dao")
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

//springboot環境執行
@RunWith(SpringRunner.class)
//載入 入口類
@SpringBootTest(classes = Application.class)
public class SpringbootApplicationTests {
@Test
public void contextLoads() {
}
}