๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

Java19

Spring - ํšŒ์›๊ด€๋ฆฌ์˜ˆ์ œ (ํšŒ์› ์„œ๋น„์Šค ํ…Œ์ŠคํŠธ) test์ฝ”๋“œ๋Š” ํ•œ๊ธ€๋กœ ์ž‘์„ฑํ•ด๋„ ๋œ๋‹ค. test์ฝ”๋“œ๋Š” ์ด ์„ธ๊ฐœ์˜ ๋กœ์ง์œผ๋กœ ์ž‘์„ฑ๋  ์ˆ˜ ์žˆ๋‹ค. Given : ๋ฌด์—‡์ด ์ฃผ์–ด์ง„๋‹ค๋ฉด when : ์ด๊ฒƒ์„ ์‹คํ–‰ํ–ˆ์„๋•Œ then : ๊ฒฐ๊ณผ๊ฐ€ ์ด๊ฒƒ์ด ๋‚˜์™€์•ผํ•œ๋‹ค @BeforeEach : ๊ฐ ํ…Œ์ŠคํŠธ ์‹คํ–‰ ์ „์— ํ˜ธ์ถœ๋œ๋‹ค. ํ…Œ์ŠคํŠธ๊ฐ€ ์„œ๋กœ ์˜ํ–ฅ์ด ์—†๋„๋ก ํ•ญ์ƒ ์ƒˆ๋กœ์šด ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜๊ณ , ์˜์กด๊ด€๊ณ„๋„ ์ƒˆ๋กœ ๋งบ์–ด์ค€๋‹ค. package hello.hellospring.service; import hello.hellospring.domain.Member; import hello.hellospring.repository.MemoryMemberRepository; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertio.. 2023. 7. 4.
Spring - ํšŒ์›๊ด€๋ฆฌ์˜ˆ์ œ (ํšŒ์› ์„œ๋น„์Šค ๊ฐœ๋ฐœ) package hello.hellospring.service; import hello.hellospring.domain.Member; import hello.hellospring.repository.MemberRepository; import hello.hellospring.repository.MemoryMemberRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; import java.util.Optional; //์–ด๋…ธํ…Œ์ด์…˜ ๋“ฑ๋ก์„ ์•ˆํ•˜๋ฉด ๊ทธ์ € ์ˆœ์ˆ˜ ์ž๋ฐ”์ผ๋ฟ... //@Service public c.. 2023. 7. 4.
Spring - ํšŒ์›๊ด€๋ฆฌ์˜ˆ์ œ (ํšŒ์› ๋„๋ฉ”์ธ๊ณผ ๋ ˆํฌ์ง€ํ† ๋ฆฌ) ํšŒ์› ๊ฐ์ฒด (./domain/Member.java) package hello.hellospring.domain; public class Member { private Long id; private String name; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } } ํšŒ์› ๋ฆฌํฌ์ง€ํ† ๋ฆฌ ์ธํ„ฐํŽ˜์ด์Šค (./repository/MemberRopository.java) package hello.hellospring.repository; import .. 2023. 7. 4.
Spring - ์›น๊ฐœ๋ฐœ๊ธฐ์ดˆ 1. ์ •์  ์ปจํ…์ธ  controller๋กœ ๋”ฐ๋กœ ์ฃผ์†Œ๊ฐ’์„ ๋งคํ•‘ํ•ด์ฃผ์ง€ ์•Š์•„๋„, staticํด๋”์— a.html๋กœ ์ €์žฅ์„ ํ–ˆ๋‹ค๋ฉด, /a ์ฃผ์†Œ๋ฅผ ์ณค์„๋•Œ ํ•ด๋‹น html์ด ๋œจ๊ฒŒ ๋œ๋‹ค. 2. MVC์™€ ํ…œํ”Œ๋ฆฟ ์—”์ง„ MVC: Model, View, Controller view๋Š” ๋ˆˆ์— ๋ณด์ด๋Š”๊ฒƒ๋งŒ ๊ด€๋ฆฌํ•œ๋‹ค. html์— ๊ฐ’์„ ๋„˜๊ธธ๋•Œ ์‚ฌ์šฉ 3. API ์„œ๋ฒ„์™€ ์•ฑ(์•ˆ๋“œ๋กœ์ด๋“œ, ios)์™€ ๋ฐ์ดํ„ฐ๋ฅผ ์ฃผ๊ณ  ๋ฐ›์„๋•Œ ์„œ๋ฒ„์™€ ์„œ๋ฒ„๋ผ๋ฆฌ ๋ฐ์ดํ„ฐ๋ฅผ ์ฃผ๊ณ  ๋ฐ›์„๋•Œ @ResponseBody ๋ฅผ ์‚ฌ์šฉ -> json ํ˜•์‹์œผ๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ˜ํ™˜ HTTP์˜ BODY์— ๋ฌธ์ž ๋‚ด์šฉ์„ ์ง์ ‘ ๋ฐ˜ํ™˜(์‘๋‹ต) -> html์„ ๊ฑฐ์น˜์ง€ ์•Š์Œ viewResolver ๋Œ€์‹ ์— HttpMessageConverter ๊ฐ€ ๋™์ž‘ ๊ธฐ๋ณธ ๋ฌธ์ž์ฒ˜๋ฆฌ: StringHttpMessageConverter.. 2023. 7. 3.
[intellij]๊ธฐ์–ตํ•˜๊ณ  ์‹ถ์€ ๋‹จ์ถ•ํ‚ค (Mac) ๐Ÿ’ก ์ž๋™ ์ž„ํฌํŠธ(Auto Import) : Opt+Enter ๐Ÿ’ก ํ€ต ํ”ฝ์Šค ์ œ์•ˆ : Opt+Enter ๐Ÿ’ก ์ž๋™์œผ๋กœ ๋’ท๋ฌธ์žฅ ์™„์„ฑ ์‹œํ‚ค๊ณ  ๋‹ค์Œ์ค„๋กœ ๋„˜์–ด๊ฐ€๊ธฐ : Command+Shift+Enter ๐Ÿ’ก ๋ณต๋ถ™ํ•˜๊ณ  ์‹ถ์€ ๋ถ€๋ถ„ ๋“œ๋ž˜๊ทธํ•ด์„œ ๊ทธ ๋ฐ‘์— ๋˜‘๊ฐ™์ด ๋ณต๋ถ™ํ•˜๊ธฐ : command + D ๐Ÿ’ก ํ•จ์ˆ˜๋กœ ๋งŒ๋“ค๊ณ  ์‹ถ์€๋ถ€๋ถ„ ๋“œ๋ž˜๊ทธํ•ด์„œ ํ•จ์ˆ˜๋กœ ์ถ”์ถœํ•˜๊ธฐ : ^ + T ํ•˜๊ณ  Extract method์„ ํƒ ๐Ÿ’ก ํŒŒ๋ผ๋ฏธํ„ฐ ์ •๋ณด ๋ณด๊ธฐ : command + P ๐Ÿ’ก Generate : command + N (aka.getter and setter ๋‹จ์ถ•ํ‚ค, ์ƒ์„ฑ์ž ์ƒ์„ฑ, toString() ์ƒ์„ฑ) ๐Ÿ’ก inline Variable : command + option + N (aka.๋ฐ˜ํ™˜ํ•  ๋ณ€์ˆ˜์— ๋‘๊ณ  ๋ˆ„๋ฅด๋ฉด Return์— ํ•œ์ค„๋กœ ๋งŒ๋“ค์–ด์คŒ) ๐Ÿ’ก ๋ณ€์ˆ˜ .. 2023. 7. 3.
Spring - ๋นŒ๋“œํ•˜๊ณ  ์‹คํ–‰ํ•˜๊ธฐ ํ„ฐ๋ฏธ๋„๋กœ ์ด๋™ 1. ./gradlew build 2. cd build/libs 3. java -jar hello-spring-0.0.1-SNAPSHOT.jar 4. ์‹คํ–‰ ํ™•์ธ 2023. 7. 3.