์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- ๊ณ์ฐ๊ธฐ๋ง๋ค๊ธฐ
- CSS
- HTML
- ์ธํ ๋ฆฌ์ ์ด
- fibonacci
- ๊นํ๋ธ
- spring data jpa
- ์ปฌ๋ ์ ํ๋ ์์ํฌ
- ์๋ฃ๊ตฌ์กฐ
- ์คํ๋ง
- ๋ฐ์ผ๋ฆฌ์ฝ๋ฉ
- testing
- ๊ฑฐ๋ญ์ ๊ณฑ
- ํ์ดํ๋ก๊ทธ๋๋ฐ
- FilterChain
- ์๋ฐ
- ์ ๋ค๋ฆญ์ค
- ๊ทธ๋ฆฌ๋
- CLI๋ช ๋ น์ด
- ์๊ณ ๋ฆฌ์ฆ
- ๋ฐฑ์๋
- ํ๊ณ
- Spring Security
- Publishing
- java
- ์ฒซ๊ธ์๋๋ฌธ์
- ๋ฐฑ์ค์๊ณ ๋ฆฌ์ฆ
- ๋ถํธ์บ ํ
- Spring Data JDBC
- ๋ฌธ์์ด๋ค์ง๊ธฐ
- Today
- Total
๋ชฉ๋ก์ ์ฒด ๊ธ (69)
๋์ ๋ชจ์
โ๏ธ Description Return power input two numbers input base: int (base >= 2) exponent: int (exponent >= 0) output return long return rest of divided by 94,906,249 of the actual calculation results caution Avoid using Math.pow, power operators Time Complexity O(logN) example of in/output ong output = power(3, 40); System.out.println(output); // --> 19334827 ๐ TIL Power: Multiply the same number mult..

๐Checked Exception ์์ธ๋ฅผ ์ก์์(catch) ์ฒดํฌํ ํ ๋ฐ๋์ ์๋ฌ์ฒ๋ฆฌ(try~catch)๋ฅผ ํด์ผํ๋ ์์ธ์ด๋ค. Exception ํด๋์ค์ ํ์ ํด๋์ค (Exception ์์๋ฐ์) ClassNotFoundException, FileNotFoundException, SQLException, … ๐Unchecked Exception ์์ธ๋ฅผ ์ก์์(catch) ํด๋น ์์ธ์ ๋ํ ์ฒ๋ฆฌ(try~catch)๋ฅผ ํ ํ์๊ฐ ์๋ ์์ธ์ด๋ค. RuntimeException์ ํ์ ํด๋์ค (RuntimeException ์์๋ฐ์) ์ฃผ๋ก ๊ฐ๋ฐ์๊ฐ ์ฝ๋๋ฅผ ์๋ชป ์์ฑํด์ ๋ฐ์ํ๋ ์ค๋ฅ๋ค์ ๋ชจ๋ RuntimeException์ ์์ํ ์์ธ๋ค์ด๋ค. NullPointException, ArrayIndexOutOfBo..
โ๏ธ Description Return whether the sample is a subset of the base by receiving two arrays input base: temporary Array with element of int sample: temporary Array with element of int output: boolean caution: no duplicates example of in/output int[] base = new int[]{1, 2, 3, 4, 5}; int[] sample = new int[]{1, 3}; boolean output = isSubsetOf(base, sample); System.out.println(output); // --> true sam..
๐ @ExceptionHandler๋ฅผ ์ด์ฉํ ์์ธ ์ฒ๋ฆฌ Controller ํด๋์ค ๋ ๋ฒจ์์ @ExceptionHandler๋ฅผ ์ฌ์ฉํ๋ฉด ํด๋น Controller์์ ๋ฐ์ํ๋ ์์ธ๋ฅผ ์ฒ๋ฆฌํ ์ ์๋ค. ํ์ํ ์์ธ ์ ๋ณด๋ง ๋ด์ ์ ์๋ Error ์ ์ฉ Response ๊ฐ์ฒด๋ฅผ ์ฌ์ฉํ๋ฉด ํด๋ผ์ด์ธํธ์๊ฒ ์กฐ๊ธ ๋ ์น์ ํ ์๋ฌ ์ ๋ณด๋ฅผ ์ ๊ณตํ ์ ์๋ค. BUT! @ExceptionHandler ๋ฐฉ์์ Controller๋ง๋ค ๋์ผํ๊ฒ ๋ฐ์ํ๋ ์์ธ ์ฒ๋ฆฌ์ ๋ํ ์ค๋ณต ์ฝ๋๊ฐ ๋ฐ์ํ ์ ์๊ธฐ ๋๋ฌธ์ ๋ค์ํ ์ ํ์ ์์ธ๋ฅผ ์ฒ๋ฆฌํ๊ธฐ์๋ ์ ์ ํ์ง ์๋ค. โ Ref. @ExceptionHandler https://docs.spring.io/spring-framework/docs/current/reference/html/web.htm..

