30
loading...
This website collects cookies to deliver better user experience
@RestController
public class GradeController {
@GetMapping("/grade/{id}")
public void getGradeById(@PathVariable String id){
// business stuff
}
}
baseUrl/grade/someGradeId
that is run when a GET request is made with a URL matching the pattern (baseUrl/grade/1
for example).baeUrl/grade/{id}
.@RestController
public class GradeController {
@PostMapping("/grade/add")
public void getGradeById(@RequestBody Grade grade){
// business stuff
}
}
class Grade{
Integer id;
String letter;
// getters and setters and constructors
}
{
"id": "1",
"letter": "A+"
}
@RestController
public class GradeController {
@PostMapping("/grade/add")
public void getGradeById(@RequestBody Grade grade) throws Exception{
if (grade.getId() < 0)
throw new Exception();
}
}
class Grade{
@Min(1)
Integer id;
String letter;
}
@PostMapping("/grade/add")
public void getGradeById(@RequestBody @Validated Grade grade)
{
// business stuff
}
@RestController @RequiredArgsConstructor
public class GradeController {
private final GradeService gradeService;
@GetMapping("/grade")
public void getGradeById()
{
gradeService.doThings();
}
}
@RestController
public class GradeController {
@GetMapping("/grade/add")
public APIResponse getGradeById()
{
// do things
return new APIResponse("success");
}
}
@AllArgsConstructor
class APIResponse{
String message;
}
{
"message" : "success"
}