user-img
๋ฐฑ์—”๋“œ ๊ฐœ๋ฐœ 69
Api Test build ์ฝ”๋“œ ๋ถ„์„
class MemoryMemberRepositoryTest { MemoryMemberRepository repository = new MemoryMemberRepository(); @AfterEach // ๊ฐ ํ•จ์ˆ˜ ๋๋‚  ๋•Œ ๋งˆ๋‹ค ์‹คํ–‰ํ•˜๋ผ public void afterEach() { repository.clearStore(); // repository ํŒจํ‚ค์ง€์— ์žˆ๋Š” clearStore ๋งค์†Œ๋“œ ์ด์šฉํ•ด๋ผ // clearStore()๋Š” Store ๋‚ด์˜ key-value ์Œ๋“ค์„ ์ง€์šฐ๋Š” ๋งค์†Œ๋“œ } @Test public void save() { Member member = new Member(); member.setName("spring"); repository.save(member); Member result ..
2022.11.30
๋ฐฑ์—”๋“œ ๊ฐœ๋ฐœ/SpringMVC
ํšŒ์› ๋„๋ฉ”์ธ๊ณผ ๋ ˆํฌ์ง€ํ† ๋ฆฌ ๋งŒ๋“ค๊ธฐ
1. Member Class //Member class ๋งŒ๋“ค๊ธฐ package hello.hellospring.domain; public class Member { private Long id; private String name; public Long getId()//ID ์กฐํšŒ { return id; } public void setId(Long id) //id ์„ค์ •(์ธ์ˆ˜๋กœ ๋“ค์–ด์˜จ ์‹ค์ˆ˜๊ฐ€ ํ•ด๋‹น ๊ฐ์ฒด์˜ id) { this.id = id; } public String getName()//Name ์กฐํšŒ { return name; } public String setName(String name)//Name ์„ค์ •(์ธ์ˆ˜๋กœ ๋“ค์–ด์˜จ String์ด ํ•ด๋‹น ๊ฐ์ฒด์˜ name ) { this.name = name; } } // ..
2022.11.29
๋ฐฑ์—”๋“œ ๊ฐœ๋ฐœ/SpringMVC
thumbnail
Web ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ณ„์ธต ๊ตฌ์กฐ
1. ์ปจํŠธ๋กค๋Ÿฌ: ํด๋ผ์ด์–ธํŠธ์˜ ์š”์ฒญ์„ ์–ด๋–ป๊ฒŒ ์ฒ˜๋ฆฌํ• ์ง€ ์ •์˜๋˜์–ด ์žˆ๋Š” ๊ณณ. 2. ์„œ๋น„์Šค: ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง์ด ๊ตฌํ˜„๋˜์–ด ์žˆ๋Š” ๊ณณ (ex- ID ์ค‘๋ณต์€ ๋ถˆ๊ฐ€ ํ•˜๋„๋ก, ํ•˜๋ฃจ 300๋งŒ์› ์ด์ƒ ์ด์ฒด๋Š” ๋ถˆ๊ฐ€๋Šฅ ํ•˜๋„๋ก) DB์˜์—ญ๊ณผ ๋„๋ฉ”์ธ ์˜์—ญ ์—ฐ๊ฒฐํ•ด์ฃผ๋Š” ๋งค๊ฐœ์ฒด ์—ญํ•  3. Repository: Domain ์˜์—ญ์—์„œ ๋ฐ›์•„์˜จ ๊ฐ์ฒด๋“ค์„ DB์— ์ €์žฅํ•˜๊ณ  ๊ด€๋ฆฌ (Domain์— ๋Œ€ํ•œ CRUD ์—ญํ• ) 4. Domain: DB ํ…Œ์ด๋ธ”๊ณผ 1๋Œ€1 ๋Œ€์‘(mapping)๋˜๋Š” ๊ฐ์ฒด (getter-์กฐํšŒ, setter-์„ค์ • ๋ฉ”์†Œ๋“œ๋ฅผ ๊ฐ€์ง„๋‹ค.) ์™ธ์šด ๊ฑฐ ํ™•์ธ ๊ทธ๋ฆผ ๋ณด๊ณ  ๊ฐ ๊ฐœ์ฒด๋“ค ์„ค๋ช…
2022.11.29
๋ฐฑ์—”๋“œ ๊ฐœ๋ฐœ/SpringMVC
thumbnail
Spring ์›น ๊ฐœ๋ฐœ ๊ธฐ์ดˆ - API
1. api ๋ž€? ํ•œ ์†Œํ”„ํŠธ์›จ์–ด์—์„œ ๋‹ค๋ฅธ ์†Œํ”„ํŠธ์›จ์–ด๋กœ ์š”์ฒญ์„ ๋ณด๋‚ด๊ฑฐ๋‚˜ ๋ฐ›์„ ์ˆ˜ ์žˆ๋Š” ์ˆ˜๋‹จ. 2. ์ฝ”๋“œ๋ถ„์„ (1) @ResponseBody์— ๋Œ€ํ•œ ์„ค๋ช… @GetMapping("hello-string") @ResponseBody //์ปจํŠธ๋กค๋Ÿฌ๊ฐ€ ๋ฐ˜ํ™˜ ๊ฐ’์„ http body๋ถ€์— ์ง์ ‘ ๋„ฃ์–ด์ฃผ๊ฒ ๋‹ค. public String helloString(@RequestParam("name") String name) { return "hello " + name; /* para์— spring์„ ๋„ฃ์œผ๋ฉด hello spring์ด ๋  ๊ฒƒ์ž„. ์—ฌ๊ธฐ์„  view์ด๋Ÿฐ ๊ฑธ๋กœ ๊ทธ์— ๋งž๋Š” template ์ฐพ์•„ ๊ฐ’ ๋„ฃ๋Š” ๊ณผ์ • ์—†์ด ๋ฐ์ดํ„ฐ๊ฐ€ ๊ทธ๋Œ€๋กœ ์›น ๋ธŒ๋ผ์šฐ์ €์— ๋“ค์–ด๊ฐ. ๋ฐ์ดํ„ฐ ์›๋ณธ ๋ณด๊ธฐ๋ฅผ ํ•ด๋„ ์ฝ”๋“œ๊ฐ€ ์•ˆ ๋œจ๊ณ  ์šฐ๋ฆฌ๊ฐ€ ๋„ฃ์€ ์ŠคํŠธ๋ง์ด ๊ทธ๋Œ€๋กœ ๋œธ. *..
2022.11.29
๋ฐฑ์—”๋“œ ๊ฐœ๋ฐœ/SpringMVC
thumbnail
Spring Web ๊ฐœ๋ฐœ ๊ธฐ์ดˆ - MVC ์ž‘๋™์›๋ฆฌ
1.MVC๋ž€? -model view controller Controller๋Š” ์›๋ž˜ view์˜ ์ผ๋ถ€์˜€๋Š”๋ฐ, ๋„ˆ๋ฌด ๋‚ด์šฉ์ด ๋ณต์žกํ•ด์„œ ๋‘˜๋กœ ์ชผ๊ฐฐ๋‹ค. view == ํ™”๋ฉด์„ ๊ทธ๋ฆฌ๋Š” ๋ฐ ์ง‘์ค‘ํ•˜๋Š” part model, Controller == ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง์ด๋‚˜ ์š”์ฒญ ๋‚ด์šฉ ์ฒ˜๋ฆฌ์— ์ง‘์ค‘ํ•˜๋Š” part 2. ์ฝ”๋“œ ๋ถ„์„ @Controller public class HelloController { @GetMapping("hello") public String hello(Model model){ model.addAttribute("data","hello!!"); return "hello"; } // hello-mvc ์กฐํšŒ(GET)์— ๋Œ€๋น„ํ•œ mapping์„ ์ถ”๊ฐ€ @GetMapping("hello-mvc") public String ..
2022.11.29
๋ฐฑ์—”๋“œ ๊ฐœ๋ฐœ/SpringMVC
thumbnail
Spring Web ๊ฐœ๋ฐœ ๊ธฐ์ดˆ - ์ •์  ์ปจํ…์ธ  ์ž‘๋™์›๋ฆฌ
1.์ •์  ์ปจํ…์ธ ๋ž€? ํŒŒ์ผ,html์— ์ ํžŒ ๋‚ด์šฉ์„ ๊ทธ๋Œ€๋กœ ์›น์— ๋ฐ˜ํ™˜ ํ•˜๋Š” ๊ฒƒ. //resource์˜ static์— hello-static.html์ด๋ผ๋Š” ํŒŒ์ผ์„ ๋งŒ๋“ ๋‹ค. ๋ฐ‘์€ ํ•ด๋‹น ํŒŒ์ผ์˜ ๋‚ด์šฉ ์ •์  ์ปจํ…์ธ  ์ž…๋‹ˆ๋‹ค. 2. ์ž‘๋™์›๋ฆฌ 1) ์›น ๋ธŒ๋ผ์šฐ์ €๊ฐ€ localhost8080/hello_static.html GET(์กฐํšŒ) ์š”์ฒญ 2) ๋‚ด์žฅ ์›น ์„œ๋ฒ„์ธ tomcat์ด ํ•ด๋‹น ์š”์ฒญ ๋ฐ›์•„์„œ springboot์— ์ „๋‹ฌ 3) ์Šคํ”„๋ง๋ถ€ํŠธ๋Š” ํ•ด๋‹น ๋‚ด์šฉ๊ณผ ๋Œ€์‘(mapping ๋˜๋Š”)ํ•˜๋Š” ์ปจํŠธ๋กค๋Ÿฌ๊ฐ€ ์žˆ๋Š”์ง€ ์‚ดํŽด๋ด„. 4) ์—†์œผ๋ฉด resource/static์— ๋“ค์–ด๊ฐ€ ํ•ด๋‹น hello_static.html์ด๋ผ๋Š” ํŒŒ์ผ์ด ์žˆ๋‚˜ ์‚ดํŽด๋ด„ 5) ์žˆ๋‹ค๋Š” ๊ฑธ ํ™•์ธ ๊ทธ๋Œ€๋กœ ์›น์— ๋ฐ˜ํ™˜ (๋”ฐ๋กœ ๋ณ€ํ™˜ ๊ณผ์ •์„ ๊ฑฐ์น˜์ง€ ์•Š๋Š”๋‹ค.) 3. ์™ธ์šด ๊ฑฐ ํ™•์ธ ์ •์ ์ปจํ…์ธ ์˜ ..
2022.11.29
๋ฐฑ์—”๋“œ ๊ฐœ๋ฐœ/SpringMVC
์œˆ๋„์šฐ ๋ช…๋ น ํ”„๋กฌํ”„ํŠธ์—์„œ jar ํŒŒ์ผ Build ํ•˜๋Š” ๋ฒ•
1. ๋ช…๋ น ํ”„๋กฌํ”„ํŠธ ์ฐฝ์„ ๋„์šฐ๊ณ , IDE์—์„œ ๋งŒ๋“  java ํด๋ž˜์Šค๊ฐ€ ์žˆ๋Š” ํด๋”๋กœ ์ด๋™ํ•œ๋‹ค. A. ์œˆ๋„์šฐ์—์„œ ๋””๋ ‰ํ† ๋ฆฌ ์ด๋™: cd, ๋””๋ ‰ํ† ๋ฆฌ ๋‚ด์šฉ๋ฌผ ๋ณด๊ธฐ:dir 2. gradlew ํŒŒ์ผ์ด ์žˆ๋Š” ๊ฒƒ์„ ํ™•์ธํ•˜๊ณ  buildํ•œ๋‹ค. gradlew build A. ๊ทธ๋Ÿฌ๋ฉด ๋™ ๋””๋ ‰ํ† ๋ฆฌ ์•ˆ์— build ํด๋”๊ฐ€ ๋งŒ๋“ค์–ด ์กŒ์„ ๊ฒƒ์ด๋‹ค. B. Cd build/libs๋ฅผ ํ•œ๋‹ค. 3. Java -jar hello-spring-0.0.1-SNAPSHOT.jar ๋กœ ํ•ด๋‹น ํด๋”์˜ jar ํŒŒ์ผ ์‹คํ–‰ 4. ๋กœ์ปฌ ํ˜ธ์ŠคํŠธ ํƒ€๊ณ  ๋“ค์–ด๊ฐ€ ์‹คํ–‰๋œ ๊ฒƒ์„ ํ™•์ธ
2022.11.29
๋ฐฑ์—”๋“œ ๊ฐœ๋ฐœ/SpringMVC
thumbnail
Spring Boot - ๋™์ž‘ํ•˜๋Š” ํŽ˜์ด์ง€ ๋งŒ๋“ค๊ธฐ
1. ์›๋ฆฌ ์„ค๋ช… 1) ์›น ๋ธŒ๋ผ์šฐ์ €์—์„œ localhost:8080/hello๋ฅผ GET(์กฐํšŒ)ํ•œ๋‹ค. -(์›น ๋ธŒ๋ผ์šฐ์ €์— Http URL์„ ์น˜๋Š” ํ–‰์œ„ ์ž์ฒด๊ฐ€ GET ํ–‰์œ„์ด๋‹ค.) 2) ์Šคํ”„๋ง๋ถ€ํŠธ๊ฐ€ ๋‚ด์žฅํ•œ Tomcat์ด๋ž€ ์›น ์„œ๋ฒ„๊ฐ€ ์ด๊ฑธ ๋ฐ›์•„์„œ ์Šคํ”„๋ง๋ถ€ํŠธ์—๊ฒŒ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋Š”์ง€ ๋ฌผ์–ด๋ณธ๋‹ค. 3) ์Šคํ”„๋ง๋ถ€ํŠธ๋Š” helloController๊ฐ€ GetMapping("hello")๋ž€ ๊ฑธ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค๋Š” ๊ฑธ ํ™•์ธํ•˜๊ณ  ์—ฌ๊ธฐ์„œ ์ผ์„ ์ฒ˜๋ฆฌํ•˜๋„๋ก ์š”์ฒญ๊ณผ ๋งค์นญ ์‹œ์ผœ์ค€๋‹ค. -(GetMapping("hello") == ~URL/hello๋กœ ์กฐํšŒ ์š”์ฒญ์ด ๋“ค์–ด์˜ค๋ฉด ๋ฐ‘์— public ํ•จ์ˆ˜๋กœ ์š”์ฒญ์— ๋Œ€์‘ํ•˜๋ผ.) -(public ํ•จ์ˆ˜๋Š” model์ด๋ผ๋Š” ๊ฑธ ๊ฐ€์ง€๊ณ  ์žˆ์Œ -> model์€ attribute์™€ ๊ฐ attribute ๋ณ„ value๋ฅผ ๊ฐ€์ง.) ..
2022.11.28
๋ฐฑ์—”๋“œ ๊ฐœ๋ฐœ/SpringMVC
API์™€ REST_API์— ๋Œ€ํ•ด
*REST_API๋Š” ๋ฌด์—‡์ธ๊ฐ€? -> REST๋Š” ์ •๋ณด๋ฅผ ์ฃผ๊ณ ๋ฐ›๋Š”๋ฐ ์žˆ์–ด์„œ ๊ฐœ๋ฐœ์ž๋“ค์ด ๋„๋ฆฌ ์‚ฌ์šฉํ•˜๋Š” ํ•˜๋‚˜์˜ ‘ํ˜•์‹’์ด๋‹ค. -> ๋”ฐ๋ผ์„œ RESTAPI๋Š” REST๋ž€ ํ˜•์‹์˜ API์ด๋‹ค. 1. API๋ž€? ํ•œ Software๊ฐ€ ๋‹ค๋ฅธ Software๋กœ ์š”์ฒญ์„ ๋ณด๋‚ด๊ฑฐ๋‚˜ ๋ฐ›์„ ์ˆ˜ ์žˆ๊ฒŒ ํ•˜๋Š” ์ˆ˜๋‹จ Ex_ ์š”๋ฆฌ์‚ฌ(Database)์™€ ์†๋‹˜(Server) ์‚ฌ์ด์˜ ์ง์›์˜ ๊ด€๊ณ„ ์ง์›์€ ์†๋‹˜(server)์˜ ์ฃผ๋ฌธ(์š”์ฒญ or ๋ช…๋ น)์„ ๋ฐ›์•„ ์š”๋ฆฌ์‚ฌ(DB)์—๊ฒŒ ์ „๋‹ฌ ๋‹ค์‹œ ์š”๋ฆฌ(์š”์ฒญ์— ๋Œ€ํ•œ ๊ฐ’)๋ฅผ ์†๋‹˜์—๊ฒŒ ์ „๋‹ฌ 2. REST๋ž€ ํ˜•์‹์˜ API๋ž€ ๋ฌด์—‡์ธ๊ฐ€? (1) REST๋ž€ ํ˜•์‹์€ ๋ฌด์—‡์ธ๊ฐ€? REST๋ž€ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ํ˜•์‹์„ ๊ฐ€์ง„๋‹ค. a. ์ž์›์˜ ๋ช…์‹œ๋Š” HTTP URL์˜ ๊ทœ์•ฝ์„ ๋”ฐ๋ผ์„œ ํ‘œ์‹œํ•œ๋‹ค. b. CRUD ์ž‘์—…์€ HTTP_METHOD์ธ GET,..
2022.11.26
๋ฐฑ์—”๋“œ ๊ฐœ๋ฐœ/SpringMVC