Java studies.
Implementing the POST method
with Spring using its corresponding Annotation @PostMapping
as well as learning more about DTOs
, how to create, how to use and why it's used.
@RestController
@RequestMapping("/api/cars")
public class CarsController {
String cars;
@GetMapping
ResponseEntity<String> getCars() {
if (cars == null) {
return ResponseEntity.status(HttpStatus.NOT_FOUND)
.body("The list of cars is empty, submit a car first.");
}
return ResponseEntity.status(HttpStatus.OK)
.body("The list of cars: \n" + cars);
}
@PostMapping
public void createCar(@RequestBody String req) {
cars = req;
System.out.println(req);
}
}
For further reference, please consider the following sections:
- Official Apache Maven documentation
- Spring Boot Maven Plugin Reference Guide
- Create an OCI image
- Spring Web
- Spring Boot DevTools
The following guides illustrate how to use some features concretely: