13- Spring boot Project Architecture when using Database(Very Important)
Whenever we are are trying to use database in our project there are few classes that are introduced so as to connect and work with our database..
Refer Spring Boot Architecture image
1- Controller
--> Uses annotation @RestController
--> Handle REST APIs
--> Is responsible for processing incoming requests, preparing a model and returning the
view to be rendered as a response
2- Model or Entity
--> Uses annotation @Entity
--> In springboot model or entity represents java object carrying data
DIFFERENT ANNOTATIONS IN MODEL CLASS USED ARE
@Table
In model java class converted into table in SQL ,
@Column
java datatype into column() for SQL.
@Id
for primary key
@GeneratedValue(strategy=GenerationType.IDENTITY)
for generating primary key automatically by adding +1 to consecutive entries
3- Repository
--> Extend your repository class to JPA repository annotation (@Repository) is optional.
--> Repository class is used to indicate that this class provides the mechanism for Storage , Retrieval , Update , Search and Delete options.
4- Service
--> Uses annotation @Service
--> Use of Service marks the class as a service provider.
So overall the service annotation is used with classes that provide bussiness logic. Spring content will auto detect thes classes when annotation based configuration and classpath used.
Comments
Post a Comment