Hey there welcome back friends, let's proceed further from where we have left in our last video we have created this particular table by the name of post and we have already added couple of information couple of rows in the database. Now this is cool now moving forward, we would like to integrate support of database into an existing application. Now, if I show you the application, we have this package or dot steadies dot entity and inside this package we have this class by the name of post. Now definitely this class must depict our database table right so let us add in the annotations real quick. So first of all, we must mark this as entity and we will make use of this package Java x dot persistence and then moving forward we will make use of a yet another annotation by the name of deeble and In here, we need to give the name of the table.
So in here, in between pair of parenthesis, if I show you the attributes, one of the attribute is a name. So we will give the name as posts. Here we go. So this is good. Now friends moving forward, we need to also mark a specific property as ID. So in here, if I show you the table, our ID field isn't nothing but the primary key.
So in here, the primary key is depicted by this post ID variable. So in here, we will mark this as ID. All right, let me import the required package. Now there is a yet another issue. The name of this variable is post ID, and the name of the column is ID. So how to like could give the exact name of the column again, we have something known as column attribute.
And using this column attribute, we can provide the name and the name is ID. So this is Good. Now friends, marking these property using this column attribute is optional, because the name of this variable and the name of the column are exactly same, but usually I prefer to mark the properties as column in order to reduce confusion. So, I will quickly mark these as columns and I will also provide the name and name as title. And in fact, let me copy this particular line real quick and use the name body in here. All right, so, our task is done, we have configured our entity class and now we need to create a repository class.
Now what is this repository class is the class using which we will perform the CRUD operations. So in here, let me highlight the package and let me create a class and we will give the package name as or dot study z. Data Repository All right, and the name of our class would be post a repository All right. So, this looks good to me. And now moving forward, let us create this class alright. So, here is our class.
Now, what is a crud operation, crud stands for create, read, update and delete right. Now, friends these operations these operations are the common operations and Spring Boot is opinionated and pre configured framework where majority of the use cases are already covered. Now, definitely crud operation is frequently used operations as a result, the business logic behind the CRUD operations are already available to us and we can easily make use of these specific operations without implementing any business logic. So this is amazing. So in order to do that, first of all in place of class we will make use of interface and we will extend a class. So it would be like extents and the name of the class which we will extend as crud repository.
Here we go. Now this particular repository is a generic type repository where we need to give the type now this generic type repository is important because using this generic type, this particular class can perform operations on any type of object, any type of database table. Now first of all, we need to give the object of our entity class so it would be like post so let me quickly give post in here. So that's one type let me import the required package. And then we need to also provide the primary key data type. So in here the primary key is integrity right?
So in here we will give type as ain't no as soon as I see The changes that is this error, the reason being we cannot give a primitive type in here. And if the primary key is a primitive type, then we need to give the class reference for the primitive type which is integer in our case. All right, and now our work is done. So let me get rid of this comment. And now our work is done. In fact, we need not to implement any business logic inside this particular interface.
All right, now moving forward in here, if I show you the service layer, inside the service layer, we don't need this static list so we will get rid of it. And now in here there are like multiple issues we need to fix these issues we need to implement a couple of things and how we can implement these changes how we can perform the actual database operation is something which we will continue in our next video. I hope you guys enjoyed this video. Well, there are like multiple things that will be We'll discuss in our next video and things would be crystal clear by the end of next video. I hope you guys enjoyed this video. Thanks for watching, have a nice day and take care