Close
« Tutorial

Spring MVC - @PathVariable MCQ

0/13
0 ✓
0 ✗

1. What is the main purpose of the @PathVariable annotation in Spring MVC?

2. Where can the @PathVariable annotation be applied?

3. Which element of @PathVariable is used to specify the URI template variable name?

4. Can you skip the variable name in @PathVariable if the URI template variable name matches the method parameter name?

5. Can a single handler method have multiple @PathVariable annotations?

6. What happens if you define two handler methods with different template variable names but the same base URI?

7. How can you make a path variable optional in Spring MVC?

8. When a path variable is optional and the segment is missing from the URL, what value does the parameter receive?

9. What type should you use for an optional path variable to avoid problems with null values?

10. What is the default value of the required element in @PathVariable?

11. What happens if a required path variable is missing from the URL?

12. Can you use a Map as a method parameter to capture multiple path variables?

13. Can a template URI be specified at the controller class level using @RequestMapping?

14. How can you restrict a path variable to match only letters (e.g., [a-zA-Z]+)?

15. What is the annotation target of @PathVariable?

16. What is the retention policy of @PathVariable?

17. In which package is @PathVariable located?

18. Which code snippet correctly captures a path variable named id?

@RequestMapping("/users/{id}")
public String getUser(/* missing parameter */) { ... }

19. Which annotation correctly marks a method parameter as an optional path variable?

public String getProfile(/* missing annotation */ Long userId) { ... }

20. Which URI template correctly restricts the path variable to only letters using a regular expression?

@RequestMapping(/* missing URI template */)
public String getByName(@PathVariable("name") String name) { ... }
Join