Skip to content

Commit 0daf8ab

Browse files
authored
Update README.md
1 parent 203f90d commit 0daf8ab

File tree

1 file changed

+95
-109
lines changed

1 file changed

+95
-109
lines changed

README.md

Lines changed: 95 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,165 +1,151 @@
11
# fast-crud
2-
Automatic creation of simple CRUD API of Spring boot and JPA project.
2+
매번 반복되는 Spring boot & JPA 의 기본적인 CRUD API 를 자동화 할 수 있지 않을까?
33

4-
<br>
4+
latest version : 1.0.1
55

6-
## How to use
6+
## 기능들
7+
- 어노테이션 표시로 엔티티의 Create, Read, Update, Delete API 가 생성된다.
8+
- 자동 생성된 API의 Root path 를 설정할 수 있다.
9+
- CRUD 중 추가할, 또는 제외할 기능을 선택할 수 있다.
710

8-
#### Step 1. Add the dependency.
11+
## 미리보기
12+
``` java
13+
@CRUD(repositoryType = SampleRepository.class)
14+
@Entity
15+
class Sample {
16+
}
17+
```
918

10-
<details>
11-
<summary>Gradle (build.gradle)</summary>
19+
Entity 의 @CRUD 를 읽어, 아래의 API가 자동 생성된다.
1220

13-
``` groovy
21+
```
22+
[POST] /sample
23+
[GET] /sample
24+
[GET] /sample/{id}
25+
[PUT] /sample
26+
[DELETE] /sample/{id}
27+
```
28+
29+
## 사용 방법
30+
31+
### build.gradle
32+
33+
라이브러리 의존성을 추가한다.
34+
```
1435
repositories {
1536
maven { url 'https://jitpack.io' }
1637
}
17-
```
1838
19-
``` groovy
2039
dependencies {
21-
implementation 'com.github.ecsimsw:fast-crud:0.0.2'
40+
implementation 'com.github.ecsimsw:api-shutdown:1.0.1'
2241
}
2342
```
24-
</details>
2543

26-
<details>
27-
<summary>Maven (pom.xml)</summary>
28-
29-
``` xml
30-
<repositories>
31-
<repository>
32-
<id>jitpack.io</id>
33-
<url>https://jitpack.io</url>
34-
</repository>
35-
</repositories>
36-
```
37-
``` xml
38-
<dependency>
39-
<groupId>com.github.ecsimsw</groupId>
40-
<artifactId>fast-crud</artifactId>
41-
<version>0.0.2</version>
42-
</dependency>
43-
```
44+
### @EnableCrud 추가
45+
46+
@EnableCrud 로 라이브러리 사용을 활성화한다.
4447

45-
</details>
48+
``` java
49+
@EnableCrud
50+
@SpringBootApplication
51+
public class MyApplication {}
52+
```
4653

47-
<br>
54+
### @CRUD 표시
4855

49-
#### Step 2. Put @CRUD on your entity class.
56+
CRUD 를 적용할 Entity에 @CRUD와 엔티티 Repository type 를 표시한다.
5057

5158
``` java
52-
@CRUD
59+
@CRUD(repositoryType = SampleRepository.class)
5360
@Enity
5461
class Sample {
5562
}
5663
```
5764

58-
<br>
59-
60-
#### Step 3. Declare JpaRepository with entity name.
61-
6265
``` java
63-
public interface SampleRepository extends JpaRepository<Sample, Long> {}
66+
interface SampleRepository extends JpaRepository<Sample, Long> {
67+
}
6468
```
6569

66-
<br>
70+
### API 명세
6771

68-
#### Step 4. That's it. You just made basic CRUD http api bellow.
72+
아래 CRUD api 가 자동 생성된다.
73+
생성과 수정의 Request body 에는 Entity 의 프로퍼티 키와 값이 포함된다.
6974

70-
| |HttpMethod|Path|RequestBody (Json)|
71-
|----|------|----|-----|
72-
|save|POST|/{entityName}|O|
73-
|findAll|GET|/{entityName}|X|
74-
|findById|GET|/{entityName}/{id}|X|
75-
|update|PUT|/{entityName}/{id}|O|
76-
|delete|DELETE|/{entityName}/{id}|X|
75+
#### 생성
76+
```
77+
[POST] /sample
78+
{
79+
"name" : "ecsimsw"
80+
}
81+
```
7782

78-
<br>
83+
#### 조회
7984

80-
#### Step 5. Example
81-
``` java
82-
@CRUD
83-
@Entity
84-
public class Sample {
85-
86-
@GeneratedValue
87-
@Id
88-
private Long id;
89-
private String name;
90-
91-
public Sample() {
92-
}
93-
94-
public Sample(String name) {
95-
this.name = name;
96-
}
97-
98-
public Long getId() {
99-
return id;
100-
}
101-
102-
public String getName() {
103-
return name;
104-
}
105-
}
85+
```
86+
[GET] /sample/{id}
10687
```
10788

