Spring Data JPA Filter / Search Examples

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi welcome to the video tutorial spring data JPI printer such with minimum income code level net throughout this video tutorial we will learn how to implement future or such for generality on existing spring book application using screen detail JB a MySQL database and hibernate framework suppose that we have an existing spring application that displaced list of products - as a end users that looks like this you see and there can be many many a lot of products so into the user and the user wants to such filters so reside based on keyword here enter in a text field here and click the search button to search and the application displays only the result that matches their keyword in the user can click the Clear button to reset such displaying all the results here as a technologist could be used in this video tutorial swing cream worked to signify that the Romanovs of our applications Springwood to signify the Dielman configuration of spring music swing data api with have net to signify the calling of data access layer family to signify the calling of the view my SQL JDBC driver to connect with MySQL database and Springwood developer tools and life reload extension to take the fantasies automatic restart and auto reload whenever we make changes to the projects code and to follow this tutorial make sure that you have the forever empty so on the computer javadi room and kids ready k spring toast with IDE and MySQL database server I have an existing screen boot and project as you can see here the project product manager in spring to sweet Heidi for it allows the user to many products in database and you can see the domain model class entity class product here with the field ID name brand medinan price the repository cross products of is classed controller class and in the term leaf will turn list we have the index that displaced all the products and new product and any product now let me started spring replication to test product manager start and as you can see in the projects form here we used spin data JP a term leaf graph and spring good depth tools for automatic we start and reload and mask ul crater Java JDBC driver for mascara okay application is up and running and must open Chrome browser to access our application it-it-it be morroco host energy this is a product manager application that displays the list of products you can see they can bend there can be many a lot of products listed under impressed and now we want to amend filter or search for generalities that allows the user to filter this list with form first from looks nicest let's come back to spring - sweet Eddie open the application controller class up controller here we see the spring MVC controller class and she met handle our method we've impressed he's handling the request we look impressed and he read all the products from the serviced class here so it's not missed all and then return the Julian index add an attribute to this products that we display in the compression and this is compressed that's HTML product manager you can see the table displays the list of products here notice the list or method of the service class and a shake the rocks the fire no method of the repository product body-positive interface fine although here open the product it was history interface here and you see there now to amend the filter or such function we need to declare the new method in the in G's product debility product proposal to request to have the method that performs filter also structured using the akira click this better return a list of product this product again then it s io with K 1 G keyword then we use the query an addiction to declare up to select product based on Commission is the keyword it's like from duck fish more for example moving search for the product name the mono plastic actually is a full name here so here is feed name like percent the same question mark on the first parameter in meta keyword here and % is containing church we select products from where name contains the keyword okay now see and in the control of class so this class we need to grab my maitake what yeah Joong Ki what then we check the K what we call fine oh my touch with the key what yeah so I'm there to controller class do you hope estimated here June Cleaver fantastic but last time the key what a stifled fat cottage a key word okay yes you can see now we have all products listed in the on breast here and now you want to future release the product names that containing the keyword - so save all the changes and we press the load test and I want to click this icon to enables a lot do extension for Chrome so we'd be automatically refreshes the past whenever I make changes to the code must request energy only products with names containing the word - yes and last specify some properties in the application of this part here - she asked clear statements generated by Hamlet we specify the point is filled with dotsub a statue not a PA now properties let format - and now you can see the best clear statement we need for shown here select use from product and what rock name like here easy now nested query to such products based on muhfeels for example we we search for products based on name and brand and MIDI fuse in the product Kathy where the police named Brandon met in here so we are better and Kerry Peter brand like Peter met in life okay and now let's try with the keyword Oh save the changes and we display all the other products having Apple in name-brand MIDI you can see where an apple here I format book have a watch iPad and nest test with another keyword like yesterday sorry she he filters the products based on the USDA keyword refused name or brand or meeting containing the key when he was they it will be listed you see and our last ability HTML file to display a search footer from last lost resist so open the index.html file here yeah we could search for me that published in the section live then this anxiety the Tarot is also in a detection and we've got such filter for Mia filter input type equals text name the keyword safe energy display label filter and textview to enter the keyword here usually with the life we got this tension and spring boutonniere but tools I don't have to refresh the browser whenever I make changes will record it now automatically he'll frosty the fish now we had such button which is a submit button input type equals submit rally with search certainly we see such button appears here and also me to have that clear button to [Music] clear text view Glaser search clear the filter so where the second button for the search from here input ie button very equal clear and the value or the keyword text few is to require so we specified actually require safe you can see click start when you're going to so there is two artists view as the action of the form is give around to the home pressed because in the controller class this is a handle a method for the oppressed here not lists or products so we use the term this inter-church action equal in the home page and in the controller class we need to read the value of the keyword from the text field here so here we specify the parameter is the Brahma notation the query name is the keyword Ching keyword and then we did it in this hard-coded keyword value here okay save all the changes you can see all the products listed here because no keyword is specified to filter down as you take a word for example iPhone here brick such energy only is a product with iPhone appears in name-brand Normandy display and we need to child as a keyword for example Mack energy look here and you can see in the URL it appends the query name keyword with the value is the keyword in the textbook you know let's type China and it display all the drugs made in China as you can see here I'm going to keep the keyword in the filter textbox so in HTML why we specify th value equal value of the keyword attribute in the controller class we need to set a keyword model that attribute for the keyword keyword okay and she okay what China he is kept here and let's search for Kindle there's energy the products twin name Kindle appears here and you see the yoga the keyword in the window here and let's search for Amazon she no reserve because yes the products containing just keyword Amazon and you can see yeah so far so good right nice thing has a better query so it can also search is filters product based on Barack ID and price which has a number of fields so in the query you can you can use this kind of query tools for the search let me show you we concatenate all the fields of product like this where concur this is a concatenation operator in JP Kiera p ID p or named p 4n p dot meeting and retail price like the same question mark for the first perimeter percent so we see with this query very easy to understand in readable energy save the change okay now let's search for through your tap the order yellow here let's see sorry this is a ready-made it feel thank you you can see now in the reserve in this place only the products having Toyota in name no it brand as you can see here we can also search for the valid ID 48 and you can see here the Valley 48 you know search for price price containing what 99 you see here many product having Medina in the price you can see here the last basically we can filter the reserve based on office of products put already name-brand medinan price razor bore such for product with price 1.99 and you can see there are two drugs with the price one more than 99 here and search for Jeff for Intel only one product and I last in remains clear button to clear okay what to display all the products so we need to use JavaScript for this new button on click we invoke the function clear filter when we purchased the rascally function and to put them on the page here script text level script function clear filter and we simply did he take the browser to the home birth your window location equal progress now see now a search for brand Amazon usually click clear he abrupt nor listed less Forge iPhone easy and clear all the products or credit up to query so that you have learned how to remain basic filter search function from existing swing good prosecuting screen data API and keypoint the most important thing is to get a search future query that looks like this and because all the fields as static fixed and so I don't need to use criteria query or complex problematic query api's I just use this simple query is easy to understand easy to write bonus I will show you how to implement a filter or search functionality for an existing application in conjunction with pagination and shouting using spring deters API so if you have not watched my video tutorial about pagination and sorting please watch it in my youtube channel so I have existing a spring boot Rosic product manager here with the personation and sorting already implemented last run this application and testing Chrome browser go to localhost port 8080 energy in this application we have the base relation and sorting facilities the already implemented you can see there are five places here and no true quest to pass three is for peaceful and sorting function shot by name brand vary in price very nice right and last human filter search for generality for this application okay so we also start with the product repository we define a method with a query for the search so for filter search in conjunction with pagination and sorting we need to return pressed instead of my list fresh product file and this method takes two parameters first is the keyword in the second is the variable object to contained information for pagination and shotty visible principal yeah then we specify the JPL the query here for the search on product the query is selectfrom product pitch nowhere and you could user could cut operator to concatenate poser values values the mother fused on the domain model class product yeah he ready name-brand medina price so we concatenate the dot ID p dot name P not brand Peter met Dean name Peter price and like person watching math one for the first parameter is keyword here and then we update the product serviced class to have the keyword parameter install method here so we banned parameter for the keyword here and check if the keyword is not know then we call a new method we turn the repo fine o with a keyword and vegetable object house key what is not specified we must return the existing frydo method with a only visible object that's it and then we need a better controller method here this hand elevated display products by person here and we also need to know specify an additional parameter for the keyword per King would change keyword and passed the keyword here to this better keyword and we're for testing the past initially we hard-coded the keyword which is minus e in the database we have many products made in China so we use a keyword china so we can test the filter so it's in connection with personation what china ok save all the changes we have made so far sorry we need to pass the key word here also and refresh in the browser and you can see only products having China in its fill properly in the reading view China here and you can see there are two prezi's for the keyword china click next you can see because we have an updated happening so the next best is to display all the products now let's cut the search form in the compression index HTML here go to source form here for filter input type equals text name equal K what require and search button input type equals submit value equal search and Clear button into 10 equal button value equal clear safe for the search form refresh and search for map est future you can see the textview must not be left blank get a depression for reply Nuala here and rejection of the form means th action scene of the for me is by default is a pressure one TIF an arrest test we need to start the keyword in a browser controller class yeah don't press the key what my default okay what is no okay and install an attribute for the keyword here Mauro had attribute okay what is variable keyword okay simply changes and in your own person all products need play as you can see we have total 30 items and 5 kgs sick items the pêche to force on a search for china such mmm we want a new property must not know empty in the national reform we need to keep we need to in the resist form we need to store the values of this sort of fever and short order so when we click certain a button the sort you know he went sort of the center server so need to declare hidden few here input type equal hidden maybe so filmed and value is value equal value of the volleyballs are few and we need to have another hidden few is for some direction short dear you can see the variables short favor and Satya set in the model in the control at not here so few stood near okay same chains and quick search for China energy in the URL it opens the keyword China following South fever and sotnia here and you can see in the result rest there are seven items all the products made in China and to pieces but when click it best second it's to display or barracks because we have an admitted that I bling for the pass in Asian yet so nice time later I play from the pagination to include keyword search K what you see a section to not display the URL for the rest number here and we append the keyword here we append the value for the keyword here as we only up NDP what is not know so we have a check here he would not know then we concatenate the your outwitted critique Nikki with the key what Gretchen McKay what equal plus keyword mouse we must concatenate with near empty string okay now see and safe not on yellow here you could not pass an expression so we have something wrong here this would be the ampersand and and more emojis nature closing my kid okay safe okay walks now and [Music] click the link to the second person you see in the second best is when we have only one product so that means the filter is coping with the pagination we need to keep the key what in the future text back here so we index it you know first we set value for the keyword here th value equal value of the variable Q what you can see keyword China and let's search for the keyword Vietnam you know it's the only one - yesterday yesterday also having two PC's and go to the second page here USA you see press number two what few new okay what u.s. they so for China first of all yesterday we had 10 items click go to the second press boy exists Rahzel as you know China not the u.s. day mm-hmm first fish yesterday and so for China you can also sort by name you know descending order ascending order brand you can see but in the sort we haven't updated to a good keyword so go through the whole piss and search for the us day second place Boise is because with a concatenation we have the us a here you see us day so this product is listed yet as containing the keyword he was day so we can fix this by inserting the white space between here between the few here in the query voice best voice press ok save the change energy now our only night items it is correct now for easier product made in products made in the USA in a display and less a bit keyword query parameter here for the links in the table column headers and links in the puzzle machine first previous next last last copy-paste let's copy-paste the this expression to input query parameter keyword yeah here yeah for next and previous nine planes and for the table column here okay so you see whispering data's API is very easy to remain puzzle Asian sorting and in conjunction with filter such okay as it say we whenever such fusion ID let's see because our arrow for the next question URL you first previous/next and last okay here we go so all the eye blinks while sorting and pagination updated within the keyword parameter example in this search we have only products meeting us day and let's sort it by name you see it by name in descending order and you see this is the first paste and next pressed you see Amazon echo is in the last name sought the way it will be sorted in ascending order first paste you see also to resolve the future here last you see son bran you see first paste next paste previous paste it works very good right very well print and price you see no sources for iced over luck with 99 in the price yeah we had to busy yeah and we can shot with thought my meeting nod my name brand go to next page previous best and for the Clear button you can amend yourself and I so we in the previous section so far you have learned how to in main filter such generalities for an existing screen good application using sprinting there's API you also learn how to amend filters just with the imagination and shutting and key important thing is to make a search query resist and with miserable parameter resist to use future search in connection with pagination and sorting I hope you found this video tutorial helpful please click subscribe like comment and share this video thank you
Info
Channel: Code Java
Views: 83,331
Rating: undefined out of 5
Keywords: Java, Spring framework, Spring Boot, Spring Data JPA, Spring filter search, Spring filter example, Spring search example, Spring Data JPA filter, Spring Data JPA search, Spring Boot filter example, Spring Boot search example, Spring search Hibernate, Spring search MySQL, Spring filter with pagination, Spring search with pagination, Spring filter with sort, Spring filter with paging
Id: Q4e_GydUjbs
Channel Id: undefined
Length: 51min 24sec (3084 seconds)
Published: Thu Apr 30 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.