- アノテーション処理を有効化する。
- Settings > Build, Excecution, Deployment > Compiler > Annotation Processor >
Enable Annotation Processing
をONにする。
- Settings > Build, Excecution, Deployment > Compiler > Annotation Processor >
- bootRunを実行している場合でもビルドされるようにする。(単一ファイルのビルドを実行すると spring-devtools が変更を検知して自動的に再起動されるようになります)
- Intellij > Ctrl+Shift+A > type Registry... >
compiler.automake.allow.when.app.running
をONにする。
- Intellij > Ctrl+Shift+A > type Registry... >
- Windowsの場合は、コンソール出力が文字化けするため、
C:¥Program Files¥JetBrains¥IntelliJ Idea xx.x.x¥bin
の中にあるidea64.exe.vmoptions
ファイルに-Dfile.encoding=UTF-8
を追記する。
$ # run spring boot app
$ ./gradlew bootRun
$ # ログイン
$ curl -s -L -X POST 'http://localhost:8080/api/auth/login' \
-H 'Content-Type: application/json' \
--data-raw '{
"username": "test@example.com",
"password": "passw0rd" }' | jq .
{
"data": {
"accessToken": "<access-token>",
"refreshToken": "<refresh-token>"
},
"success": true,
"message": "正常終了"
}
$ # トークンリフレッシュ
$ curl -s -L -X POST 'http://localhost:8080/api/auth/refresh' \
-H 'Content-Type: application/json' \
--data-raw '{
"accessToken": "<access-token>",
"refreshToken": "<refresh-token>"
}' | jq .
{
"data": {
"accessToken": "<new-access-token>",
"refreshToken": "<new-refresh-token>"
},
"success": true,
"message": "正常終了"
}
$ # 検索
$ curl -s -L -X GET 'http://localhost:8080/api/system/staffs' \
-H 'Authorization: Bearer <access-token>' | jq .
{
"page": 0,
"perpage": 10,
"count": 1,
"totalPages": 1,
"data": [
{
"createdAt": "2022-06-23T01:19:50",
"updatedAt": "2022-06-23T01:19:50",
"version": 1,
"id": "23fb7d1e-f247-11ec-8bad-0242ac11000a",
"firstName": "john",
"lastName": "doe",
"email": "test@example.com",
"tel": "09011112222"
}
],
"success": true,
"message": "正常終了"
}
$ # 登録
$ curl -s -L -X POST 'http://localhost:8080/api/system/staff' \
-H 'Authorization: Bearer <access-token>' \
-H 'Content-Type: application/json' \
--data-raw '{
"firstName": "jiro",
"lastName": "yamada",
"password": "aaaaaaaa",
"passwordConfirm": "aaaaaaaa",
"email": "aaaa@bbbb.com",
"tel": "0000000000"
}' | jq .
{
"data": {
"createdAt": "2022-06-24T13:19:28.273167",
"updatedAt": "2022-06-24T13:19:28.273167",
"version": 0,
"id": "d312b078-64d1-492e-a5b9-0f0f390d25b9",
"firstName": "jiro",
"lastName": "yamada",
"email": "aaaa@bbbb.com",
"tel": "0000000000"
},
"success": true,
"message": "正常終了"
}
$ # 更新
$ curl -s -L -X PUT 'http://localhost:8080/api/system/staff/fdae5e41-2edf-46ca-8b35-22cb3c5b447a' \
-H 'Authorization: Bearer <access-token>' \
-H 'Content-Type: application/json' \
--data-raw '{
"id": "fdae5e41-2edf-46ca-8b35-22cb3c5b447a",
"firstName": "jiro2",
"lastName": "yamada",
"password": "aaaaaaaa",
"passwordConfirm": "aaaaaaaa",
"email": "aaaa@bbbb.com",
"tel": "0000000000",
"version": 0
}' | jq .
{
"data": {
"createdAt": "2022-06-24T14:39:19",
"updatedAt": "2022-06-24T14:48:24.435239",
"version": 1,
"id": "fdae5e41-2edf-46ca-8b35-22cb3c5b447a",
"firstName": "jiro2",
"lastName": "yamada",
"email": "aaaa@bbbb.com",
"tel": "0000000000"
},
"success": true,
"message": "正常終了"
}
$ # 取得
$ curl -s -L -X GET 'http://localhost:8080/api/system/staff/fdae5e41-2edf-46ca-8b35-22cb3c5b447a' \
-H 'Authorization: Bearer <access-token>' | jq .
{
"data": {
"createdAt": "2022-06-24T14:39:19",
"updatedAt": "2022-06-24T14:48:24",
"version": 1,
"id": "fdae5e41-2edf-46ca-8b35-22cb3c5b447a",
"firstName": "jiro2",
"lastName": "yamada",
"email": "aaaa@bbbb.com",
"tel": "0000000000"
},
"success": true,
"message": "正常終了"
}
$ # 削除
$ curl -s -L -X DELETE 'http://localhost:8080/api/system/staff/fdae5e41-2edf-46ca-8b35-22cb3c5b447a' \
-H 'Authorization: Bearer <access-token>' | jq .
{
"data": {
"createdAt": "2022-06-24T14:39:19",
"updatedAt": "2022-06-24T14:48:24",
"version": 1,
"id": "fdae5e41-2edf-46ca-8b35-22cb3c5b447a",
"firstName": "jiro2",
"lastName": "yamada",
"email": "aaaa@bbbb.com",
"tel": "0000000000"
},
"success": true,
"message": "正常終了"
}
http://localhost:8080/swagger-ui.html
mysql -h 192.168.64.3 -P 30306 -uroot -ppassw0rd spring-boot-doma2-rest-sample
mysql> show tables;
+----------------------------------------------+
| Tables_in_spring-boot-doma2-rest-sample |
+----------------------------------------------+
| code_categories |
| codes |
| flyway_schema_history |
| holidays |
| mail_templates |
| permissions |
| role_permissions |
| roles |
| send_mail_queue |
| staff_roles |
| staffs |
| upload_files |
| user_roles |
| users |
+----------------------------------------------+
14 rows in set (0.01 sec)
プロジェクト | 概要 |
---|---|
Lombok Project | 定型的なコードを書かなくてもよくする |
Springframework | Spring Framework(Spring WebFlux) |
Spring Security | セキュリティ対策、認証・認可のフレームワーク |
MyBatis | O/Rマッパー |
SpringDoc | OpenAPI ドキュメントツール |
Flyway | DBマイグレーションツール |
ModelMapper | Beanマッピングライブラリ |
JUnit5 | テストフレームワーク |
Mockito | モッキングフレームワーク |
MailHog | ウェブベースのSMTPテスター |