- BC Java - Assignment 10 - Spring Boot
- Requirements
- Question 1: Path + Query
- Question 2: POST + Query + Body
- Question 3: Header + Path
- Question 4: Query Param có default
- Question 5: Nhận danh sách Query
- Question 6: Query Map động
- Question 7: Form URL Encoded
- Question 8: Multipart + nhiều tham số
- Question 9: PUT cập nhật từng phần
- Question 10: DELETE + Header xác thực
- Prerequisites
- Author
- Requirements
- Requirement:
-
API:
- GET
/orders/{orderId}?currency=VND
- GET
-
Trả về:
{ "orderId": 101, "currency": "VND" } -
Dùng
@PathVariable+@RequestParam
-
- Solution: Question 1
- URL: http://localhost:8080/orders/101?currency=VND
- Requirement:
-
API:
- POST
/comments?postId=5-
Body:
{ "content": "Bài viết hay quá!" }
-
- POST
-
Dùng
@RequestParam+@RequestBody
-
- Solution: Question 2
- URL:
- POST: http://localhost:8080/q2/comments?postId=5
-
Body:
{ "content": "Bài viết hay quá!" }
-
- POST: http://localhost:8080/q2/comments?postId=5
-
Requirement:
- API:
- GET
/users/{id} - Header:
X-Client-Version: 1.2.0
- GET
- Dùng
@RequestHeader+@PathVariable
- API:
-
Solution: Question 3
-
URL:
- http://localhost:8080/q3/users/1
- Header:
X-Client-Version: 1.2.0
- Header:
- http://localhost:8080/q3/users/1
- Requirement:
- API:
- GET /search?keyword=spring Nếu không có page, size → mặc định page=0, size=10
- Dùng
@RequestParam(defaultValue=...)
- API:
- Solution: Question 4
- URL:
- Requirement:
- API:
- GET /tags?tags=java,spring,boot
- Trả về:
List<String>["java", "spring", "boot"]
- Trả về:
- GET /tags?tags=java,spring,boot
- API:
- Solution: Question 5
- URL:
-
Requirement:
- API:
- GET
/filters?color=red&size=M&brand=Nike
- GET
- Dùng
@RequestParam Map<String, String>
- API:
-
Solution: Question 6
-
URL:
- Requirement:
- API:
- POST
/login-form - Content-Type:
application/x-www-form-urlencoded - Params:
username=admin&password=123
- POST
- Dùng
@RequestParam
- API:
- Solution: Question 7
- URL: http://localhost:8080/q7/login-form
- Requirement:
- API:
- POST
/documents - Nhận:
- file
- title
- description
- tags (list)
- POST
- Dùng
MultipartFile+@RequestParam
- API:
- Solution: Question 8
- URL: http://localhost:8080/q8/documents
- Choice "Body" > "form-data"
- Enter "title", "description", "tags" (String)
- Enter "file" (File) and select a file
- Requirement:
-
API:
- PUT
/users/{id}-
Body:
{ "email": "new@email.com" }
-
- PUT
-
Dùng
@PutMapping+@RequestBody+@PathVariable
-
- Solution: Question 9
- URL: PUT http://localhost:8080/q9/users/1
-
Body:
{ "email": "new@email.com" }
-
- Requirement:
- API:
- DELETE
/posts/{id}- Header:
Authorization: Bearer xxx
- Header:
- DELETE
- Dùng
@DeleteMapping+@RequestHeader
- API:
- Solution: Question 10
- URL: http://localhost:8080/q10/posts/1
- Case success:
Authorization: Bearer abc - Case fail:
Authorization: Bearerabcor missAuthorization
- Case success:
- IDE: IntelliJ
- Java 21
Khang Nguyen