使用 VS Code 開發 Springboot MVC 專案
使用 Intellij Community 2023.2
- 主程式: /src/main/java/com.hengetech.simple_demo/exercises/ _01..._04
- 測試程式: /src/test/java/com.hengetech.simple_demo/exercises/ _01..._04
- 從測試程式可以看到輸入值及預期輸出值, 再把主程式完成以滿足測試的條件。
- 分別完成主程式 exercises 內的程式, 程式的完成以測試程式是否通過測試為目的
- 測試程式不用變動, 僅用來檢驗主程式的執行結果。程式完成後, 測試結果應該全部呈現綠色通過標誌。
- 完成後的參考程式在位 branch: exercise_01_04, https://github.com/FreePhil/maven_basic/tree/exercise_01_04
- Java Extension Plugin
- Spring Boot Plugin
- Extra Plugins
- Web: http://localhost:8080/content1
- Web: http://localhost:8080/content1?name=HengeTech
- Rest API: http://localhost:8080/gi/fix-wired
Java | C# |
---|---|
|
|
|
|
- namespace: 全部小寫或_, i.e., com.henge.maven_basic
- class/interface: 大寫開頭 Pascal Style, i.e., Car, ToyotaCar, ToyotaCRVCar
- variable: 小寫開頭 Camel Style, i.e., userName, location, createdDate
- method/function: 小寫開頭 Camel Style, i.e., getUserName, findLocation
- interface
public interface Car { String getMake(); }
- class
public class ToyotaCar implements Car { public String getMake() { return "Toyota"; } } or public class CarImpl implements Car { .... .... .... } public class ToyotaCRVCar extends ToyotaCar { @Override public String getMake() { return "Toyota-CRV"; } }
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>nz.net.ultraq.thymeleaf</groupId>
<artifactId>thymeleaf-layout-dialect</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>12.4.1.jre11</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>