Q. Which annotation sets a base path for controller mappings?
@RequestMapping
@RestController
@Controller
@ResponseStatus
Q. Which snippet shows correct @PathVariable usage?
@GetMapping("/hello/{name}")
public String hello(@PathVariable String name) {
return "Hello, " + name + "!";
}
@GetMapping("/hello/{name}")
public String hello(@RequestParam String name) {
return "Hello, " + name + "!";
}
@GetMapping("/hello")
public String hello(@PathVariable String name) {
return "Hello, " + name + "!";
}
@GetMapping("/hello")
public String hello(@RequestParam String name) {
return "Hello, " + name + "!";
}
Q. Which annotation serializes a handler result into the response body?
@ResponseBody
@RequestMapping
@RestController
@ResponseStatus
Q. Which annotation registers an exception handler method?
@ExceptionHandler
@ResponseStatus
@RequestBody
@ResponseBody
Q. Which annotation sets a custom HTTP status for a handler?
@ResponseBody
@RequestMapping
@ResponseStatus
@RestController
Q. Which snippet correctly uses @RequestBody?
@PostMapping("/hello")
public String hello(@RequestBody String body) {
return "Hello, " + body + "!";
}
@GetMapping("/hello")
public String hello(@RequestParam String name) {
return "Hello, " + name + "!";
}
@PostMapping("/hello")
public String hello(@PathParam String name) {
return "Hello, " + name + "!";
}
@GetMapping("/hello")
public String hello(@RequestBody String body) {
return "Hello, " + body + "!";
}
Q. Which annotation lets you declare the HTTP verb for a handler?
@RequestMapping
@ResponseBody
@Controller
@RequestMethod
Q. Which annotation defines a shared base URL for controller methods?
@RequestMapping
@ResponseBody
@RestController
@Controller