Resource class for the entity

In the src/main/java/com/mycompany/store/web/rest folder, you will find the entity resource service. Open ProductResource.java:

@RestController
@RequestMapping("/api")
public class ProductResource {
...
}

The resource acts as the controller layer, and in our case, it serves the REST endpoints to be used by our client-side code. The endpoint has a base mapping to "/api":

    @GetMapping("/products")
public ResponseEntity<List<Product>> getAllProducts(Pageable
pageable) {
log.debug("REST request to get a page of Products");
Page<Product> page = productService.findAll(pageable);
HttpHeaders headers = PaginationUtil.
generatePaginationHttpHeaders(
ServletUriComponentsBuilder.fromCurrentRequest(),
page);
return ResponseEntity.ok().headers(headers).
body(page.getContent());
}

All the CRUD actions have equivalent mapping methods hereā€”for example, the getAllProducts maps to findAll from our service. The resource also handles pagination by adding appropriate headers for pagination.

Let's take a look at the client-side code in the next section.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.220.1.239