|
2 | 2 |
|
3 | 3 |  |
4 | 4 |  |
| 5 | +[](https://jitpack.io/#CoffeeDrivenDevelopment/sangchu-common) |
5 | 6 |
|
| 7 | +해당 라이브러리는 `Sangchu` 프로젝트에서 사용하는 기본적인 기능들을 제공합니다. |
6 | 8 |
|
7 | | -## Dependency |
| 9 | +## Quick Starter |
8 | 10 |
|
9 | | -[Jitpack - Dependency]() |
10 | | - |
11 | | -### build.gradle |
| 11 | +### 1. Add Dependency |
12 | 12 |
|
13 | 13 | --- |
14 | 14 |
|
| 15 | +**build.gradle** |
| 16 | + |
15 | 17 | ```groovy |
16 | 18 | repositories { |
17 | 19 | mavenCentral() |
18 | 20 | maven { url 'https://jitpack.io' } |
19 | 21 | } |
20 | 22 |
|
21 | 23 | dependencies { |
22 | | - implementation 'com.github.CoffeeDrivenDevelopment:sangchu-common:Tag' |
| 24 | + implementation 'com.github.CoffeeDrivenDevelopment:sangchu-common:0.0.2' |
23 | 25 | } |
24 | 26 | ``` |
25 | 27 |
|
26 | | -### build.gradle.kts |
27 | | - |
28 | | ---- |
| 28 | +**build.gradle.kts** |
29 | 29 |
|
30 | 30 | ```kts |
31 | 31 | repositories { |
32 | 32 | mavenCentral() |
33 | | - maven('https://jitpack.io') |
| 33 | + maven("https://jitpack.io") |
34 | 34 | } |
35 | 35 |
|
36 | 36 | dependencies { |
37 | 37 | implementation("com.github.CoffeeDrivenDevelopment:sangchu-common:Tag") |
38 | 38 | } |
39 | 39 | ``` |
40 | 40 |
|
| 41 | +### 2. RestControllerAdvice |
| 42 | + |
| 43 | +--- |
| 44 | + |
| 45 | +공통으로 사용하는 에러 처리용 `RestControllerAdvice`입니다. |
| 46 | + |
| 47 | +**SangchuConfig.java** |
| 48 | + |
| 49 | +```java |
| 50 | + |
| 51 | +@Configuration |
| 52 | +public class SangchuConfig { |
| 53 | + @Bean |
| 54 | + public SangchuAdvice sangchuAdvice() { |
| 55 | + return new SangchuAdvice(); |
| 56 | + } |
| 57 | +} |
| 58 | +``` |
| 59 | + |
| 60 | +**SangchuConfig.kt** |
| 61 | + |
| 62 | +```kotlin |
| 63 | +@Configuration |
| 64 | +class SangchuConfig { |
| 65 | + @Bean |
| 66 | + fun sangchuAdvice(): SangchuAdvice { |
| 67 | + return SangchuAdvice() |
| 68 | + } |
| 69 | +} |
| 70 | +``` |
| 71 | + |
| 72 | +### 3. ResponseEntityFactory |
| 73 | + |
| 74 | +--- |
| 75 | + |
| 76 | +반복되는 `ResponseEntity<MessageBody<Void>>` 와 같은 클래스를 생성해주는 유틸입니다. |
| 77 | + |
| 78 | +예시는 아래와 같습니다. |
| 79 | + |
| 80 | +```java |
| 81 | + |
| 82 | +@GetMapping("/v1") |
| 83 | +public ResponseEntity<MessageBody<String>> get() { |
| 84 | + ResponseEntity<MessageBody<Passport>> response = ResponseEntityFactory.ok("Hello", "world!"); |
| 85 | + return response; |
| 86 | +} |
| 87 | +``` |
| 88 | + |
| 89 | +```kotlin |
| 90 | +@GetMapping("/v1") |
| 91 | +fun get(): ResponseEntity<MessageBody<String>> { |
| 92 | + val response: ResponseEntity<MessageBody<Passport>> = ResponseEntityFactory.ok( |
| 93 | + message = "Hello", |
| 94 | + body = "world!" |
| 95 | + ) |
| 96 | + return response |
| 97 | +} |
| 98 | +``` |
| 99 | + |
| 100 | +이 외에도 헤더를 추가하여 전송할 수 있는 `ResponseEntityFactoryWithHeaders`와 예외 처리를 담당하는 `ResponseEntityExceptionFactory`가 있습니다. |
| 101 | + |
41 | 102 | ## Dependencies |
42 | 103 |
|
| 104 | +해당 프로젝트에서 사용하는 라이브러리의 모음입니다. |
| 105 | + |
43 | 106 | - [Jackson Databind 2.15.3](https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind/2.15.3) |
44 | 107 |
|
45 | | -> `2.15.3`을 사용하는 이유는 현재(2024.03.13) Spring Boot에서 사용하는 버전이 2.15.3이기 때문입니다. |
| 108 | +> `2.15.3`을 사용하는 이유는 현재(2024.03.13) Spring Boot에서 사용하는 버전이 2.15.3이기 때문입니다. |
| 109 | +
|
| 110 | +- [Lombok 1.18.30](https://mvnrepository.com/artifact/org.projectlombok/lombok/1.18.30) |
| 111 | +- [Spring WebMvc 6.1.5](https://mvnrepository.com/artifact/org.springframework/spring-webmvc/6.1.5) |
| 112 | +- [Spring Web 6.1.5](https://mvnrepository.com/artifact/org.springframework/spring-web/6.1.5) |
| 113 | +- [Slf4j Api 2.0.7](https://mvnrepository.com/artifact/org.slf4j/slf4j-api/2.0.7) |
| 114 | + |
0 commit comments