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

BE/๐Ÿƒ Spring6

[Spring Boot] Controller์™€ RestController ์ฐจ์ด์™€ ResponseBody @Controller Vs. @RestControllerRestController๋Š” Spring Boot 4.0 ๋ถ€ํ„ฐ Restful ์„œ๋น„์Šค ๊ฐœ๋ฐœ์„ ์œ„ํ•ด ์ถ”๊ฐ€๋จRestController๋Š” Controller + ResponseBody ์ฆ‰, Controller์ž„์„ ์˜๋ฏธํ•˜๋ฉด์„œ ResponseBody์ธ RestApi์ž„์„ ์˜๋ฏธํ•œ๋‹ค @Controller@RestController์‚ฌ์šฉํ•˜๋Š” ๊ณณWeb Application ๊ฐœ๋ฐœ์— ์‚ฌ์šฉ๋จRestful Web Service ๊ฐœ๋ฐœ์— ์‚ฌ์šฉ๋จ๋ฐ˜ํ™˜ ํƒ€์ž…html๊ณผ ๊ฐ™์€ View๋ฅผ ๋ฐ˜ํ™˜json, XML๊ณผ ๊ฐ™์€ Response ๋ฐ˜ํ™˜ @Target({ElementType.TYPE})@Retention(RetentionPolicy.RUNTIME)@Documented@Controller@Re.. 2024. 9. 22.
Spring boot ํ”„๋กœ์ ํŠธ์— SSL ์ธ์ฆ์„œ ์ ์šฉํ•˜๊ธฐ ํ•ด๋‹น ํฌ์ŠคํŒ…์€ ์‚ฌ์„ค ์ธ์ฆ SSL ์ ์šฉ์ž…๋‹ˆ๋‹ค. ์ž์ฒด ์„œ๋ช… SSL์€ ๋‹ค๋ฅธ ๊ธ€์„ ์ฐธ๊ณ ํ•˜์„ธ์š”! ๐Ÿ™‡ ์ €์˜ ๊ฒฝ์šฐ ์—ฌ๋Ÿฌ ์ฒจ๋ถ€ ํŒŒ์ผ์„ ์ œ๊ณต ๋ฐ›์•˜๋Š”๋ฐ ํŒŒ์ผ ์ด๋ฆ„์€ ๋‹ฌ๋ผ๋„ ์•„๋ž˜์™€ ๊ฐ™์€ ๊ตฌ์„ฑ์œผ๋กœ ๋˜์–ด ์žˆ์„ ๊ฑฐ์—์š”!.crt.pem์„œ๋ฒ„ ์ธ์ฆ์„œ PEM .key.pem๊ฐœ์ธํ‚ค PEM (์ด๋ฏธ .jks๋ฅผ ํŒŒ์ผ์ด ํฌํ•จ๋˜์–ด ์žˆ๋Š” ๊ฒฝ์šฐ๋„ ์žˆ์œผ๋‹ˆ ํ™•์ธํ•ด๋ณด์„ธ์š”! ์ด๋ฏธ .jks๊ฐ€ ์žˆ๋‹ค๋ฉด jks ๋งŒ๋“œ๋Š” ๊ณผ์ •์€ ๊ฑด๋„ˆ ๋›ฐ์–ด๋„ ๋ฉ๋‹ˆ๋‹ค!) ์ด ๋‘๊ฐ€์ง€๋ฅผ ์‚ฌ์šฉํ•ด์„œ .p12๋ฅผ ๋งŒ๋“ค๊ณ  .p12๋ฅผ .jks๋กœ ๋ณ€๊ฒฝํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.  openssl pkcs12 -export -in [์„œ๋ฒ„์ธ์ฆ์„œ.pem] -inkey [๊ฐœ์ธํ‚ค.pem] -out [์ƒ์„ฑํ•  ํŒŒ์ผ์ด๋ฆ„.p12] -name [alias ์ด๋ฆ„] Enter Export Password:Verifying - Enter E.. 2024. 7. 15.
[Spring Boot JPA ๊ฒŒ์‹œํŒ ๋งŒ๋“ค๊ธฐ] 3. Entity ์ƒ์„ฑ ๊ฐ„๋‹จํ•œ ๊ฒŒ์‹œํŒ์„ ๋งŒ๋“ค๊ธฐ ์œ„ํ•ด์„œ Board๋ผ๋Š” Entity ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค์–ด ์ฃผ๊ฒ ์Šต๋‹ˆ๋‹ค. JPA๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์˜ ๊ตฌ์กฐ๋ฅผ ์ž๋ฐ”์˜ ํด๋ž˜์Šค๋กœ ํ‘œํ˜„ํ•ด ์ค„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋ฅผ ORM์ด๋ผ๊ณ  ํ•˜๋Š”๋ฐ, ORM์€ Object Relational Mapping์˜ ์•ฝ์ž์ž…๋‹ˆ๋‹ค. ์ž๋ฐ”์˜ ๊ฐ์ฒด์™€ ๊ด€๊ณ„ํ˜• ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ๋งคํ•‘ํ•˜๋Š” ๊ธฐ์ˆ ์„ ๋งํ•ฉ๋‹ˆ๋‹ค. JPA๋Š” ORM์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.   ๊ณตํ†ต์œผ๋กœ ์‚ฌ์šฉํ•˜๋Š” Entity ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์„ค๊ณ„๋ฅผ ํ•˜๋‹ค๋ณด๋ฉด ๊ณตํ†ต์ ์œผ๋กœ ์ž์ฃผ ์‚ฌ์šฉํ•˜๋Š” ์ปฌ๋Ÿผ๋“ค์ด ์žˆ์Šต๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด ์ƒ์„ฑ์ผ๊ณผ ์ˆ˜์ •์ผ ๋“ฑ์ด ์žˆ์Šต๋‹ˆ๋‹ค. ํด๋ž˜์Šค ์ •์˜ํ•  ๋•Œ ๋งˆ๋‹ค ๋งค๋ฒˆ ์ •์˜ ํ•˜์ง€ ์•Š๊ณ  ๊ณตํ†ต Entity ํด๋ž˜์Šค๋กœ ๋งŒ๋“ค์–ด ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์–ด์š”. ๋จผ์ € BaseTime์ด๋ผ๋Š” ํด๋ž˜์Šค๋ฅผ ์ƒ์„ฑํ•ด ๋ด…์‹œ๋‹ค! import lombok... 2024. 5. 8.
[Spring Boot JPA ๊ฒŒ์‹œํŒ ๋งŒ๋“ค๊ธฐ] 2. ํ”„๋กœ์ ํŠธ ๊ตฌ์กฐ ์„ค์ • Controller MVC์˜ Controller์„œ๋น„์Šค ๊ณ„์ธต์„ ํ˜ธ์ถœํ•˜๊ณ  ๊ฒฐ๊ณผ๋ฅผ ๋ทฐ์— ์ „๋‹ฌํ•จ๋ฐ์ดํ„ฐ ๊ฒ€์ฆ(๋ฒจ๋ฆฌ๋ฐ์ด์…˜)์„ ์ˆ˜ํ–‰ํ•œ๋‹คํ”„๋กœ์  ํ…Œ์ด์…˜ ๋ ˆ์ด์–ด๋กœ์„œ ์›น ์š”์ฒญ๊ณผ ์‘๋‹ต์„ ์ฒ˜๋ฆฌํ•œ๋‹ค๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง์ด ๊ตฌํ˜„๋˜๋Š” ๊ณณ์ด ์•„๋‹ˆ๋‹ค! Request์™€ Response๋ฅผ ๋‹ด๋‹นํ•œ๋‹คurl์— ๋”ฐ๋ผ ์ ์ ˆํ•œ View์™€ mapping์„ ์ฒ˜๋ฆฌ@Autowired, @Service๋ฅผ ์‚ฌ์šฉํ•ด service์˜ ๋ฉ”์†Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค@Controller@RequestMapping("/board")public class BoardController { @Autowired private BoardService boardService;}   Service๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง์ด ํฌํ•จ๋˜๋ฉฐ ํŠธ๋žœ์žญ์…˜์„ ์‹œ์ž‘ ํ•˜๋Š” ๊ณณ์ด๋‹ค๋ฐ์ดํ„ฐ ์ ‘๊ทผ ๊ณ„์ธต์ธ Repository๋ฅผ ํ˜ธ์ถœํ•œ๋‹ค.. 2024. 4. 29.
IntelliJ ๋ฌด๋ฃŒ ๋ฒ„์ „์œผ๋กœ ์Šคํ”„๋ง ๋ถ€ํŠธ ํ”„๋กœ์ ํŠธ ๋งŒ๋“ค๊ธฐ ํ•ด๋‹น ํฌ์ŠคํŒ…์€ ๋„์„œ [์Šคํ”„๋ง ๋ถ€ํŠธ 3 ๋ฐฑ์—”๋“œ ๊ฐœ๋ฐœ์ž ๋˜๊ธฐ ์ž๋ฐ”ํŽธ]๋ฅผ ์ฐธ๊ณ ํ•ด์„œ ์ž‘์„ฑ๋˜์—ˆ์Šต๋‹ˆ๋‹ค! ์‚ฌ์ง„์˜ UI๋Š” ์œ ๋ฃŒ ๋ฒ„์ „์˜ ์ธํ…”๋ฆฌ์ œ์ด๋ผ์„œ ๋ฌด๋ฃŒ ๋ฒ„์ „์˜ UI์™€ ์ฐจ์ด๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. Java ํ”„๋กœ์ ํŠธ๋ฅผ ๋ˆŒ๋Ÿฌ์ฃผ๊ณ  ํ”„๋กœ์ ํŠธ ์ด๋ฆ„์„ค์ •, ๋นŒ๋“œ ์‹œ์Šคํ…œ์„ Gradle, Gradle DSL์€ Groovy, GroupId ์ง€์ • ํ•ด์ค๋‹ˆ๋‹ค. (์—ฌ๋‹ด์ด์ง€๋งŒ ์ธํ…”๋ฆฌ์ œ์ด ์œ ๋ฃŒ๋ฒ„์ „ ์กฐ์•„์š”...ํ•œ๋ฒˆ ๋ง›๋“ค๋ฆฌ๋‹ˆ ๋Œ์•„๊ฐˆ ์ˆ˜๊ฐ€ ์—†๋ ) build.gradle ํŒŒ์ผ๋กœ ์ด๋™ plugins { id 'java' id 'org.springframework.boot' version '3.2.0' // ์ถ”๊ฐ€ id 'io.spring.dependency-management' version '1.1.0' // ์ถ”๊ฐ€ } group = 'org.youable' vers.. 2024. 4. 18.
[Spring Boot JPA ๊ฒŒ์‹œํŒ ๋งŒ๋“ค๊ธฐ] 1. ํ™˜๊ฒฝ์„ค์ • Intro Spring Boot์™€ JPA๋ฅผ ํ™œ์šฉํ•ด์„œ ๊ฐ„๋‹จํ•œ ๊ฒŒ์‹œํŒ ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ๊ธ€์€ ์‹œ๋ฆฌ์ฆˆ๋กœ ์ž‘์„ฑ๋  ์˜ˆ์ •์ด๋ฉฐ ํ˜„์žฌ ๊ธ€์—์„œ๋Š” ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ, build.gradle๊ณผ dependencies, applicaiton.yaml ํŒŒ์ผ ์„ค์ •์— ๋Œ€ํ•ด ์•Œ์•„๋ณผ๊ฒŒ์š”. - IDE : IntelliJ - java version : 17 ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ ์ผ์ผ์ด ์ˆ˜๋™์œผ๋กœ Spring ํ”„๋กœ์ ํŠธ๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ์„ค์ •ํ•˜๋Š” ๊ฒƒ์€ ์‰ฝ์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— IntelliJ์™€ Spring Initializer๋ฅผ ์‚ฌ์šฉํ•ด์„œ Spring Boot ํ”„๋กœ์ ํŠธ๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์•Œ์•„๋ด…์‹œ๋‹ค! IntelliJ IDEA ์‚ฌ์šฉ ์ธํ…”๋ฆฌ ์ œ์ด ์œ ๋ฃŒ ๋ฒ„์ „(IntelliJ IDEA)์„ ์‚ฌ์šฉํ•˜์‹ ๋‹ค๋ฉด ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ ์‹œ Spring Boot Generators๋ฅผ ์‚ฌ์šฉํ•  .. 2024. 4. 18.