0
0
Spring Bootframework~10 mins

@RequestMapping for base paths in Spring Boot - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to set the base path for all requests in this controller.

Spring Boot
@RestController
[1]("/api")
public class ApiController {
    // methods here
}
Drag options to blanks, or click blank then click option'
A@GetMapping
B@RequestMapping
C@PostMapping
D@PathVariable
Attempts:
3 left
💡 Hint
Common Mistakes
Using @GetMapping or @PostMapping at class level instead of @RequestMapping.
Forgetting to add the base path in the annotation.
2fill in blank
medium

Complete the code to map GET requests to the '/users' path under the base path.

Spring Boot
@RestController
@RequestMapping("/api")
public class UserController {
    @[1]("/users")
    public String getUsers() {
        return "";
    }
}
Drag options to blanks, or click blank then click option'
AGetMapping
BPostMapping
CRequestMapping
DDeleteMapping
Attempts:
3 left
💡 Hint
Common Mistakes
Using @PostMapping for GET requests.
Using @RequestMapping without specifying method.
3fill in blank
hard

Fix the error in the code to correctly map POST requests to '/submit' under the base path.

Spring Boot
@RestController
@RequestMapping("/form")
public class FormController {
    @RequestMapping(value = "/submit", method = RequestMethod.[1])
    public String submitForm() {
        return "Submitted";
    }
}
Drag options to blanks, or click blank then click option'
AGET
BPUT
CPOST
DDELETE
Attempts:
3 left
💡 Hint
Common Mistakes
Using GET instead of POST for form submission.
Forgetting to specify the method attribute.
4fill in blank
hard

Fill both blanks to create a controller with base path '/shop' and map DELETE requests to '/item'.

Spring Boot
@RestController
[1]("/shop")
public class ShopController {
    @[2]("/item")
    public String deleteItem() {
        return "Item deleted";
    }
}
Drag options to blanks, or click blank then click option'
A@RequestMapping
BGetMapping
CDeleteMapping
DPostMapping
Attempts:
3 left
💡 Hint
Common Mistakes
Using @GetMapping for DELETE requests.
Using @PostMapping at class level.
5fill in blank
hard

Fill all three blanks to define a controller with base path '/blog', map PUT requests to '/post', and GET requests to '/posts'.

Spring Boot
@RestController
[1]("/blog")
public class BlogController {
    @[2]("/post")
    public String updatePost() {
        return "Post updated";
    }

    @[3]("/posts")
    public String getPosts() {
        return "";
    }
}
Drag options to blanks, or click blank then click option'
A@RequestMapping
BPutMapping
CGetMapping
DDeleteMapping
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing HTTP method annotations.
Forgetting to set base path with @RequestMapping.