tenets of Spring boot
main annotations
[[REST]] is the way stuff works now
#spring bean - is something that's created by Spring and its lifecycle is managed from within the Spring framework - user never specifies it's creation or GC #confirm
wow you can create an api by just doing this
@RestControllerclass ProductService {private List<Product> products = new ArrayList<Product>();public ProductService() {products.addAll(List.of(new Product("1", "potato"),new Product("2", "onions"),new Product("3", "chips"),new Product("4", "fruits")));}@GetMapping(value = "/products")Iterable<Product> getProducts() {return products;}}
Optional<type>
as the return param for an api if the value can be empty@GetMapping(value = "/products/{id}")Optional<Product> getProductById(@PathVariable String id) {for(Product p: products) {if(p.getId() == id) return Optional.of(p);}return Optional.empty();}
.equals()
method to check on valuesways we can environmentify the application
@Value
with some expression language to get the valuean example showing reading value from
application.properties
@RestControllerclass ConfigParamsController {@Value("${environment}")private String environment;@GetMapping("/environment")String getEnvironment() {return environment;}}