---
# System prepended metadata

title: java 台北2

---

# java 台北2

## project lombok
```
java -jar lombok.jar
```

## JDK, wifi同學無法安裝WDT

```
keytool -delete -alias "CTBC_CA_SHA2" -keystore "d:\tools\jdk17\..." -storepass changeit
```

# lab1 
* https://start.spring.io/
* Maven
* Spring 2.7.10
* lab1
* web, lombok, devtools, h2, jpa, validation
* copy lab1 to desktop\labs
* extract
* File/Import
* Maven/Existing Maven Projects
* 會看到pom.xml
* Run as /Maven build ...
* spring-boot:run

you should see " Tomcat started on port(s): 8080 (http) with context path ''"
* src\test\java Run as==> JUnit
```
```
---

## download this:

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

### /src/main/resources/templates/home.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>Insert title here123</title>
</head>
<body>
	<h1>My first spring boot MVC</h1>
	<h2 th:text="${message}"></h2>
	<h3>logo</h3>
	<img src="/images/ctbc_logo.png" />
	<h3>logo2</h3>
	<img th:src="@{/images/ctbc_logo.png}" />
</body>
</html>
```
### /src/main/java/<default_package>/controllers
```java
package com.ctbcbank.demo.Lab1.controllers;

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

@Controller
public class HomeController {
	@GetMapping("/")
	public String home(Model model) {
		model.addAttribute("message", 
				"試試message from controller123!!");
		return "home";
	}
}

```

# 26-Apr-2023
```java
package com.ctbcbank.demo.Lab1;

import org.hamcrest.Matchers;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.web.servlet.MockMvc;

import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
@SpringBootTest
@AutoConfigureMockMvc
public class FirstHomeControllerTests {
	@Autowired
	private MockMvc mockMvc;
	@Test
	void mockIsNotNull() {
		Assertions.assertNotNull(mockMvc);
	}
	@Test
	void rootShouldBeOK() throws Exception {
		mockMvc.perform(MockMvcRequestBuilders.get("/"))
		.andExpect(MockMvcResultMatchers.status().isOk());
	}
	@Test
	void rootShouldBeHomeHTML() throws Exception {
		mockMvc.perform(MockMvcRequestBuilders.get("/"))
		.andExpect(MockMvcResultMatchers.status().isOk())
		.andExpect(MockMvcResultMatchers.view().name("home"))
		.andExpect(MockMvcResultMatchers.content().string(
				Matchers.containsString("message from controller")));
	}
	@Test
	void xyzShouldBeNotFound() throws Exception {
		mockMvc.perform(MockMvcRequestBuilders.get("/xyz"))
		.andExpect(MockMvcResultMatchers.status().isNotFound());
		
	}

}

```

# https://site.mockito.org/

## your lab1 sample:

### https://drive.google.com/file/d/1Oi1ig8rVB3YUigdxyUPHWga_BmToerMO/view?usp=sharing


### Java Spring finish

* https://drive.google.com/file/d/10a8EpxeL0TfbxsF3tXLr2uAz3FIVPuI2/view?usp=share_link


### Spring lab pre walkthrough

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

### angular lab files:

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

