Writing services
In this section, we will now write the services for our application, but first, let’s discuss the primary purpose of services in Spring Boot. Services are classes where we place all of our business logic; this is where we will write our CRUD functionalities with the help of JPA repositories. In this case, we will not only make our service class but will also create our JPA repository.
JPA repository
As discussed in Chapter 4, Setting Up the Database and Spring Data JPA, the JPA repository is a widely used specification for managing relational data in Java applications. It helps develop Spring by reducing boilerplate code by not implementing read and write operations.
It is simple to create a JPA repository in Spring Boot; having said that, the JPA library provides classes such as CrudRepository
that we can use to extend our classes. Let’s make one in our Spring Boot application example. Proceed as follows:
- Right-click on our
antiHero
...