#18 RESTful Web Services | Spring JPA | REST

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so the get request works perfectly right but then think about this if you remember your that your zest with Jersey we have and if you have specified the education which is at at at get right here we can mention that in the in the method itself we can specify a comma here you can say method and that get all you can simply use at the rate get mapping so when you say get mapping it means you are using a get request you can also use post mapping put mapping and delete mapping for other thing I'll get will see that once we continue with the videos in this video we are the most important part is the database connection now think about this if you want to work with database because I want to fetch all the data here from database so of course we have to we have to connect with database we have to create a repository right so we have to see in a repository right and we have to specify all the same examples that you specify on all this properties and of course some that we have to specify all this properties but you have to mention your URL your username password the URL and you have to mention this methods we need a method to put to find all the aliens edge right you have to mention the entire stuff here you have to mention data of this entire code right for one alien you want the entire code for create alien this is the code for delete aliens you have a code write software for everything you have a code there but what if I say you have a easier way now how do i implement that now first of all I am not using normal JDBC here of course we'll be using the EBC but then we will be using a layer of it which is called as a string forum now we also have a concept of JPA again if you're not familiar with JP a concept I would recommend you to learn about that as well I do have a hibernate playlist if you if you follow the follow that playlist you will understand how exactly JPA works or how exactly happen it works again you will find that in description area but even if you don't know that's fine I will we can ignore that internal part of it we can understand the order structure what is happening what we do here is first of all I will add a GPS support in this project and as you can see in my parmesan file I don't have a GPS support so we have to add a GPS support how do I get that how do I get a spring JPA support for that you have to go to memory depository and search for things boot oh what's that spring boot J P a now if you search for spring good GPA your first research in this you have to make sure that you are selecting one point five point four because that's our project version if you'll see that's the project or spring boot version we are working with so let's use one point five point four copy that and paste in your dependencies now you've got a spring boot JPA support now once you have added that and the moment you run this project even if you are not changing and stuff we have just added dependencies right let's try to run this code let's say run as a spring or we'll just run the application the moment to restart the application you will get an error okay before solving the data I want to tell you one more thing let's say if you want to get a project and you're sure that you will be building a project which will be having arrests and JPA both so while while you're getting the project at that time itself we can mention that you want to work with GPA so you don't have to manually add this dependency again we can it's very easy you can just right click here and say new spring Strutter project and you can mention it at the default stop here you can mention I want a web stuff so you can mention web and you can mention JPA so you don't have to manually manually do the manually add a dependency but let's say we have added this dependency right anyhow but what is this error now it says cannot determine the embedded driver class for database type none what what is this error now what is what happens you know your spring boots logic is very intelligent all you can say very smart it's a cheapo grammar I can see that you have additive spring JP dependency but you have not specified you properties Oh spring understand so what you have to do now is we have to specify those properties here but which property have to mention now other things we have to do here so it's very easy actually you can mention URL and it will give you a list here right and in fact this list you have to be you have to select spring dot data source dot you others because we are using a data source contact here and this will mentioned JDBC : MySQL colon double slash localhost the same the same property you have to mention in normal JDBC right so evolution 3 C 0 6 / the database name I forgot it a bit name which you are working with so if I go to my agent depository the database is less DB right next to the same thing with the rest DB the next thing you have to mention is user name so I will say string dot data source dot username we mention the user name as root and I will say again fring dot data so stored password I'll mention be password as 0 and the last thing is the Java class we'll say spring dot the same property you have to mention in the na JDBC ok don't this is nothing new with the spring data source dot it is drywall dot driver - class - name you didn't have to buy hard this thing okay it will be pop-up it will pop up automatically so we'll stay calm dot man skills or JDBC driver right so we have specified all this properties when you work with agent repository here the same stuff we see that the same stuff and that is our job is done I think let's reset the application again this will not be fetching from database but at least the addition should work oh we got an error now it says it is not able to find for MySQL dodge it is the driver because we forgot to add MySQL dependency let's add that as well let's go to mount deposit ratio and let's say hey I want our MySQL connector inside you don't even have to do this if you know that you are working with the spring boot JPA web and masculine while cutting this project we know first for master it will give the dependency but since we have not done that there let's do it manually here I will say I want I want to deny inversion which is four point three point nine again you can go with any ways in which you love okay we have added the master dependency as well this lets you start the application now it should work and you can see there is no error right there is no error now but again it will not work on database because we are not facing from database how do I do that here so in this project if you want to make it work with it abyss you have to go to your package and say hey I want to create a new class now what if I say you don't have to pay the class you have to pay the interface you went to thinking okay we have to first get the interface then we have to get a class and then we'll implement let's see how it works we'll say alien repository okay and we just have to extend or great click on finish we got the interfaces right we just have to extend with one of the one of the internals one of the internal interface colors code repository where you have to mention whatever plans you are working with and the primary key whatever parameter key you're working with so i working with a primary key in teacher now in your master database you have a primary key which is this is not our table let's use rest DB let's verify what you are working with and select star from alien okay so this is our data right now this is your primary key which is integer so it is specify integer here and now you might be thinking okay we have to define all the methods here create or get update and delete and then we have to get one more class which will implement in it this interface works that's how Java works but what if I say you don't have to do any of this stuff let's keep this interface empty and let us not get any other class and in here in this resources we have to create object of ADA repository will say agent repository and we say as I poke that's it and here we simply lights at auto wire now this is a spring code feature if you want object you don't have to get the object by saying new or alien repository you can say right at or two-word it will search for the implementation it will give you the object you don't have to worry about that and here let's not create the object by ourselves simply say the data will be coming from the airport with the report dot Zippo dot find all so we have to use internal method we could find all ok this works ok so we can type past it if it's not work with let's change something let's let's run this for let's see what happens the moment along this code you can see I am using the left for now and oh we got an error oh it says it is not a management if you are using database we have to also make sure that this is an entity because we are using a concept of hibernate and in hibernate we have to mention this as at entity and it's not just hibernate we are talking about in general JP is right so in JP a we have to mention identity and add ID so I ID will give you a idea will make this is a primary key and this class is entity class ok so we are nudging flow Meadows now let's go back to our postman and let's say hey postman fetch the data and you can see that we are getting all this data and this things are coming from database right so that's how this that's how this stuff works here you just have to say find all just type cache it with this list and everything will work fine you don't have to use any trivial stuff everything will work fine right awesome things right so this is how you use a spring rest with database with the help of GPA let me recap what is happening here the magic thing here is we are not getting any class which instances interface and it still works right so this thing is done by spring for you now there are lots of people they say ok thing is not that good now what is this thing is awesome thing is not good it is awesome like it will give you all those extra features which which you need right so that's the magic of spring boot again well once we continue with the example in the next videos will you will get more idea about it but I would recommend you that before going for the next video Duke because this is something which you will understand only when you do it because it's a magic light and magic when I show the magic you will be thinking oh this is awesome but the CEO think you will understand when you fly it by yourself so try it by yourself but then you will see the actual then you will understand the actual stuff the next video we'll see the other methods
Info
Channel: Telusko
Views: 41,497
Rating: undefined out of 5
Keywords: telusko, navin, reddy, tutorial, java, rest, spring, spring jpa example, spring orm, database, jdbc, jpa, spring data jpa
Id: moj78gBA9_o
Channel Id: undefined
Length: 11min 26sec (686 seconds)
Published: Tue Jul 25 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.