---
# System prepended metadata

title: CTBC台北-1 2023/2/22

---

# CTBC台北-1 2023/2/22
# 環境檢查
## 環境檢查

### cmd

### `java -version`
### `javac -version`
### `where java`

### 設定JAVA_HOME
### 設定Path
* `%JAVA_HOME%\bin`

### Eclipse的設定位置

![](https://i.imgur.com/BQpUPzc.png)

![](https://i.imgur.com/5s94nvN.png)

### Add JRE

![](https://i.imgur.com/lWYZ7MK.png)

### 測試eclipse的連網 (下午)

### Windows/Preference

### https://github.com/adobe-fonts/source-code-pro

![](https://i.imgur.com/1hYLnES.png)


### Demo1 Review熱鍵
```java
package lab1;

import java.util.ArrayList;
import java.util.List;

// 使用alt+/
// 使用ctrl+shift+F
// ctrl+shift+O
// alt+上, alt+下
// ctrl+/ 註解(toggle)
// alt+shift+S ==> 對source生成...
public class Lab1Main {

	public static void main(String[] args) {
		// 1 設定環境
		// 2 講解規則
		// 3 設定學習目標
		List<String> studied = new ArrayList<String>();
		List<String> studied2 = new ArrayList<String>();
		// 4 執行
		String[] targets = { "Java", "Spring Boot", "Angular", "Domain Driven Design" };

				
		for (String s : targets) { // ctrl+click 物件變數==> 物件的定義
			System.out.println("選取的是:" + s);
		}

	}
}




```
### lab2
```java
package lab2;
// 單行註解
/*
 * 我是
 * 多
 * 行註解
 * 
 */
/**
 * 我是說明文件
 * @author Admin
 *
 */
public class Lab2Main {
	public static void main(String[] args) {
		// 001, 010, 100, 011,
		String s1 = "111101011010";
		int x1 = Integer.parseInt(s1, 2);
		int x2 = 0b111101011010;
		System.out.printf("x1=%d x2=%d \n", x1, x2);
		int x3 = 1_0000_0000;
		int x4 = 100_000_000;
		System.out.printf("x3=%d, x4=%d, x3-x4=%d \n", x3, x4, x3-x4);
		// System.out.println("good bye");
	}
}

```

![](https://i.imgur.com/Mgs1nDo.png)


![](https://i.imgur.com/DUvoiAp.png)

![](https://i.imgur.com/NVRh7z7.png)


# Day2
* %JAVA_HOME%\bin
##  jconsole
## jarsigner
## keytool

### https://martinfowler.com/books/uml.html

![](https://i.imgur.com/Rsoxcmm.png)

![](https://i.imgur.com/4mN4Ijn.png)

![](https://i.imgur.com/yILdzvS.png)


# https://zh.wikipedia.org/zh-tw/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%EF%BC%9A%E5%8F%AF%E5%A4%8D%E7%94%A8%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E8%BD%AF%E4%BB%B6%E7%9A%84%E5%9F%BA%E7%A1%80


![](https://i.imgur.com/MQBxrn0.png)

![](https://i.imgur.com/hXUdKxb.png)


# https://www.manning.com/

# https://www.manning.com/books/regular-expression-puzzles-and-ai-coding-assistants


![](https://i.imgur.com/FNDQeBI.png)


![](https://i.imgur.com/38ZvACH.png)


# https://git-scm.com/

## week1的原始碼:

* https://drive.google.com/file/d/1JQIStmhHJz0xKpaz38zOfXV5LXrMXJ8k/view?usp=sharing


![](https://i.imgur.com/ESPjs9j.png)

![](https://i.imgur.com/IYDs8KD.png)

# Day4

![Uploading file..._5h4x8hi1f]()



![](https://i.imgur.com/ivOw80N.png)

# Day5

1. https://start.spring.io/

https://start.spring.io/

![](https://i.imgur.com/Y9GMdtf.png)


![](https://i.imgur.com/iK4022q.png)


![](https://i.imgur.com/6ZFhu3B.png)

![](https://i.imgur.com/HWK5gmv.png)

![](https://i.imgur.com/KhLxDpK.png)

![](https://i.imgur.com/pU7J1Xk.png)

![](https://i.imgur.com/IblZn9L.png)

![](https://i.imgur.com/tOOYjwT.png)

![](https://i.imgur.com/XggSSFz.png)

# http://localhost:8080/
# http://localhost:8080/actuator

# https://git-scm.com/

```
git --version
```

# 正式開始

1. https://start.spring.io/

![](https://i.imgur.com/96MbDTm.png)


![](https://i.imgur.com/LJShJ1P.png)

![](https://i.imgur.com/GKmHzOK.png)

![](https://i.imgur.com/Y0w0nA4.png)

![](https://i.imgur.com/Z8SunOj.png)

![](https://i.imgur.com/8URXQAa.png)

# share the project setup

* copy/paste this

* https://start.spring.io/#!type=maven-project&language=java&platformVersion=2.7.9&packaging=jar&jvmVersion=11&groupId=com.ctbcbank.boot&artifactId=lab1&name=lab1&description=Demo%20project%20for%20Spring%20Boot&packageName=com.ctbcbank.boot.lab1&dependencies=devtools,h2,web,thymeleaf,lombok,actuator,validation,data-jpa


* 解壓縮
* File/Import

![](https://i.imgur.com/v930FX7.png)

![](https://i.imgur.com/JgClayK.png)

![](https://i.imgur.com/bqIkL6t.png)

```
spring-boot:run
```
![](https://i.imgur.com/1rWxXW6.png)


# http://localhost:8080/
# http://localhost:8080/actuator

![](https://i.imgur.com/dqzN6k1.png)


# https://git-scm.com/book/zh-tw/v2/%E9%96%8B%E5%A7%8B-%E5%88%9D%E6%AC%A1%E8%A8%AD%E5%AE%9A-Git

```
git config --global user.name "Mark Ho"
git config --global user.email "mark@patristar.com"
```
more .gitconfig

![](https://i.imgur.com/38NEqpy.png)


![](https://i.imgur.com/LUu3x0i.png)


![](https://i.imgur.com/C2sCM4B.png)


![](https://i.imgur.com/2v1dZrg.png)

![](https://i.imgur.com/7hzYF3P.png)

![](https://i.imgur.com/Y1TYRtH.png)

![](https://i.imgur.com/8EqsWoq.png)


![](https://i.imgur.com/I6WZXRl.png)


# 午休完的準備
* 用marketplace安裝web tools
* 下載2-3張圖形到桌面備用

# https://projectlombok.org/

![](https://i.imgur.com/NLfV4Fg.png)

![](https://i.imgur.com/c1E4S2f.png)

* https://www.tenlong.com.tw/products/9789864345618?list_name=srh


![](https://i.imgur.com/qbZVHry.png)

```
surefire-report:report
```
# C:\Users\Admin\Desktop\2023_Mar_02\lab1\target\site

# Day6

## https://learn.microsoft.com/en-us/dotnet/architecture/modern-web-apps-azure/common-web-application-architectures

## mvnw --version
* 告訴你maven版本, 抓到的JDK version
## mvnw install
## mvnw spring-boot:run
## mvnw test
## mvnw surefire-report:report

![](https://i.imgur.com/udh0nLR.png)


## https://martinfowler.com/books/refactoring.html

![](https://i.imgur.com/YO3i9av.png)

# Lab1&2的準備

![](https://i.imgur.com/6H0FOWQ.png)


![](https://i.imgur.com/ZYhJteJ.png)


![](https://i.imgur.com/QAXwvNy.png)

![](https://i.imgur.com/W0By7L0.png)


* https://start.spring.io/#!type=maven-project&language=java&platformVersion=2.7.9&packaging=jar&jvmVersion=11&groupId=com.ctbcbank.lab&artifactId=lab1&name=lab1&description=Demo%20project%20for%20Spring%20Boot&packageName=com.ctbcbank.lab.lab1&dependencies=lombok,devtools,web,thymeleaf,h2,data-jpa,validation,actuator


```
https://start.spring.io/#!type=maven-project&language=java&platformVersion=2.7.9&packaging=jar&jvmVersion=11&groupId=com.ctbcbank.lab&artifactId=lab1&name=lab1&description=Demo%20project%20for%20Spring%20Boot&packageName=com.ctbcbank.lab.lab1&dependencies=lombok,devtools,web,thymeleaf,h2,data-jpa,validation,actuator
```

![](https://i.imgur.com/OEoPiV3.png)

![](https://i.imgur.com/CbSvXeH.png)


![](https://i.imgur.com/FtL1z0V.png)


# mvnw install
# mvnw spring-boot:run
* ctrl+c停掉
# mvnw test
# mvnw surefire-report:report
# mvnw dependency:tree


![](https://i.imgur.com/TTOphnK.png)

![](https://i.imgur.com/LyLk9XL.png)

* new
# https://junit.org/junit5/docs/current/user-guide/#extensions-exception-handling
* original 
# https://junit.org/junit5/docs/current/user‑guide/#extensionsexception‑handling


# 作業1
* https://drive.google.com/file/d/1_uE3sJQadeLJySGoijdwDF-x_7SRAypo/view?usp=sharing

# week2的code
* https://drive.google.com/file/d/1ScZOm2C1m_v-t8kyExJiwqUPmB9jk8QT/view?usp=sharing

# Week3 Day3

## package com.ctbcbank.boot.lab1.bean
### CourseForm.java
```java
package com.ctbcbank.boot.lab1.bean;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Size;

import lombok.Getter;
import lombok.Setter;

//@Data
public class CourseForm {
	@NotEmpty
	@Size(min=5, max=30)
	@Getter
	@Setter
	private String courseId;
	@Getter
	@Setter
	private String courseName;
	@Getter
	@Setter
	private Integer duration;
}

```

## 縮減的型式

### 完成的如下
```java
package com.ctbcbank.boot.lab1.bean;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import lombok.Data;

@Data
public class CourseForm {
	@NotEmpty
	@Size(min=5, max=30)
	private String courseId;
	@NotEmpty
	private String courseName;
	@NotNull
	@Min(7)
	private Integer duration;
}

```

![](https://i.imgur.com/5pzF5y1.png)

### 樣版
```html
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
	xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF8">
<title>Insert title here</title>
</head>
<body>
</body>
</html>
```

![](https://i.imgur.com/ZbaUep7.png)

![](https://i.imgur.com/XPYaXHT.png)

![](https://i.imgur.com/52iJKyx.png)


# When you want to implement a MVC
## html --> view
* `course.html`
## controller --> @Controller
## Model --> form (data bean)


# CourseController.java
```java
package com.ctbcbank.boot.lab1.controllers;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class CourseController {
	@GetMapping("/course")
	public String showCourse() {
		return "course";
	}
}

```

# 講解lab
## https://start.spring.io/
* https://start.spring.io/#!type=maven-project&language=java&platformVersion=2.7.9&packaging=jar&jvmVersion=11&groupId=com.ctbcbank.lab&artifactId=workthrough1&name=workthrough1&description=Demo%20project%20for%20Spring%20Boot&packageName=com.ctbcbank.lab.workthrough1&dependencies=web,devtools,lombok,validation


## git建立基礎 
* 從start.spring.io新增, 初始相依性web,devtools,lombok,validation
![](https://i.imgur.com/DxgKaFg.png)

![](https://i.imgur.com/Ysk15Ez.png)

* `git status`

* https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/UUID.html
* Course
```java
package com.ctbcbank.lab.workthrough1.model;

import java.util.UUID;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@NoArgsConstructor
@AllArgsConstructor
public class Course {
	@Getter
	@Setter
	private UUID id;
	@Getter
	@Setter
	private String name;
	@Getter
	@Setter
	private int price;
	@Getter
	@Setter
	private CourseCategory category;
}

```

* CourseCategory
```java
package com.ctbcbank.lab.workthrough1.model;

import java.util.UUID;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@AllArgsConstructor
@NoArgsConstructor
public class CourseCategory {
	@Getter
	@Setter
	private String name;
	@Getter
	@Setter
	private String detail;
	@Getter
	@Setter
	private UUID id;
}

```

# CourseTest.java
```java
package com.ctbcbank.lab.workthrough1.lab1;

import java.util.UUID;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import com.ctbcbank.lab.workthrough1.model.Course;

public class CourseTest {
	@Test
	public void noArgumentTest() {
		Course c1 = new Course();
		//Course c1 = null;
		Assertions.assertNotNull(c1,
				"course should not be null");
	}
	@Test
	public void allArgsTest() {
		Course c1 = new Course(UUID.randomUUID(),"name",500,null);
		Assertions.assertNotNull(c1,
				"course should not be null");		
	}

}


```

* CourseService.java
```java
package com.ctbcbank.lab.workthrough1.service;

import java.util.List;
import java.util.UUID;

import com.ctbcbank.lab.workthrough1.model.Course;
import com.ctbcbank.lab.workthrough1.model.CourseCategory;

public interface CourseService {
	List<Course> getAllCourse();
	Course addCourse(String name, int price, CourseCategory cateogry);
	void removeCourse(UUID id);
	Course modifyCourse(UUID id, String name, int price, CourseCategory cateogry);
}

```

* CourseServiceJDKImplement

```java
package com.ctbcbank.lab.workthrough1.service;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import com.ctbcbank.lab.workthrough1.model.Course;
import com.ctbcbank.lab.workthrough1.model.CourseCategory;

public class CourseServiceJDKImplement implements CourseService {
	private List<Course> course = new ArrayList<>();

	@Override
	public List<Course> getAllCourse() {
		return course;
	}

	@Override
	public Course addCourse(String name, int price, CourseCategory category) {
		Course c1 = new Course(UUID.randomUUID(), name, price, category);
		course.add(c1);
		return c1;
	}

	@Override
	public void removeCourse(UUID id) {
		for (Course c : course) {
			if (c.getId().equals(id)) {
				course.remove(c);
			}
		}
	}

	@Override
	public Course modifyCourse(UUID id, String name, int price, CourseCategory cateogry) {
		for (Course c : course) {
			if (c.getId().equals(id)) {
				c.setName(name);
				c.setPrice(price);
				c.setCategory(cateogry);
				return c;
			}
		}

		return null;
	}

}

```
* CourseCategoryService
```java
package com.ctbcbank.lab.workthrough1.service;

import java.util.List;
import java.util.UUID;

import com.ctbcbank.lab.workthrough1.model.CourseCategory;

public interface CourseCategoryService {
	List<CourseCategory> getAllCourseCategory();
	CourseCategory addCourseCategory(String name, String detail);
	void removeCourseCategory(UUID id);
	CourseCategory modifyCourseCategory(UUID id, String name, 
			String detail);
}

```
* CourseCategoryServiceJDKImplement
```java
package com.ctbcbank.lab.workthrough1.service;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import com.ctbcbank.lab.workthrough1.model.CourseCategory;

public class CourseCategoryServiceJDKImplement implements CourseCategoryService{
	List<CourseCategory> categories = new ArrayList<>();
	@Override
	public List<CourseCategory> getAllCourseCategory() {
		return categories;
	}
	@Override
	public CourseCategory addCourseCategory(String name, String detail) {
		UUID uuid = UUID.randomUUID();
		CourseCategory category = new CourseCategory(name, detail,uuid);
		categories.add(category);
		return category;
	}

	@Override
	public void removeCourseCategory(UUID id) {
		for(CourseCategory category:categories) {
			if (category.getId().equals(id)) {
				categories.remove(category);
				return;
			}
		}	
	}

	@Override
	public CourseCategory modifyCourseCategory(UUID id, String name, String detail) {
		for(CourseCategory category:categories) {
			if (category.getId().equals(id)) {
				category.setName(name);
				category.setDetail(detail);
				return category;
			}
		}	
		return null;
	}

}

```

* CourseFactory
```java
package com.ctbcbank.lab.workthrough1.factory;

import com.ctbcbank.lab.workthrough1.service.CourseService;
import com.ctbcbank.lab.workthrough1.service.CourseServiceJDKImplement;

public class CourseFactory {
	// static
	public static CourseService getService() {
		CourseService s1 = new CourseServiceJDKImplement();
		return s1;
		
	}

}

```

* CourseForm.html
```html
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
	xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF8">
<title>課程管理介面</title>
</head>
<body>
	<h1>課程表單</h1>
	<form th:object="${courseForm}" method="post" th:action="@{/course}">
		<table>
			<tr>
				<td>課程ID</td>
				<td><input type="text" th:field="*{courseId}" /></td>
				<td th:errors="*{courseId}">如果id有錯就會放在這兒</td>
			</tr>
			<tr>
				<td>課程名稱</td>
				<td><input type="text" th:field="*{courseName}" /></td>
				<td th:errors="*{courseName}">如果name有錯就會放在這兒</td>
			</tr>
			<tr>
				<td>課程時數</td>
				<td><input type="number" th:field="*{duration}"></td>
				<td th:errors="*{duration}"></td>
			</tr>
			<tr>
				<td><button type="submit">Submit</button></td>
			</tr>
		</table>
	</form>
</body>
</html>
```
* CourseController.java
```java
package com.ctbcbank.boot.lab1.controllers;

import javax.validation.Valid;

import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import com.ctbcbank.boot.lab1.bean.CourseForm;

import lombok.extern.slf4j.Slf4j;

@Controller
@Slf4j
public class CourseController implements WebMvcConfigurer {
	@Override
	public void addViewControllers(ViewControllerRegistry registry) {
		registry.addViewController("/results").setViewName("results");
	}
	@GetMapping("/course")
	public String showCourse(CourseForm x) {
		return "course";
	}
	@PostMapping("/course")
	public String checkCourse(@Valid CourseForm y,BindingResult bindingResult) {
		log.info("get course from form:{}",y);
		if (bindingResult.hasErrors()) {
			log.info("validation got errors, need to fix");
			return "course";
		}
		return "redirect:/results"; //這邊應該是個成功的網頁的URL
	}
}

```

# maven 
```
mvnw --version
mvnw clean
mvnw compile
mvnw package
java -jar target\lab1-0.0.1-SNAPSHOT.jar
```

![](https://i.imgur.com/azsLrdS.png)
```
mvnw dependency:tree
```

* https://tomcat.apache.org/whichversion.html
* https://www.postman.com/
* https://www.advancedrestclient.com/

# GreetingController
```java
package com.ctbcbank.boot.lab1.controllers;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class GreetingController {
	private static final String NAME = "name";
	private static final String PROMPT = "prompt";
	@RequestMapping("/hello")
	public String doGreet(
			@RequestParam(value="name",required=false,defaultValue = "Brian") String name,
			@RequestParam(value="prompt",required=false,defaultValue = "hello") String prompt
			,Model model) {
		model.addAttribute(NAME, name);
		model.addAttribute(PROMPT,prompt);
		return "greeting";
	}
}

```

# HelloController
```java
package com.ctbcbank.boot.lab1.controllers;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/hello")
public class HelloController {
	@GetMapping("")
	public String getHello() {
		return "hello_get";
	}
	@PostMapping("")
	public String postHello() {
		return "hello_post";
	}
	@PutMapping("")
	public String putHello() {
		return "hello_put";
	}
	@PatchMapping("")
	public String patchHello() {
		return "hello_patch";
	}
	@DeleteMapping("")
	public String deleteHello() {
		return "hello_delete";
	}
}


```

* Customer.java
```java
package com.ctbcbank.boot.lab1.bean;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@NoArgsConstructor
@AllArgsConstructor
@Data
@Entity
public class Customer {
	@Id
	@GeneratedValue
	private Long id;
	private String firstName;
	private String lastName;
	private String mobilePhone;
	private String email;
}

```

* show-sql
* `spring.jpa.show-sql=true`
```
## change server port
# server.port=8880
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true

```

* CustomerRunner.java
```java

package com.ctbcbank.boot.lab1.runner;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import com.ctbcbank.boot.lab1.bean.Customer;
import com.ctbcbank.boot.lab1.repository.CustomerRepository;

import lombok.extern.slf4j.Slf4j;

@Component
@Slf4j
public class CustomerRunner implements CommandLineRunner {
	@Autowired
	private CustomerRepository repository;

	@Override
	public void run(String... args) throws Exception {
		// 塞幾筆資料
		initData();
		// 把資料取得
		// SELECT * FROM CUSTOMER
		for (Customer customer : repository.findAll()) {
			log.info("get a customer:{}", customer);
		}
		repository.findAll().forEach(customer -> log.info("**{}", customer));
	}

	private void initData() {
		Customer customer = new Customer();
		customer.setLastName("Ho");
		customer.setFirstName("Mark");
		Customer customer2 = new Customer();
		customer2.setLastName("Chiang");
		customer2.setFirstName("Brian");
		repository.save(customer);
		repository.save(customer2);

	}

}

```

* CustomerServiceJPAImplement.java
```java

package com.ctbcbank.boot.lab1.services;

import java.util.List;
import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ctbcbank.boot.lab1.bean.Customer;
import com.ctbcbank.boot.lab1.repository.CustomerRepository;

@Service
public class CustomerServiceJPAImplement implements CustomerService {
	@Autowired
	private CustomerRepository repository;
	@Override
	public List<Customer> findAll() {
		return repository.findAll();
	}

	@Override
	public Customer findOne(Long id) {
		Optional<Customer> optionalCustomer = repository.findById(id);
		return optionalCustomer.get();
	}

	@Override
	public Customer create(Customer c) {
		Customer savedCustomer = repository.save(c);
		return savedCustomer;
	}

	@Override
	public Customer update(Customer c) {
		Customer savedCustomer = repository.save(c);
		return savedCustomer;
	}

	@Override
	public void delete(Long id) {
		repository.deleteById(id);
	}

}

```

* CustomerRestController
```java
package com.ctbcbank.boot.lab1.controllers;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ctbcbank.boot.lab1.bean.Customer;
import com.ctbcbank.boot.lab1.services.CustomerService;

@RestController
@RequestMapping("/api/customers")
public class CustomerRestController {
	@Autowired
	private CustomerService service;
	@GetMapping("")
	public List<Customer> getAllCustomers() {
		return service.findAll();
	}
	@PostMapping("")
	public Customer createCustomer(@RequestBody Customer customer) {
		return service.create(customer);
	}
}

```
## 作業2

* https://drive.google.com/file/d/16GlB3RFKbnBwXEOZ-KbdtBGDeMqENylD/view?usp=sharing


## 第三周的程式碼整包
* https://drive.google.com/file/d/1K4jQU3VAG0myE8oMdngk0_-8ivJPcW_o/view?usp=sharing

# Day9

![](https://i.imgur.com/SRLI1Xk.png)


```
'Source Code Pro',Consolas, 'Courier New', monospace
```

![](https://i.imgur.com/jWr8BaM.png)


![](https://i.imgur.com/XlDj9Jf.png)


```
node --version
npm --version
npm config ls
npm config get prefix
npm install -g npm
npm list -g
npm install -g @angular/cli
npm list -g
npm list -g --depth=2
```
```
ng serve
ng new lab1_no_strict --strict false
```

```
npm start
ng serve
```

![](https://i.imgur.com/tYGUqcG.png)

# https://getbootstrap.com/

![](https://i.imgur.com/bcvr68G.png)


# lab2的準備工作
* https://start.spring.io/

* https://start.spring.io/#!type=maven-project&language=java&platformVersion=2.7.9&packaging=jar&jvmVersion=11&groupId=com.ctbcbank.lab&artifactId=backend&name=backend&description=Demo%20project%20for%20Spring%20Boot%2C%20as%20angular%20backend&packageName=com.ctbcbank.lab.backend&dependencies=devtools,lombok,web,thymeleaf,data-jpa,h2,validation

* https://docs.jboss.org/hibernate/stable/entitymanager/reference/en/html/listeners.html
* 1.2.1

----------------------------
# Day10

### `ng serve`
### https://getbootstrap.com/docs/5.0/getting-started/introduction/

### https://getbootstrap.com/docs/5.0/components/buttons/


# Day11

### gyms.component.ts
```javascript

import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-gyms',
  templateUrl: './gyms.component.html',
  styleUrls: ['./gyms.component.css'],
})
export class GymsComponent implements OnInit {
  gyms = [
    { name: '復興北', count: 4 },
    { name: '北車京站', count: 3 },
    { name: '戶江高中', count: 12 },
  ];

  onGymAdd(eventData: { name: string; count: number }) {
    this.gyms.push({ name: eventData.name, count: eventData.count });
  }
  onGymDelete(deletedItemIndex: number) {
    this.gyms.splice(deletedItemIndex, 1);
  }
  onGymUpdate(index: number, eventData: { name: string; count: number }) {
    this.gyms[index] = { name: eventData.name, count: eventData.count };
  }

  allowReload = true;
  searchCriteria = '找的預設值';
  searchCriteria2 = '第二個預設值';
  onSearchGym(event: Event) {
    console.log('事件是:', event);
    console.log('對象是:', event.target);
    console.log('值是:', (event.target as HTMLInputElement).value);
    this.searchCriteria = (event.target as HTMLInputElement).value;
  }
  onCheckStatus(condition) {
    console.log('查詢是否可以重新載入', condition);
  }
  constructor() {
    console.log('gyms component創建了!');
    setTimeout(() => {
      console.log('五秒後才會執行這個');
      this.allowReload = false;
      this.gyms.push({ name: '松菸', count: 10 });
      setTimeout(() => {
        console.log('五秒後才會執行這個');
        this.allowReload = true;
        this.gyms.push({ name: '民生東', count: 8 });
      }, 5000);
    }, 5000);
  }
  ngOnInit(): void {
    console.log('gyms component初始化了');
  }
}

```

# Day12
### bootstrap color
* https://getbootstrap.com/docs/4.0/utilities/colors/



* final angular
* https://drive.google.com/file/d/1DzSLSt0IL4JWfmKaAlwi3vX0h5DC1vDa/view?usp=sharing


* spring final 
* https://drive.google.com/file/d/1OvSWJPyXYmzzjJjsiSQDGvwra7Mi-KZ7/view?usp=sharing