๐ DI๋ฅผ ํตํ ์๋น์ค ๊ณ์ธต ←→ API ๊ณ์ธต ์ฐ๋ ์ ํ๋ฆฌ์ผ์ด์ ์์ Service: ๋๋ฉ์ธ ์ ๋ฌด ์์ญ์ ๊ตฌํํ๋ ๋น์ฆ๋์ค ๋ก์ง์ ์ฒ๋ฆฌํ๋ ๊ฒ์ด๋ค. ์ ํ๋ฆฌ์ผ์ด์ ์ ๋น์ฆ๋์ค ๋ก์ง์ ์ฒ๋ฆฌํ๊ธฐ ์ํ ์๋น์ค ๊ณ์ธต์ ๋๋ถ๋ถ ๋๋ฉ์ธ ๋ชจ๋ธ์ ํฌํจํ๊ณ ์๋ค. Spring Bean์ผ๋ก ๋ฑ๋ก Controller ํด๋์ค์ @RestController ์ถ๊ฐ Service ํด๋์ค์ @Service ์ถ๊ฐ ์์ฑ์ ๋ฐฉ์์ DI๋ ์์ฑ์๊ฐ ํ๋์ผ ๊ฒฝ์ฐ์๋ @Autowired ์ ๋ํ ์ด์ ์ ์ถ๊ฐํ์ง ์์๋ DI๊ฐ ์ ์ฉ๋๋ค. ์๋น์ค ๊ณ์ธต๊ณผ API ๊ณ์ธต์ ์ฐ๊ฒฐํ๋ค๋ ๊ฒ์ API ๊ณ์ธต์์ ๊ตฌํํ Controller ํด๋์ค๊ฐ ์๋น์ค ๊ณ์ธต์ Service ํด๋์ค์ ๋ฉ์๋ ํธ์ถ์ ํตํด ์ํธ์์ฉํ๋ ๊ฒ์ด๋ค. ๐ ๋งคํผ(Mapper)๋ฅผ ์ด์ฉํ DTO ํด๋..
๐DTO ์ ํจ์ฑ ๊ฒ์ฆ์ด ํ์ํ ์ด์ ์๋ฐ์คํฌ๋ฆฝํธ๋ก ์ ์ก๋๋ ๋ฐ์ดํฐ๋ ๋ธ๋ผ์ฐ์ ์ ๊ฐ๋ฐ์ ๋๊ตฌ์์ ๊ฐ์ ์กฐ์ํ ์ ์๊ธฐ ๋๋ฌธ์ ํ๋ก ํธ์๋ ์ชฝ์์ ์ ํจ์ฑ ๊ฒ์ฌ๋ฅผ ์งํํ๋ค๊ณ ํ๋๋ผ๋ ์๋ฒ ์ชฝ์์ ํ๋ฒ ๋ ์ ํจ์ฑ ๊ฒ์ฌ๋ฅผ ์งํํด์ผ ํ๋ค. ํ๋ก ํธ์๋ ์ชฝ์์ ์งํํ๋ ์ ํจ์ฑ ๊ฒ์ฆ ํ๋ก์ธ์ค๋ ์ฌ์ฉ์ ํธ์์ฑ ์ธก๋ฉด์์ ํ์ํ ์์ ์ด๋ค. ๐DTO ํด๋์ค์ ์ ํจ์ฑ ๊ฒ์ฆ ์ ์ฉํ๊ธฐ ๐งฉ ์ ํจ์ฑ ๊ฒ์ฆ์ ์ํ ์์กด ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ถ๊ฐ dependencies { implementation 'org.springframework.boot:spring-boot-starter-validation:2.7.3' } ๐@PathVariable ์ ํจ์ฑ ๊ฒ์ฆ @PathVariable์์ ์ ํจ์ฑ ๊ฒ์ฆ์ ํ๋ ค๋ฉด ํด๋์ค์ @Validated์ ๋ถ์ฌ์ค์ผ ํ๋ค. ์..
๐ DTO(Data Trasfer Object) ๋งํด ํ์ธ๋ฌ(Martin Fowler)๊ฐ ‘Patterns of Enterprise Application Architecture’ ๋ผ๋ ์ฑ ์์ ์ฒ์ ์๊ฐํ ์ํฐํ๋ผ์ด์ฆ ์ ํ๋ฆฌ์ผ์ด์ ์ํคํ ์ฒ ํจํด์ ํ๋์ด๋ค. ๋ฐ์ดํฐ๋ฅผ ์ ์กํ๊ธฐ ์ํ ๊ฐ์ฒด ์ฃผ๋ก ํด๋ผ์ด์ธํธ์์ ์๋ฒ ์ชฝ์ผ๋ก ์ ์กํ๋ ์์ฒญ ๋ฐ์ดํฐ๋ฅผ ์ ๋ฌ ๋ฐ์ ๋, ์๋ฒ์์ ํด๋ผ์ด์ธํธ ์ชฝ์ผ๋ก ์ ์กํ๋ ์๋ต ๋ฐ์ดํฐ๋ฅผ ์ ์กํ๊ธฐ ์ํ ์ฉ๋๋ก ์ฌ์ฉ๋๋ค. ๋ฐ์ดํฐ ์ ์ก์ด ์ด๋ฃจ์ด์ง๋ ๊ตฌ๊ฐ ํด๋ผ์ด์ธํธ → ์๋ฒ: ์์ฒญ(request) ๋ฐ์ดํฐ ์๋ฒ → ํด๋ผ์ด์ธํธ: ์๋ต(response) ๋ฐ์ดํฐ DTO ํด๋์ค: ์์ฒญ ๋ฐ์ดํฐ๋ฅผ ํ๋์ ๊ฐ์ฒด๋ก ์ ๋ฌ ๋ฐ๋ ์ญํ ๐ DTO๊ฐ ํ์ํ ์ด์ ํด๋ผ์ด์ธํธ์ Request Body๋ฅผ ํ๋์ ๊ฐ์ฒด๋ก ๋ชจ๋..