108-
``` java
109-
public interface SampleRepository extends JpaRepository<Sample, Long> {}
89+
#### 전체 조회
90+
```
91+
[GET] /sample
11092
```
11193

112-
```
113-
[POST] localhost:8080/sample
114-
{
115-
"name" : "ecsimsw"
116-
}
117-
[PUT] localhost:8080/sample/1
94+
#### 수정
95+
96+
```
97+
[PUT] /sample/{id}
11898
{
119-
"name" : "new_name"
99+
"name" : "new_name"
120100
}
121-
[GET] localhost:8080/sample
122-
[GET] localhost:8080/sample/1
123-
[DELETE] localhost:8080/sample/1
124101
```
125102

126-
<br>
127-
128-
## Additional features
129-
130-
#### Repository name
131-
132-
You can set your repository bean name in @CRUD with `repositoryBean` parameter.
103+
#### 삭제
133104

134-
``` java
135-
@CRUD(repositoryBean = "anotherName")
136105
```
137-
138-
``` java
139-
public interface AnotherName extends JpaRepository<Sample, Long> {}
106+
[DELETE] /sample/{id}
140107
```
141108

142-
<br>
109+
### Root path 설정
143110

144-
#### API root path
145-
146-
You can set your api `root path`
111+
기본 API 기본 경로는 Entity 이름이다. @CRUD 어노테이션의 rootPath 값으로 API 기본 경로를 변경할 수 있다.
112+
아래 예시의 경우 `/api/sample` 으로 API 경로가 생성된다.
147113

148114
``` java
149-
@CRUD(rootPath = "anotherRoot")
115+
@CRUD(rootPath = "api/sample")
116+
@Entity
117+
class Sample {}
150118
```
151119

120+
### 제외 기능 설정
121+
122+
CRUD 중 제외할 기능을 명시할 수 있다.
123+
아래 예시의 겨우 엔티티의 수정과 삭제 기능없이, 생성과 조회 API 만 자동 생성된다.
124+
152125
```
153-
/anotherRoot
154-
/anotherRoot/{id}
126+
@CRUD(excludeType = {CrudType.DELETE, CrudType.UPDATE})
127+
@Entity
128+
class Sample {
155129
```
156130

157-
<br>
131+
## 변경 사항
158132

159-
#### Exclude method
133+
### v1.0.0
160134

161-
Method can be excluded in @CRUD with `exclude` parameter.
135+
Spring boot 2.6 이상부터 MVC 핸들러 매핑 경로 매칭 기본 전략이 AntPathMatcher -> PathPatternParser 로 수정되었다. RequestMappingHandlerMapping 에 추가되는 RequestMappingInfo 에 PathMatcher 를 설정하는 것으로, 기본 전략은 유지한 채 라이브러리에서 자동 생성하는 RequestMapping 정보만 AntPathMatcher를 따르도록 수정한다.
162136

163137
``` java
164-
@CRUD(exclude = {CrudMethod.UPDATE, CrudMethod.DELETE})
138+
public HandlerInfo(CrudRequestHandler handlerInstance, RequestMethod httpMethod, String requestPath) {
139+
this.handler = handlerInstance;
140+
var buildConfig = new RequestMappingInfo.BuilderConfiguration();
141+
buildConfig.setPathMatcher(new AntPathMatcher());
142+
buildConfig.setPatternParser(new PathPatternParser());
143+
this.requestMappingInfo = RequestMappingInfo
144+
.paths(requestPath)
145+
.methods(httpMethod)
146+
.options(buildConfig)
147+
.build();
148+
}
165149
```
150+
151+

0 commit comments

Comments
 (0)