โ๏ธ Description ์ ์๋ฅผ ์์๋ก ๊ฐ๋ ๋ฐฐ์ด์ ์ ๋ ฅ๋ฐ์ 3๊ฐ์ ์์๋ฅผ ๊ณฑํด ๋์ฌ ์ ์๋ ์ต๋๊ฐ ๋ฆฌํด ์ ๋ ฅ: int[] ํ์ ์ ์์๋ก ๊ฐ๋ ์์์ ๋ฐฐ์ด ์ถ๋ ฅ: int ์ฃผ์์ฌํญ ์ฃผ์ด์ง ๋ฐฐ์ด์ ์ค์ฒฉ๋์ง ์์ 1์ฐจ์ ๋ฐฐ์ด ๋ฐฐ์ด ์์๋ ์์์ 0์ ํฌํจํ๋ ์ ์ ๋ฐฐ์ด ๊ธธ์ด๋ 3 ์ด์ ์ ์ถ๋ ฅ ์์ int output = largestProductOfThree(new int[]{2, 1, 3, 7}); // --> 42 (= 2 * 3 * 7) output = largestProductOfThree(new int[]{-1, 2, -5, 7}); // --> 35 (= -1 * -5 * 7) ๐ Flow - ๊ฐ์ฅ ํฐ ์๋ฅผ ๊ณฑํ๊ธฐ => ์ค๋ฆ์ฐจ์ ์ ๋ ฌํด์ ๋งจ ๋ค์ ์ธ ๊ฐ ๊ณฑํด์ค - ๋ฐฐ์ด์ ์์ ์์ ๋ => ํฐ ..