diff --git a/.gitattributes b/.gitattributes index 379c2a5de75403a89d22b3b98811afc8a2dd1566..bf9dce6b5723c9f54b0d2090effe0f6f4a98d2b8 100644 --- a/.gitattributes +++ b/.gitattributes @@ -92,3 +92,16 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text 02[[:space:]]-[[:space:]]Core[[:space:]]Java/058[[:space:]]Access[[:space:]]Modifiers.mp4 filter=lfs diff=lfs merge=lfs -text 02[[:space:]]-[[:space:]]Core[[:space:]]Java/056[[:space:]]Method[[:space:]]Overriding.mp4 filter=lfs diff=lfs merge=lfs -text 02[[:space:]]-[[:space:]]Core[[:space:]]Java/061[[:space:]]Final[[:space:]]keyword.mp4 filter=lfs diff=lfs merge=lfs -text +02[[:space:]]-[[:space:]]Core[[:space:]]Java/060[[:space:]]Dynamic[[:space:]]Method[[:space:]]Dispatch.mp4 filter=lfs diff=lfs merge=lfs -text +02[[:space:]]-[[:space:]]Core[[:space:]]Java/062[[:space:]]Object[[:space:]]Class[[:space:]]equals[[:space:]]toString[[:space:]]hashcode.mp4 filter=lfs diff=lfs merge=lfs -text +02[[:space:]]-[[:space:]]Core[[:space:]]Java/063[[:space:]]Upcasting[[:space:]]and[[:space:]]Downcasting.mp4 filter=lfs diff=lfs merge=lfs -text +02[[:space:]]-[[:space:]]Core[[:space:]]Java/064[[:space:]]Wrapper[[:space:]]Class.mp4 filter=lfs diff=lfs merge=lfs -text +03[[:space:]]-[[:space:]]Advance[[:space:]]Java/002[[:space:]]Project[[:space:]]1-[[:space:]]QuestionService[[:space:]]and[[:space:]]Question[[:space:]]class.mp4 filter=lfs diff=lfs merge=lfs -text +03[[:space:]]-[[:space:]]Advance[[:space:]]Java/003[[:space:]]Project[[:space:]]1-[[:space:]]Hard[[:space:]]Coded[[:space:]]Questions[[:space:]]and[[:space:]]Display[[:space:]]them.mp4 filter=lfs diff=lfs merge=lfs -text +03[[:space:]]-[[:space:]]Advance[[:space:]]Java/004[[:space:]]Project[[:space:]]1-[[:space:]]Play[[:space:]]Quiz.mp4 filter=lfs diff=lfs merge=lfs -text +03[[:space:]]-[[:space:]]Advance[[:space:]]Java/001[[:space:]]Project[[:space:]]1-[[:space:]]Introduction.mp4 filter=lfs diff=lfs merge=lfs -text +03[[:space:]]-[[:space:]]Advance[[:space:]]Java/005[[:space:]]Project[[:space:]]1-[[:space:]]Calculate[[:space:]]Score.mp4 filter=lfs diff=lfs merge=lfs -text +03[[:space:]]-[[:space:]]Advance[[:space:]]Java/008[[:space:]]Anonymous[[:space:]]Inner[[:space:]]class.mp4 filter=lfs diff=lfs merge=lfs -text +03[[:space:]]-[[:space:]]Advance[[:space:]]Java/007[[:space:]]Inner[[:space:]]class.mp4 filter=lfs diff=lfs merge=lfs -text +03[[:space:]]-[[:space:]]Advance[[:space:]]Java/006[[:space:]]Abstract[[:space:]]keyword.mp4 filter=lfs diff=lfs merge=lfs -text +03[[:space:]]-[[:space:]]Advance[[:space:]]Java/010[[:space:]]What[[:space:]]is[[:space:]]Interface.mp4 filter=lfs diff=lfs merge=lfs -text diff --git a/02 - Core Java/060 Dynamic Method Dispatch.mp4 b/02 - Core Java/060 Dynamic Method Dispatch.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..9308a86d40a7ad172cc8dedbfe4a42a576683142 --- /dev/null +++ b/02 - Core Java/060 Dynamic Method Dispatch.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bc9d46f02807b29a077f3b2e6b099473191052518f1597a17f77fd25d7a7b0aa +size 129233029 diff --git a/02 - Core Java/062 Object Class equals toString hashcode.mp4 b/02 - Core Java/062 Object Class equals toString hashcode.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..a5335fbda93cb1bd4431c8cd370c0595352183e0 --- /dev/null +++ b/02 - Core Java/062 Object Class equals toString hashcode.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7c852c2cabe1313a58066dc134b3a4e7f18c557cce975636a4365022d22aaaf3 +size 190406934 diff --git a/02 - Core Java/063 Upcasting and Downcasting.mp4 b/02 - Core Java/063 Upcasting and Downcasting.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..abfe5925b47fa9969d0d0daede907dec2aa9a87f --- /dev/null +++ b/02 - Core Java/063 Upcasting and Downcasting.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bd31327ddd8fa7668fb1d16310feea6bc75b40244da9e96ca0dca86d6f3985e3 +size 102704879 diff --git a/02 - Core Java/064 Wrapper Class.mp4 b/02 - Core Java/064 Wrapper Class.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..e024b80539795e24f2e0b933c4ae60904e7b6ca3 --- /dev/null +++ b/02 - Core Java/064 Wrapper Class.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:85cf27831c11f02a53002461ca8a1518dd09dd619b3a033df7d8725de08e102e +size 145677485 diff --git a/03 - Advance Java/001 Project 1- Introduction.mp4 b/03 - Advance Java/001 Project 1- Introduction.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..4f46c5eb8fba95366ba729a893fe8f726263e011 --- /dev/null +++ b/03 - Advance Java/001 Project 1- Introduction.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:35be7a4d600f461a21aa0c6ea3f958147ff5df69f57de5eb3f08bbc8fc5be76c +size 136418515 diff --git a/03 - Advance Java/002 Project 1- QuestionService and Question class.mp4 b/03 - Advance Java/002 Project 1- QuestionService and Question class.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..faae8abcbb4c964b3f2578e3d956829e6af197e3 --- /dev/null +++ b/03 - Advance Java/002 Project 1- QuestionService and Question class.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c5de5f0e0e7ab143315fb1eb8e060acbffbb27dfbd37ee1dbc6dbdaa7bcf8575 +size 145550215 diff --git a/03 - Advance Java/003 Project 1- Hard Coded Questions and Display them.mp4 b/03 - Advance Java/003 Project 1- Hard Coded Questions and Display them.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..f052067b31774d3abd5bd60ef0c4779c0033f30c --- /dev/null +++ b/03 - Advance Java/003 Project 1- Hard Coded Questions and Display them.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:67ba97b25f20a47b8c08a6547e95b84cad6188cbbef9283d9a26945bc1b83a3b +size 69362437 diff --git a/03 - Advance Java/004 Project 1- Play Quiz.mp4 b/03 - Advance Java/004 Project 1- Play Quiz.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..b2e49c7990282f8020047e313abdd2803c80a6be --- /dev/null +++ b/03 - Advance Java/004 Project 1- Play Quiz.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:04b93ed99f219f66b56c85d0def994b2bc3d4e3300685cb4fb161323d0a06935 +size 107860262 diff --git a/03 - Advance Java/005 Project 1- Calculate Score.mp4 b/03 - Advance Java/005 Project 1- Calculate Score.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..3ac0ccf4af9b097e4f298ccc0da79bef433ab74c --- /dev/null +++ b/03 - Advance Java/005 Project 1- Calculate Score.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:736267e1ec3b3a405c6489817ad3596dfd890c8fb747ee1ee8fceb95a32ccf7e +size 37740181 diff --git a/03 - Advance Java/006 Abstract keyword.mp4 b/03 - Advance Java/006 Abstract keyword.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..12b856cb2878c775120d9b38f866ac083195e5b3 --- /dev/null +++ b/03 - Advance Java/006 Abstract keyword.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1bc255c60390b8acec234115f5f9b657a4a0308740e03c7666a29f16c64d5d02 +size 189686181 diff --git a/03 - Advance Java/007 Inner class.mp4 b/03 - Advance Java/007 Inner class.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..faf519535914532a6ed9c7c0f81202374274b568 --- /dev/null +++ b/03 - Advance Java/007 Inner class.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:398fe16f53ef983719ad3443aaca02622a914aed9bad58bf5b9950066e8e65e1 +size 89146904 diff --git a/03 - Advance Java/008 Anonymous Inner class.mp4 b/03 - Advance Java/008 Anonymous Inner class.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..5f09d3cefcceb0e344c00e51c7e5ddf81626b5d3 --- /dev/null +++ b/03 - Advance Java/008 Anonymous Inner class.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:43d8d348499aa15af87ce7c8dc6f82de2d4136f42e88de3b0f695ad90ecda971 +size 78822462 diff --git a/03 - Advance Java/010 What is Interface.mp4 b/03 - Advance Java/010 What is Interface.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..a9782edb9cf2eb15d639e0cfe4fee4aa077417be --- /dev/null +++ b/03 - Advance Java/010 What is Interface.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ab7c6bbb1c08f639eebfdc1872a8a02ba22912992402efc2d9616c045a413741 +size 41653219 diff --git a/12 - Spring Boot Web/009 Source-Code.url b/12 - Spring Boot Web/009 Source-Code.url new file mode 100644 index 0000000000000000000000000000000000000000..4b22f7dee861dc9ebcc5d6cc209a04f69f471e6c --- /dev/null +++ b/12 - Spring Boot Web/009 Source-Code.url @@ -0,0 +1,2 @@ +[InternetShortcut] +URL=https://github.com/navinreddy20/spring6-course/tree/f1161e151ea06b68810b3cae03005d4955a96a8b/6%20Spring%20%20Boot%20Web/5.9%20Creating%20a%20Controller \ No newline at end of file diff --git a/12 - Spring Boot Web/010 RequestMapping_en.srt b/12 - Spring Boot Web/010 RequestMapping_en.srt new file mode 100644 index 0000000000000000000000000000000000000000..30b88f59b53d988ebf8f0ca0d11adf62e8d11dcc --- /dev/null +++ b/12 - Spring Boot Web/010 RequestMapping_en.srt @@ -0,0 +1,376 @@ +1 +00:00:00,000 --> 00:00:03,000 +(bright music) + +2 +00:00:03,000 --> 00:00:06,000 +-: Okay, so let's solve this problem of mapping. + +3 +00:00:06,000 --> 00:00:08,000 +The thing is, if you want to map this, you don't have + +4 +00:00:08,000 --> 00:00:11,000 +to do any qualification for the XML, luckily. + +5 +00:00:11,000 --> 00:00:12,000 +We have to use annotation. + +6 +00:00:12,000 --> 00:00:14,000 +Now, which annotation we have to use? + +7 +00:00:14,000 --> 00:00:16,000 +So for this, for mapping the request, + +8 +00:00:16,000 --> 00:00:19,000 +we have to use annotation call RequestMapping. + +9 +00:00:19,000 --> 00:00:23,000 +And in this mapping you have to pass the path. + +10 +00:00:23,000 --> 00:00:24,000 +The path here is homepage. + +11 +00:00:24,000 --> 00:00:26,000 +So whenever someone calls the homepage, + +12 +00:00:26,000 --> 00:00:28,000 +this is something I want to execute. + +13 +00:00:28,000 --> 00:00:30,000 +It is as simple as that. + +14 +00:00:30,000 --> 00:00:32,000 +Just a request mapping, it will come to know + +15 +00:00:32,000 --> 00:00:34,000 +that this is a mapping we have to do, + +16 +00:00:34,000 --> 00:00:35,000 +which is for the slash. + +17 +00:00:35,000 --> 00:00:36,000 +Yeah, if you're doing for the students, + +18 +00:00:36,000 --> 00:00:37,000 +you can also say student. + +19 +00:00:37,000 --> 00:00:39,000 +So you can say slash student, + +20 +00:00:39,000 --> 00:00:40,000 +you will map for slash student, + +21 +00:00:40,000 --> 00:00:44,000 +but at this point I want to map it for the slash homepage. + +22 +00:00:44,000 --> 00:00:46,000 +And that's the only change you have to make. + +23 +00:00:46,000 --> 00:00:50,000 +Let's refresh this taking some time, go back to your browser + +24 +00:00:50,000 --> 00:00:52,000 +and say, refresh, done. + +25 +00:00:52,000 --> 00:00:54,000 +Something happened. + +26 +00:00:54,000 --> 00:00:56,000 +Okay, it's not the same thing which we were expecting. + +27 +00:00:56,000 --> 00:00:59,000 +We were expecting a page. + +28 +00:00:59,000 --> 00:01:00,000 +But you can see it says, + +29 +00:01:00,000 --> 00:01:04,000 +do you want to allow downloads on local host? + +30 +00:01:04,000 --> 00:01:07,000 +If I say allow, something got downloaded. + +31 +00:01:07,000 --> 00:01:10,000 +If I see here it says unknown file. I mean that's weird. + +32 +00:01:10,000 --> 00:01:13,000 +I was expecting a output on the page, + +33 +00:01:13,000 --> 00:01:16,000 +but it is giving me a download. + +34 +00:01:16,000 --> 00:01:18,000 +But if you really think about this download, + +35 +00:01:18,000 --> 00:01:22,000 +this is actually a file which has your JSP content. + +36 +00:01:22,000 --> 00:01:26,000 +So if you see this is the page which we are getting, + +37 +00:01:26,000 --> 00:01:29,000 +I don't want page, I want output, what's happening here? + +38 +00:01:29,000 --> 00:01:31,000 +So we'll talk about what is happening in some time. + +39 +00:01:31,000 --> 00:01:33,000 +It is not working the way we wanted, + +40 +00:01:33,000 --> 00:01:38,000 +but at least we are able to call this home. + +41 +00:01:38,000 --> 00:01:41,000 +This is working, right? So we have reached to this point + +42 +00:01:41,000 --> 00:01:43,000 +where we are able to call a particular method, + +43 +00:01:43,000 --> 00:01:45,000 +depend upon the mapping. + +44 +00:01:45,000 --> 00:01:47,000 +And request mapping is not the only method we have. + +45 +00:01:47,000 --> 00:01:48,000 +So apart from RequestMapping, + +46 +00:01:48,000 --> 00:01:50,000 +we also have GetMapping, PostMapping. + +47 +00:01:50,000 --> 00:01:52,000 +We'll see that later. + +48 +00:01:52,000 --> 00:01:54,000 +So if I say, I'll show you just a method name, + +49 +00:01:54,000 --> 00:01:57,000 +like we got GetMapping, PostMapping, + +50 +00:01:57,000 --> 00:01:59,000 +so we'll see that when to use what. + +51 +00:01:59,000 --> 00:02:01,000 +But at this point we're using RequestMapping + +52 +00:02:01,000 --> 00:02:04,000 +to map the request and is able to call the index.jsp. + +53 +00:02:04,000 --> 00:02:06,000 +Now question is no, why it's not working. + +54 +00:02:06,000 --> 00:02:09,000 +The reason it is not working is because by default, + +55 +00:02:09,000 --> 00:02:12,000 +springboard does not support JSP page. + +56 +00:02:12,000 --> 00:02:14,000 +So we have to basically convert. + +57 +00:02:14,000 --> 00:02:16,000 +So, remember we talked about conversion, + +58 +00:02:16,000 --> 00:02:18,000 +we have to convert your JSP into Servlet? + +59 +00:02:18,000 --> 00:02:22,000 +Who will do that? And that's where you need a help here. + +60 +00:02:22,000 --> 00:02:25,000 +So we have to add one more dependency to achieve that, + +61 +00:02:25,000 --> 00:02:28,000 +which is called a Tomcat Jasper. + +62 +00:02:28,000 --> 00:02:32,000 +So I will go to my browser and go to your MEN repository + +63 +00:02:32,000 --> 00:02:35,000 +and search for Tomcat Jasper. + +64 +00:02:35,000 --> 00:02:37,000 +This is the library which we want. + +65 +00:02:37,000 --> 00:02:41,000 +So if you click on this, okay, which one, which version? + +66 +00:02:41,000 --> 00:02:44,000 +Now this depend upon which version you're using + +67 +00:02:44,000 --> 00:02:45,000 +for your Tomcat. + +68 +00:02:45,000 --> 00:02:48,000 +So if you scroll down, the Tomcat version, + +69 +00:02:48,000 --> 00:02:51,000 +which we're using is 10.1.16. + +70 +00:02:51,000 --> 00:02:56,000 +Let's use the same one, which is here, click on this, + +71 +00:02:56,000 --> 00:02:57,000 +you need this dependency. + +72 +00:02:57,000 --> 00:03:01,000 +Go back, page it here. I don't want this advertisement. + +73 +00:03:02,000 --> 00:03:05,000 +Okay, let's import this particular package. + +74 +00:03:05,000 --> 00:03:07,000 +Reload your Maven. And that's done. + +75 +00:03:07,000 --> 00:03:10,000 +We got this dependency and I hope this time it'll work. + +76 +00:03:10,000 --> 00:03:13,000 +So if you go back to your browser now, go back + +77 +00:03:13,000 --> 00:03:15,000 +to your homepage, which was not working. + +78 +00:03:15,000 --> 00:03:20,000 +Let's do localhost:8080, enter, and boom, + +79 +00:03:20,000 --> 00:03:22,000 +you got the output, which is hello world. + +80 +00:03:22,000 --> 00:03:23,000 +This time it is not saying download is + +81 +00:03:23,000 --> 00:03:27,000 +because now we are able to convert the JSP into Servlet + +82 +00:03:27,000 --> 00:03:28,000 +and that's what is running now. + +83 +00:03:29,000 --> 00:03:32,000 +Oh, now you're not thinking, you know, + +84 +00:03:32,000 --> 00:03:33,000 +a lot of dependencies. + +85 +00:03:33,000 --> 00:03:35,000 +See, technically we'll not be using JSP in + +86 +00:03:35,000 --> 00:03:36,000 +your actual project, right? + +87 +00:03:36,000 --> 00:03:38,000 +You'll be using some front end technologies. + +88 +00:03:38,000 --> 00:03:41,000 +That's the, that's how we are building application now. + +89 +00:03:41,000 --> 00:03:44,000 +And what you will be turning there is the data. That's it. + +90 +00:03:44,000 --> 00:03:46,000 +So at this point, we are doing a page, + +91 +00:03:46,000 --> 00:03:47,000 +but we'll see how do we return data? + +92 +00:03:47,000 --> 00:03:52,000 +Not the page, but at this point it's working, + +93 +00:03:52,000 --> 00:03:53,000 +so let's be happy with it. + +94 +00:03:53,000 --> 00:03:56,000 +And we are using request mapping to map the request. + diff --git a/12 - Spring Boot Web/010 Source-Code.url b/12 - Spring Boot Web/010 Source-Code.url new file mode 100644 index 0000000000000000000000000000000000000000..df0b1953ad13f10749ba6314b5d3bb4507f00419 --- /dev/null +++ b/12 - Spring Boot Web/010 Source-Code.url @@ -0,0 +1,2 @@ +[InternetShortcut] +URL=https://github.com/navinreddy20/spring6-course/tree/f1161e151ea06b68810b3cae03005d4955a96a8b/6%20Spring%20%20Boot%20Web/5.10%20RequestMapping \ No newline at end of file diff --git a/12 - Spring Boot Web/011 Sending data to Controller_en.srt b/12 - Spring Boot Web/011 Sending data to Controller_en.srt new file mode 100644 index 0000000000000000000000000000000000000000..ce3767013347e063bae8e403d0c470da267ae1b7 --- /dev/null +++ b/12 - Spring Boot Web/011 Sending data to Controller_en.srt @@ -0,0 +1,484 @@ +1 +00:00:00,000 --> 00:00:03,000 +(bright music) + +2 +00:00:03,000 --> 00:00:06,000 +-: So we got the homepage, which is hello world. + +3 +00:00:06,000 --> 00:00:08,000 +But then we don't want a simple page here, right? + +4 +00:00:08,000 --> 00:00:10,000 +Maybe I want to perform some operation. + +5 +00:00:10,000 --> 00:00:13,000 +See, the entire idea of having a backend + +6 +00:00:13,000 --> 00:00:16,000 +is where a user will request for something. + +7 +00:00:16,000 --> 00:00:18,000 +Maybe you want to add two numbers, simplest stuff, + +8 +00:00:18,000 --> 00:00:22,000 +or you want to find the data about something. + +9 +00:00:22,000 --> 00:00:24,000 +Or maybe you want to see the listing of a product + +10 +00:00:24,000 --> 00:00:26,000 +by the price. + +11 +00:00:26,000 --> 00:00:29,000 +So basically what you're doing is a client sends a request + +12 +00:00:29,000 --> 00:00:30,000 +for the server, server does some processing + +13 +00:00:30,000 --> 00:00:33,000 +and give something back to the client. + +14 +00:00:33,000 --> 00:00:35,000 +Now at this point, I don't don't want + +15 +00:00:35,000 --> 00:00:36,000 +to get into complex logic + +16 +00:00:36,000 --> 00:00:39,000 +because we are here to learn Spring Framework, + +17 +00:00:39,000 --> 00:00:42,000 +not to make complex logic. + +18 +00:00:42,000 --> 00:00:44,000 +And that's why we'll go for a simple example. + +19 +00:00:44,000 --> 00:00:45,000 +How do we add two numbers? + +20 +00:00:45,000 --> 00:00:48,000 +Now, why we are doing this for a simple reason, we want + +21 +00:00:48,000 --> 00:00:50,000 +to send some data to the server. + +22 +00:00:50,000 --> 00:00:53,000 +We want to ask server, Hey, you know you have + +23 +00:00:53,000 --> 00:00:54,000 +to do something for me. + +24 +00:00:54,000 --> 00:00:56,000 +Sever say, "okay, we'll do it." + +25 +00:00:56,000 --> 00:00:58,000 +Give back the data to the client. + +26 +00:00:58,000 --> 00:01:01,000 +That's the process we want to achieve. So how do we do that? + +27 +00:01:01,000 --> 00:01:03,000 +So first of all, in this homepage, I don't want + +28 +00:01:03,000 --> 00:01:05,000 +to simply print a hello world. + +29 +00:01:05,000 --> 00:01:08,000 +Maybe I want to add two numbers and to achieve that, + +30 +00:01:08,000 --> 00:01:11,000 +first of all, you need a page where you can add two numbers. + +31 +00:01:11,000 --> 00:01:13,000 +So what I will do is I need a form here + +32 +00:01:13,000 --> 00:01:14,000 +so they can submit data. + +33 +00:01:14,000 --> 00:01:17,000 +So when I say form, it means I need two text field. + +34 +00:01:17,000 --> 00:01:20,000 +I need a button where I can click the button + +35 +00:01:20,000 --> 00:01:24,000 +and this two text field data should go to the server. + +36 +00:01:24,000 --> 00:01:26,000 +And for that we have to create a form. + +37 +00:01:26,000 --> 00:01:28,000 +Now instead of wasting our time writing the code, + +38 +00:01:28,000 --> 00:01:30,000 +I do have the code with me. + +39 +00:01:30,000 --> 00:01:31,000 +So that's our simple form. + +40 +00:01:31,000 --> 00:01:35,000 +You can see I'm using a label for enter the first number, + +41 +00:01:35,000 --> 00:01:37,000 +and then we have a text typed + +42 +00:01:37,000 --> 00:01:40,000 +or text box you can say, which is a typed text + +43 +00:01:40,000 --> 00:01:42,000 +and it takes a number. + +44 +00:01:42,000 --> 00:01:43,000 +And the ID for that is num1, + +45 +00:01:43,000 --> 00:01:45,000 +because these ID are important. + +46 +00:01:45,000 --> 00:01:48,000 +And then the ID for the second one is num2. + +47 +00:01:48,000 --> 00:01:51,000 +And then we have a button there which is called submit. + +48 +00:01:51,000 --> 00:01:53,000 +And maybe I just want to change this from hello world + +49 +00:01:53,000 --> 00:01:56,000 +to Telusko Calculator. + +50 +00:01:56,000 --> 00:02:00,000 +That's it. Nothing fancy, just a simple page here. + +51 +00:02:00,000 --> 00:02:02,000 +And now let me restart this + +52 +00:02:02,000 --> 00:02:04,000 +just to see if I can get this page. + +53 +00:02:04,000 --> 00:02:06,000 +Is it looking good on the screen? + +54 +00:02:06,000 --> 00:02:10,000 +So go back to your browser and say refresh, take some time + +55 +00:02:10,000 --> 00:02:11,000 +and you can see we got a calculator. + +56 +00:02:11,000 --> 00:02:12,000 +Not looking good. + +57 +00:02:12,000 --> 00:02:13,000 +But again, we are not here + +58 +00:02:13,000 --> 00:02:16,000 +to make some beautiful things, right? + +59 +00:02:16,000 --> 00:02:18,000 +I mean we want to make beautiful things, + +60 +00:02:18,000 --> 00:02:20,000 +but not in the front end, in the back end. + +61 +00:02:20,000 --> 00:02:21,000 +But still it doesn't look good, right? + +62 +00:02:21,000 --> 00:02:23,000 +Let's have something here. + +63 +00:02:23,000 --> 00:02:25,000 +So what I will do is I will create a CSS file here + +64 +00:02:27,000 --> 00:02:28,000 +just to style this stuff. + +65 +00:02:28,000 --> 00:02:30,000 +Let me create a CSS file here. + +66 +00:02:30,000 --> 00:02:33,000 +So I'll say style.css. + +67 +00:02:33,000 --> 00:02:38,000 +And in this style.css, I want to have some CSS code. + +68 +00:02:38,000 --> 00:02:40,000 +And again, I'm not here to teach you CSS. + +69 +00:02:40,000 --> 00:02:43,000 +So let me just get some CSS file here + +70 +00:02:43,000 --> 00:02:45,000 +just to make our page beautiful. + +71 +00:02:45,000 --> 00:02:48,000 +And we have to also make sure that we use the CSS here. + +72 +00:02:48,000 --> 00:02:51,000 +So I'll put that in the head tag + +73 +00:02:51,000 --> 00:02:53,000 +and we have to provide the link for the CSS + +74 +00:02:53,000 --> 00:02:55,000 +and let me do that here. + +75 +00:02:55,000 --> 00:02:56,000 +So basically by doing this, + +76 +00:02:56,000 --> 00:03:00,000 +what we are doing is we are having a CSS in the code so + +77 +00:03:00,000 --> 00:03:03,000 +that it'll make the page bit beautiful, not very beautiful + +78 +00:03:03,000 --> 00:03:06,000 +because we tried to use some Java theme, coffee theme + +79 +00:03:06,000 --> 00:03:08,000 +here with the CSS. + +80 +00:03:08,000 --> 00:03:09,000 +Let's see if that works out. + +81 +00:03:09,000 --> 00:03:12,000 +Let's run this and taking some time. + +82 +00:03:12,000 --> 00:03:15,000 +Okay, so you got a page here. + +83 +00:03:15,000 --> 00:03:17,000 +Not great looking but manageable, right? + +84 +00:03:17,000 --> 00:03:20,000 +So we've got a page and I can provide some numbers here. + +85 +00:03:20,000 --> 00:03:22,000 +So let's say I want to add six and seven, + +86 +00:03:22,000 --> 00:03:26,000 +and the output I want here is 13. + +87 +00:03:26,000 --> 00:03:27,000 +Now of course we will say, Hey, we can do that + +88 +00:03:27,000 --> 00:03:28,000 +with simple JavaScript, right? + +89 +00:03:28,000 --> 00:03:31,000 +We can write a client site code, add this to number, + +90 +00:03:31,000 --> 00:03:32,000 +see we can do whatever we want. + +91 +00:03:32,000 --> 00:03:36,000 +We can simply take a mobile phone, get a open the calculator + +92 +00:03:36,000 --> 00:03:37,000 +and add this two numbers. + +93 +00:03:37,000 --> 00:03:38,000 +Not the main thing here. + +94 +00:03:38,000 --> 00:03:40,000 +The main thing is what if I want + +95 +00:03:40,000 --> 00:03:43,000 +to build a Spring application where the client sends data + +96 +00:03:43,000 --> 00:03:45,000 +to the server and you want to perform some operation. + +97 +00:03:45,000 --> 00:03:49,000 +So when I click on submit here, I want this to work. + +98 +00:03:49,000 --> 00:03:52,000 +And you can, you can see at this point it says 4 0 4. + +99 +00:03:52,000 --> 00:03:54,000 +So basically your server is not happy by saying, hey, + +100 +00:03:54,000 --> 00:03:57,000 +you know, you're sending some request + +101 +00:03:57,000 --> 00:03:59,000 +and I don't have any idea what you want me to do. + +102 +00:03:59,000 --> 00:04:02,000 +I would say, okay, it's not very complex. + +103 +00:04:02,000 --> 00:04:04,000 +If someone sends request for the add. + +104 +00:04:04,000 --> 00:04:06,000 +Now you can see when you say submit it, + +105 +00:04:06,000 --> 00:04:08,000 +you're sending a request for the add URL. + +106 +00:04:09,000 --> 00:04:12,000 +And if you observe the URL here, which is not visible + +107 +00:04:12,000 --> 00:04:14,000 +by default in Safari, + +108 +00:04:14,000 --> 00:04:15,000 +but you can see we got a URL here, + +109 +00:04:15,000 --> 00:04:19,000 +it says localized:8080/add. + +110 +00:04:19,000 --> 00:04:21,000 +Then we are passing two values. + +111 +00:04:21,000 --> 00:04:23,000 +So in the URL itself, we are passing the values. + +112 +00:04:23,000 --> 00:04:26,000 +Number one value is six, and num two value is seven. + +113 +00:04:26,000 --> 00:04:29,000 +And the URL and the request we're sending is for the add. + +114 +00:04:29,000 --> 00:04:31,000 +Okay? Initially we were sending the request + +115 +00:04:31,000 --> 00:04:32,000 +for the homepage, but now we are sending the + +116 +00:04:32,000 --> 00:04:33,000 +request for the add. + +117 +00:04:33,000 --> 00:04:34,000 +Okay. + +118 +00:04:34,000 --> 00:04:36,000 +That means we need a controller + +119 +00:04:36,000 --> 00:04:38,000 +who can accept this request. + +120 +00:04:38,000 --> 00:04:41,000 +Now question arise how we look, create that controller. + +121 +00:04:41,000 --> 00:04:42,000 +Let's see that in the next video. + diff --git a/12 - Spring Boot Web/011 Source-Code.url b/12 - Spring Boot Web/011 Source-Code.url new file mode 100644 index 0000000000000000000000000000000000000000..1d8953f18b5268b8965d6064c21123c1a8687c6c --- /dev/null +++ b/12 - Spring Boot Web/011 Source-Code.url @@ -0,0 +1,2 @@ +[InternetShortcut] +URL=https://github.com/navinreddy20/spring6-course/tree/f1161e151ea06b68810b3cae03005d4955a96a8b/6%20Spring%20%20Boot%20Web/5.11%20Sending%20data%20to%20Controller \ No newline at end of file diff --git a/12 - Spring Boot Web/012 Accepting Data the servlet way_en.srt b/12 - Spring Boot Web/012 Accepting Data the servlet way_en.srt new file mode 100644 index 0000000000000000000000000000000000000000..76a68f00186798377d21d9bd8e36ec7251f8d32e --- /dev/null +++ b/12 - Spring Boot Web/012 Accepting Data the servlet way_en.srt @@ -0,0 +1,744 @@ +1 +00:00:00,000 --> 00:00:03,000 +(soft music) + +2 +00:00:03,000 --> 00:00:06,000 +-: Now, let's try to create a controller + +3 +00:00:06,000 --> 00:00:08,000 +which can accept this request. + +4 +00:00:08,000 --> 00:00:09,000 +Because if you see the HomeController. + +5 +00:00:09,000 --> 00:00:13,000 +Of course, we can create a new controller here, a new class, + +6 +00:00:13,000 --> 00:00:16,000 +but then Spring allows you to have multiple controllers + +7 +00:00:16,000 --> 00:00:17,000 +in one controller. + +8 +00:00:17,000 --> 00:00:18,000 +So what I'm saying is + +9 +00:00:18,000 --> 00:00:21,000 +Spring allows you to have multiple requests + +10 +00:00:21,000 --> 00:00:24,000 +mapped in one particular controller. + +11 +00:00:24,000 --> 00:00:26,000 +And logically, if you have different types of controllers, + +12 +00:00:26,000 --> 00:00:28,000 +let's say you have different types of requests. + +13 +00:00:28,000 --> 00:00:30,000 +So if you're making an e-commerce website + +14 +00:00:30,000 --> 00:00:34,000 +and you want to request for user, so user addition, + +15 +00:00:34,000 --> 00:00:38,000 +or maybe adding a user, deleting a user, or updating a user, + +16 +00:00:38,000 --> 00:00:40,000 +so everything that deals with the user, + +17 +00:00:40,000 --> 00:00:41,000 +you can put that in one controller. + +18 +00:00:41,000 --> 00:00:44,000 +Maybe you can have the controller for products + +19 +00:00:44,000 --> 00:00:46,000 +where you can add a product, remove a product, + +20 +00:00:46,000 --> 00:00:48,000 +update a product. + +21 +00:00:48,000 --> 00:00:51,000 +You can also have a controller for orders, place the order, + +22 +00:00:51,000 --> 00:00:54,000 +delete the order, change the status of the order. + +23 +00:00:54,000 --> 00:00:57,000 +So you can have that in the OrderController. + +24 +00:00:57,000 --> 00:00:59,000 +But here, since we only have two controls now, + +25 +00:00:59,000 --> 00:01:02,000 +let's work with the same HomeController. + +26 +00:01:02,000 --> 00:01:02,000 +So what I will do is, + +27 +00:01:02,000 --> 00:01:05,000 +if you want to have something that will accept the request, + +28 +00:01:05,000 --> 00:01:06,000 +you have to create another method. + +29 +00:01:06,000 --> 00:01:09,000 +So at this point, I will say public String + +30 +00:01:09,000 --> 00:01:12,000 +because maybe I want to return a page, of course, right? + +31 +00:01:12,000 --> 00:01:15,000 +When you add two numbers, you also want a page, + +32 +00:01:15,000 --> 00:01:17,000 +and that's what you're expecting in the browser. + +33 +00:01:17,000 --> 00:01:20,000 +So if you see in the output, when you send this request, + +34 +00:01:20,000 --> 00:01:23,000 +this should be another page. + +35 +00:01:23,000 --> 00:01:24,000 +Okay, so that means I have to return something, + +36 +00:01:24,000 --> 00:01:26,000 +and then we can have a method name. + +37 +00:01:26,000 --> 00:01:28,000 +Method name can be anything. I will say add here + +38 +00:01:28,000 --> 00:01:30,000 +and open bracket close. + +39 +00:01:30,000 --> 00:01:33,000 +Okay, now here, I want to return the name of a page. + +40 +00:01:33,000 --> 00:01:34,000 +So what's should be the name of the page? + +41 +00:01:34,000 --> 00:01:36,000 +I will simply say return. + +42 +00:01:36,000 --> 00:01:38,000 +We can return any page name. + +43 +00:01:38,000 --> 00:01:42,000 +I will say return "result.jsp". + +44 +00:01:42,000 --> 00:01:44,000 +And, okay, that's done. + +45 +00:01:44,000 --> 00:01:45,000 +But then will it be getting called? + +46 +00:01:45,000 --> 00:01:47,000 +Of course not. + +47 +00:01:47,000 --> 00:01:49,000 +So basically, we have to map it. + +48 +00:01:49,000 --> 00:01:50,000 +Now how do you map it? + +49 +00:01:50,000 --> 00:01:53,000 +Of course, for mapping, we can use @RequestMapping. + +50 +00:01:53,000 --> 00:01:56,000 +And then in the bracket, we can mention the URL. + +51 +00:01:56,000 --> 00:02:01,000 +The URL for this is add, because if you see on the homepage, + +52 +00:02:01,000 --> 00:02:04,000 +we are saying, "This is my website name, + +53 +00:02:04,000 --> 00:02:09,000 +and then this is the URL," the URL path basically, + +54 +00:02:09,000 --> 00:02:10,000 +and that's what you have to mention. + +55 +00:02:10,000 --> 00:02:11,000 +This is for the add request, + +56 +00:02:11,000 --> 00:02:13,000 +and this method should be called. + +57 +00:02:13,000 --> 00:02:14,000 +Is it really working? + +58 +00:02:14,000 --> 00:02:15,000 +Let's try. + +59 +00:02:15,000 --> 00:02:17,000 +So what I will do is, before making any changes, + +60 +00:02:17,000 --> 00:02:19,000 +let's rerun this and see the output. + +61 +00:02:19,000 --> 00:02:21,000 +Go back to your browser, + +62 +00:02:21,000 --> 00:02:23,000 +and I will just say "Submit" once again, + +63 +00:02:23,000 --> 00:02:27,000 +because I have not made any changes in the index.jsp. + +64 +00:02:27,000 --> 00:02:30,000 +I will click on "Submit," and we got an error. + +65 +00:02:30,000 --> 00:02:32,000 +It may not be able to find it, + +66 +00:02:32,000 --> 00:02:34,000 +or maybe I will just refresh the page. + +67 +00:02:37,000 --> 00:02:39,000 +Is the mapping happening? + +68 +00:02:39,000 --> 00:02:40,000 +Maybe it is happening, + +69 +00:02:40,000 --> 00:02:42,000 +or maybe it is searching for result.jsp. + +70 +00:02:42,000 --> 00:02:44,000 +Not able to find it the result.jsp. + +71 +00:02:44,000 --> 00:02:45,000 +To prove that or to check that, + +72 +00:02:45,000 --> 00:02:49,000 +we can say "in add" just to see if this is working. + +73 +00:02:49,000 --> 00:02:50,000 +You know, we should always go step by step; + +74 +00:02:50,000 --> 00:02:53,000 +otherwise, we are not sure at what point we got the error. + +75 +00:02:53,000 --> 00:02:55,000 +So I'm just saying "in add" now. + +76 +00:02:55,000 --> 00:02:59,000 +Let's go back here and say "Submit," + +77 +00:03:00,000 --> 00:03:02,000 +and you can see in this it says "in add." + +78 +00:03:02,000 --> 00:03:05,000 +So that means, yes, we are able to call this. + +79 +00:03:05,000 --> 00:03:08,000 +But now, it's not just about calling this, right? + +80 +00:03:08,000 --> 00:03:10,000 +Basically, it's not able to find result.jsp. + +81 +00:03:10,000 --> 00:03:14,000 +Do we have result.jsp in the file, or we don't yet? + +82 +00:03:14,000 --> 00:03:15,000 +So let me create a file, + +83 +00:03:15,000 --> 00:03:18,000 +or maybe I will just copy-paste this index.jsp here + +84 +00:03:18,000 --> 00:03:21,000 +with a different name: result.jsp. + +85 +00:03:21,000 --> 00:03:24,000 +And we don't need a form here, okay? + +86 +00:03:24,000 --> 00:03:26,000 +What we need is to print something. + +87 +00:03:26,000 --> 00:03:30,000 +So I'll print "Result is." + +88 +00:03:30,000 --> 00:03:30,000 +That's it. + +89 +00:03:30,000 --> 00:03:32,000 +Nothing fancy, I'm just saying "Result is." + +90 +00:03:32,000 --> 00:03:34,000 +If I refresh, you can see it says "Result is." + +91 +00:03:34,000 --> 00:03:36,000 +So it is able to find the page now, + +92 +00:03:36,000 --> 00:03:37,000 +but we are not printing anything. + +93 +00:03:37,000 --> 00:03:40,000 +So what is happening is, when you send the first request, + +94 +00:03:40,000 --> 00:03:41,000 +the request goes to the homepage. + +95 +00:03:41,000 --> 00:03:43,000 +It is bringing index.jsp. + +96 +00:03:43,000 --> 00:03:47,000 +From index.jsp, you are basically sending an add request, + +97 +00:03:47,000 --> 00:03:48,000 +and the add request says, + +98 +00:03:48,000 --> 00:03:50,000 +"Okay, we have to call result.jsp." + +99 +00:03:50,000 --> 00:03:53,000 +But the question arise, who is doing this mapping? + +100 +00:03:53,000 --> 00:03:54,000 +If you go back to servlets, + +101 +00:03:54,000 --> 00:03:55,000 +remember, for every servlet + +102 +00:03:55,000 --> 00:03:58,000 +we have to do the mapping in the XML file. + +103 +00:03:58,000 --> 00:04:01,000 +We are not doing mapping here, so who is calling it? + +104 +00:04:01,000 --> 00:04:03,000 +So the thing is, there's something called DispatcherServlet. + +105 +00:04:03,000 --> 00:04:05,000 +Again, we will not be discussing much + +106 +00:04:05,000 --> 00:04:06,000 +about DispatcherServlet now. + +107 +00:04:06,000 --> 00:04:07,000 +We will be talking about that later. + +108 +00:04:07,000 --> 00:04:09,000 +But there is DispatcherServlet + +109 +00:04:09,000 --> 00:04:11,000 +who is responsible for mapping all these requests. + +110 +00:04:11,000 --> 00:04:13,000 +So it sees, "Okay, what is the request? + +111 +00:04:13,000 --> 00:04:15,000 +This is the request, call this method. + +112 +00:04:15,000 --> 00:04:17,000 +This is the request, call this method. + +113 +00:04:17,000 --> 00:04:19,000 +Someone is returning index.jsp, search for it." + +114 +00:04:19,000 --> 00:04:22,000 +So that's the job of DispatcherServlet. + +115 +00:04:22,000 --> 00:04:23,000 +Again, we will discuss that later. + +116 +00:04:23,000 --> 00:04:25,000 +But yeah, it is able to call it. + +117 +00:04:25,000 --> 00:04:27,000 +Okay, so that's the step one. + +118 +00:04:27,000 --> 00:04:30,000 +The next step is, basically, we have to accept the values. + +119 +00:04:30,000 --> 00:04:34,000 +Remember, in the browser, we are sending these values. + +120 +00:04:34,000 --> 00:04:36,000 +We have to accept them. + +121 +00:04:36,000 --> 00:04:37,000 +How will you do that? + +122 +00:04:37,000 --> 00:04:38,000 +See there are two ways of doing it: + +123 +00:04:38,000 --> 00:04:41,000 +one is the servlet way, and the second is the Spring way. + +124 +00:04:41,000 --> 00:04:43,000 +Let's start with the servlet way, + +125 +00:04:43,000 --> 00:04:44,000 +and then we'll move towards the Spring way. + +126 +00:04:44,000 --> 00:04:48,000 +In servlet, if you want to accept the data from a client, + +127 +00:04:48,000 --> 00:04:51,000 +we have to use something called HttpServletRequest. + +128 +00:04:51,000 --> 00:04:53,000 +We have done that before as well, right? + +129 +00:04:53,000 --> 00:04:57,000 +So in this bracket, I can simply say HttpServletRequest. + +130 +00:04:58,000 --> 00:04:59,000 +I can create the object, + +131 +00:04:59,000 --> 00:05:02,000 +or I can create a reference called req. + +132 +00:05:02,000 --> 00:05:03,000 +Now, the question arises, + +133 +00:05:03,000 --> 00:05:05,000 +who is responsible for giving this object? + +134 +00:05:05,000 --> 00:05:08,000 +Mind you, we are working on the Spring Framework. + +135 +00:05:08,000 --> 00:05:11,000 +So when you specify the HttpServletRequest here, + +136 +00:05:11,000 --> 00:05:13,000 +it is Spring's responsibility + +137 +00:05:13,000 --> 00:05:15,000 +to assign you the object for this. + +138 +00:05:15,000 --> 00:05:17,000 +You just say, "I want this request object." + +139 +00:05:17,000 --> 00:05:18,000 +Spring says, "Okay, done." + +140 +00:05:18,000 --> 00:05:20,000 +Now once you have this object, you can get the values. + +141 +00:05:20,000 --> 00:05:22,000 +How will you get the values? + +142 +00:05:22,000 --> 00:05:24,000 +You can say req.getParameter. + +143 +00:05:24,000 --> 00:05:25,000 +So that's the method you have to use + +144 +00:05:25,000 --> 00:05:27,000 +to get the value from the request object. + +145 +00:05:27,000 --> 00:05:28,000 +Because, see, anyway, + +146 +00:05:28,000 --> 00:05:30,000 +when a client sends a request to the server, + +147 +00:05:30,000 --> 00:05:31,000 +the request object will have all the data. + +148 +00:05:31,000 --> 00:05:33,000 +So we just have to fetch the data. + +149 +00:05:33,000 --> 00:05:34,000 +So you have to say getParameter. + +150 +00:05:34,000 --> 00:05:36,000 +But for which value? + +151 +00:05:36,000 --> 00:05:39,000 +In the browser, if you see, we have num1 and num2. + +152 +00:05:39,000 --> 00:05:41,000 +So we got two parameters. + +153 +00:05:41,000 --> 00:05:45,000 +I will say num1, but then this will be a type of String. + +154 +00:05:45,000 --> 00:05:47,000 +If you try to assign that to a variable. + +155 +00:05:47,000 --> 00:05:49,000 +So let's say you have int num1 here. + +156 +00:05:49,000 --> 00:05:51,000 +So of course, this will not work + +157 +00:05:51,000 --> 00:05:53,000 +because the getParameter returns a String. + +158 +00:05:53,000 --> 00:05:54,000 +So we have to basically convert this. + +159 +00:05:54,000 --> 00:05:57,000 +You have to parse it with the Integer.parseInt. + +160 +00:05:57,000 --> 00:05:58,000 +That's done. + +161 +00:05:58,000 --> 00:06:00,000 +And we need this for the second variable as well. + +162 +00:06:00,000 --> 00:06:02,000 +So I will just copy this, paste it here, + +163 +00:06:02,000 --> 00:06:04,000 +and this should be num2. + +164 +00:06:04,000 --> 00:06:05,000 +This should be num2. + +165 +00:06:05,000 --> 00:06:08,000 +Now, by doing this, we are getting the values, + +166 +00:06:08,000 --> 00:06:10,000 +and then we just have to add them. + +167 +00:06:10,000 --> 00:06:14,000 +So I will say int result = num1 + num2. + +168 +00:06:14,000 --> 00:06:16,000 +Again, the logic can be anything, right? + +169 +00:06:16,000 --> 00:06:17,000 +So whatever logic you have, + +170 +00:06:17,000 --> 00:06:19,000 +you can write inside this method, + +171 +00:06:19,000 --> 00:06:21,000 +and that's what we're doing here. + +172 +00:06:21,000 --> 00:06:23,000 +Once you've got this value, your job is done, right? + +173 +00:06:23,000 --> 00:06:26,000 +You got the values, you are adding them. + +174 +00:06:26,000 --> 00:06:29,000 +At this point, I will just print the result in the console. + +175 +00:06:29,000 --> 00:06:31,000 +So here, this is where I want to print it. + +176 +00:06:31,000 --> 00:06:32,000 +So I will just restart this + +177 +00:06:32,000 --> 00:06:35,000 +and see if I can actually get the values. + +178 +00:06:35,000 --> 00:06:37,000 +So I'll go back here and say "Submit." + +179 +00:06:37,000 --> 00:06:40,000 +Okay, it says "Result is," but we are not printing it here; + +180 +00:06:40,000 --> 00:06:41,000 +we are printing it on the console. + +181 +00:06:41,000 --> 00:06:42,000 +And the console says 13. + +182 +00:06:42,000 --> 00:06:44,000 +So 6 + 7 = 13, and it's working. + +183 +00:06:44,000 --> 00:06:46,000 +But then I don't want to print on the console, right? + +184 +00:06:46,000 --> 00:06:48,000 +I want to print it on the page. + +185 +00:06:48,000 --> 00:06:49,000 +How will you do that? + +186 +00:06:49,000 --> 00:06:51,000 +Let's see that in the next video. + diff --git a/12 - Spring Boot Web/012 Source-Code.url b/12 - Spring Boot Web/012 Source-Code.url new file mode 100644 index 0000000000000000000000000000000000000000..d9fad9771d431541cb960c3964fbabe06c1fdc6f --- /dev/null +++ b/12 - Spring Boot Web/012 Source-Code.url @@ -0,0 +1,2 @@ +[InternetShortcut] +URL=https://github.com/navinreddy20/spring6-course/tree/f1161e151ea06b68810b3cae03005d4955a96a8b/6%20Spring%20%20Boot%20Web/5.12%20Accepting%20Data%20the%20servlet%20way \ No newline at end of file diff --git a/12 - Spring Boot Web/013 Display Data on Result Page_en.srt b/12 - Spring Boot Web/013 Display Data on Result Page_en.srt new file mode 100644 index 0000000000000000000000000000000000000000..4eff8f9d6c7ecd98b3b8734302b943bfe92405a2 --- /dev/null +++ b/12 - Spring Boot Web/013 Display Data on Result Page_en.srt @@ -0,0 +1,540 @@ +1 +00:00:00,000 --> 00:00:02,000 +(upbeat music) + +2 +00:00:02,000 --> 00:00:06,000 +-: Okay, now we are printing the data on the console. + +3 +00:00:06,000 --> 00:00:09,000 +We don't do that, we want to print this on the result page. + +4 +00:00:09,000 --> 00:00:11,000 +To do that, first of all, + +5 +00:00:11,000 --> 00:00:13,000 +we have to send this data to the result page. + +6 +00:00:13,000 --> 00:00:15,000 +How will you do that, see, there are multiple ways + +7 +00:00:15,000 --> 00:00:17,000 +of sending this data to the result page. + +8 +00:00:17,000 --> 00:00:19,000 +Of course, you cannot simply expect + +9 +00:00:19,000 --> 00:00:22,000 +that this data will be available in this page. + +10 +00:00:22,000 --> 00:00:24,000 +You have to send it, there are multiple ways + +11 +00:00:24,000 --> 00:00:26,000 +you can basically pass through the URL. + +12 +00:00:26,000 --> 00:00:28,000 +You can put a question mark here + +13 +00:00:28,000 --> 00:00:30,000 +and you can say the result is this, + +14 +00:00:30,000 --> 00:00:33,000 +or you can use something called session. + +15 +00:00:33,000 --> 00:00:36,000 +So in servlet, basically we have a concept of session. + +16 +00:00:36,000 --> 00:00:38,000 +I mean when I say servlet, it is also applicable for spring + +17 +00:00:38,000 --> 00:00:41,000 +because behind the scene everything is servlet. + +18 +00:00:41,000 --> 00:00:46,000 +So we have to put the data in a session object. + +19 +00:00:46,000 --> 00:00:48,000 +Now what your session, so basically when you have multiple + +20 +00:00:48,000 --> 00:00:51,000 +pages and if a user is accessing multiple pages, + +21 +00:00:51,000 --> 00:00:55,000 +you want to maintain this data between the pages. + +22 +00:00:55,000 --> 00:00:57,000 +And the way you can do that is with the help of session + +23 +00:00:57,000 --> 00:00:59,000 +and to get the hold on a session, + +24 +00:00:59,000 --> 00:01:01,000 +what you can do is you can just + +25 +00:01:01,000 --> 00:01:03,000 +pass this session object here. + +26 +00:01:03,000 --> 00:01:05,000 +So you can create a HttpSession. + +27 +00:01:07,000 --> 00:01:10,000 +Now we just specify, so this is an interface. + +28 +00:01:10,000 --> 00:01:12,000 +If you click on HttpSession, this is an interface + +29 +00:01:12,000 --> 00:01:14,000 +and we are creating a reference for it. + +30 +00:01:14,000 --> 00:01:17,000 +Now who is responsible to inject the object? + +31 +00:01:17,000 --> 00:01:18,000 +You know it, spring framework. + +32 +00:01:18,000 --> 00:01:22,000 +Now with the object, I just have to add this data, + +33 +00:01:22,000 --> 00:01:25,000 +visual data in the session. + +34 +00:01:25,000 --> 00:01:28,000 +So the way you can do that is by saying session dot. + +35 +00:01:28,000 --> 00:01:31,000 +So it has a method called set attribute. + +36 +00:01:31,000 --> 00:01:32,000 +And in this you have to pass two things. + +37 +00:01:32,000 --> 00:01:35,000 +The name of a variable or name of the data, which result, + +38 +00:01:35,000 --> 00:01:38,000 +and the actual data which is result. + +39 +00:01:38,000 --> 00:01:40,000 +So basically you have to do, you have to pass two things. + +40 +00:01:40,000 --> 00:01:43,000 +One is the name and second is the data. + +41 +00:01:43,000 --> 00:01:46,000 +So name is result and the data is result, + +42 +00:01:46,000 --> 00:01:47,000 +which is the value in this case. + +43 +00:01:47,000 --> 00:01:51,000 +And that's it, so when you call result JSP, + +44 +00:01:51,000 --> 00:01:52,000 +and see we talked about it, right? + +45 +00:01:52,000 --> 00:01:56,000 +So when you call add, the dispatcher is calling result JSP. + +46 +00:01:56,000 --> 00:01:58,000 +So that means that there's two different pages. + +47 +00:01:58,000 --> 00:02:00,000 +So we have to maintain this data. + +48 +00:02:00,000 --> 00:02:03,000 +The way we can do that is with help of session. + +49 +00:02:03,000 --> 00:02:06,000 +So we are adding this data in the session object. + +50 +00:02:06,000 --> 00:02:09,000 +Okay, we have done that right now, we have added it. + +51 +00:02:09,000 --> 00:02:11,000 +How will you get this data in the result page? + +52 +00:02:11,000 --> 00:02:14,000 +Now that's tricky, so what you can do is here, + +53 +00:02:14,000 --> 00:02:17,000 +you can print, in fact you can print it here itself. + +54 +00:02:17,000 --> 00:02:21,000 +You can print the data, you can simply say result, + +55 +00:02:21,000 --> 00:02:22,000 +but will it work? + +56 +00:02:22,000 --> 00:02:24,000 +Of course not, right, this look like a normal text. + +57 +00:02:24,000 --> 00:02:28,000 +How will your JSP knows that this is not a simple text. + +58 +00:02:28,000 --> 00:02:30,000 +This is actually a variable. + +59 +00:02:30,000 --> 00:02:33,000 +And to do that we have to make sure that we put + +60 +00:02:33,000 --> 00:02:36,000 +that into JSP code. + +61 +00:02:36,000 --> 00:02:39,000 +So whenever you want to write a Java code inside JSP, + +62 +00:02:39,000 --> 00:02:40,000 +you have to open the angular bracket. + +63 +00:02:40,000 --> 00:02:42,000 +Then percentage, then percentage, angular bracket. + +64 +00:02:42,000 --> 00:02:43,000 +This is how we write the Java code. + +65 +00:02:43,000 --> 00:02:46,000 +Now in between you can write whatever code you want + +66 +00:02:46,000 --> 00:02:48,000 +and we don't want any code. + +67 +00:02:48,000 --> 00:02:52,000 +What we want is we have to say session get attribute. + +68 +00:02:52,000 --> 00:02:54,000 +And in bracket you have to mention the name + +69 +00:02:54,000 --> 00:02:55,000 +of a variable which is result here. + +70 +00:02:55,000 --> 00:02:57,000 +So we have to say session get attribute + +71 +00:02:57,000 --> 00:03:00,000 +and name of our variable + +72 +00:03:00,000 --> 00:03:02,000 +or the name of the data which result in this case. + +73 +00:03:02,000 --> 00:03:04,000 +Now the question arise, how will you get this session? + +74 +00:03:04,000 --> 00:03:05,000 +Object because in servlet + +75 +00:03:05,000 --> 00:03:08,000 +or here we are injecting the object right? + +76 +00:03:08,000 --> 00:03:10,000 +Now that's the beauty about JSP. + +77 +00:03:10,000 --> 00:03:12,000 +JSP gives you this object by default. + +78 +00:03:12,000 --> 00:03:14,000 +So you don't have to create this object. + +79 +00:03:14,000 --> 00:03:16,000 +JSP says, session is yours, request is yours. + +80 +00:03:16,000 --> 00:03:19,000 +You just use the object, it's available behind the scene. + +81 +00:03:19,000 --> 00:03:21,000 +So we got a session object, we are saying get attribute + +82 +00:03:21,000 --> 00:03:25,000 +and we are printing or we are getting the data of result. + +83 +00:03:25,000 --> 00:03:27,000 +And that's what you're going to display on the page. + +84 +00:03:27,000 --> 00:03:30,000 +And now let's see if this works, let's read on this. + +85 +00:03:30,000 --> 00:03:31,000 +Go back to your browser + +86 +00:03:31,000 --> 00:03:33,000 +and I will just refresh this + +87 +00:03:33,000 --> 00:03:38,000 +with a different value this time, let's say 7 and 88. + +88 +00:03:38,000 --> 00:03:41,000 +Let's click on submit and we got an error. + +89 +00:03:41,000 --> 00:03:44,000 +The error is internal servlet error 500. + +90 +00:03:44,000 --> 00:03:49,000 +Let's see what happened here, and I love errors. + +91 +00:03:49,000 --> 00:03:50,000 +Okay, one thing I forgot. + +92 +00:03:50,000 --> 00:03:53,000 +It's just that when you, I mean you can write the code here, + +93 +00:03:53,000 --> 00:03:55,000 +but then when you want the value of it, + +94 +00:03:55,000 --> 00:03:56,000 +you have to put the equal to as well + +95 +00:03:56,000 --> 00:03:58,000 +because we directly want to get this value + +96 +00:03:58,000 --> 00:04:00,000 +and print it on the page. + +97 +00:04:00,000 --> 00:04:03,000 +I forgot to put the equal to symbol + +98 +00:04:05,000 --> 00:04:07,000 +now I hope it'll work. + +99 +00:04:07,000 --> 00:04:12,000 +Let's go back to the browser, say refresh. + +100 +00:04:12,000 --> 00:04:14,000 +And you can see we got the value, which is 95. + +101 +00:04:14,000 --> 00:04:16,000 +So that's how basically you can get the value, okay? + +102 +00:04:16,000 --> 00:04:18,000 +So we can use a session object to get the value. + +103 +00:04:18,000 --> 00:04:20,000 +There's one way, there's another way + +104 +00:04:20,000 --> 00:04:22,000 +where you can use the JSTL way. + +105 +00:04:22,000 --> 00:04:25,000 +JSTL is basically a JSP standard library + +106 +00:04:25,000 --> 00:04:27,000 +or template library, which allows you + +107 +00:04:27,000 --> 00:04:30,000 +to directly use some certain tags, + +108 +00:04:30,000 --> 00:04:31,000 +which you can get the value. + +109 +00:04:31,000 --> 00:04:34,000 +So we can just put the currently packets here + +110 +00:04:34,000 --> 00:04:35,000 +and we can remove everything. + +111 +00:04:35,000 --> 00:04:37,000 +And you can simply put result. + +112 +00:04:37,000 --> 00:04:38,000 +So it'll directly use, + +113 +00:04:38,000 --> 00:04:41,000 +it'll directly search this session object, + +114 +00:04:41,000 --> 00:04:42,000 +request object to get your data. + +115 +00:04:42,000 --> 00:04:44,000 +And if you have, it'll directly fetch it. + +116 +00:04:44,000 --> 00:04:47,000 +The only thing is you have to put the dollar symbol as well + +117 +00:04:47,000 --> 00:04:50,000 +by specifying, hey, this is not a normal curly packet, + +118 +00:04:50,000 --> 00:04:51,000 +this is a JSTL. + +119 +00:04:51,000 --> 00:04:54,000 +So you have to use the dollar symbol and the current package + +120 +00:04:54,000 --> 00:04:55,000 +and then you have to set result. + +121 +00:04:55,000 --> 00:04:59,000 +Now if you run this, let's see if it is changing something, + +122 +00:04:59,000 --> 00:05:02,000 +let's refresh the servlet is not started yet. + +123 +00:05:02,000 --> 00:05:04,000 +Refresh and it works. + +124 +00:05:04,000 --> 00:05:07,000 +So basically you have both the ways you can use the normal + +125 +00:05:07,000 --> 00:05:11,000 +JSP syntax or you can use the JSTL. + +126 +00:05:11,000 --> 00:05:13,000 +But this is how basically you can pass the value + +127 +00:05:13,000 --> 00:05:16,000 +between the JSP or between the servlets. + +128 +00:05:16,000 --> 00:05:20,000 +Because ultimately JSP will get converted into servlets. + +129 +00:05:20,000 --> 00:05:22,000 +But one thing here, I mean this works, + +130 +00:05:22,000 --> 00:05:23,000 +but it doesn't look good. + +131 +00:05:23,000 --> 00:05:26,000 +We are working on spring framework, right? + +132 +00:05:26,000 --> 00:05:29,000 +This is okay, but can you just simplify this? + +133 +00:05:29,000 --> 00:05:32,000 +And that's the beauty about spring, right? + +134 +00:05:32,000 --> 00:05:34,000 +Can we simplify this code, of course we can. + +135 +00:05:34,000 --> 00:05:37,000 +And let's see that in the next video. + diff --git a/12 - Spring Boot Web/013 Source-Code.url b/12 - Spring Boot Web/013 Source-Code.url new file mode 100644 index 0000000000000000000000000000000000000000..06abafdcbc22d8588405bb1dad6a03f0e3bde8d0 --- /dev/null +++ b/12 - Spring Boot Web/013 Source-Code.url @@ -0,0 +1,2 @@ +[InternetShortcut] +URL=https://github.com/navinreddy20/spring6-course/tree/f1161e151ea06b68810b3cae03005d4955a96a8b/6%20Spring%20%20Boot%20Web/5.13%20Display%20Data%20on%20Result%20Page \ No newline at end of file diff --git a/12 - Spring Boot Web/014 RequestParam_en.srt b/12 - Spring Boot Web/014 RequestParam_en.srt new file mode 100644 index 0000000000000000000000000000000000000000..f263bd1788536ab3de75c6e81b5da9a6c2abebdf --- /dev/null +++ b/12 - Spring Boot Web/014 RequestParam_en.srt @@ -0,0 +1,428 @@ +1 +00:00:00,000 --> 00:00:03,000 +(bright music) + +2 +00:00:03,000 --> 00:00:06,000 +-: So let's simplify this particular code here. + +3 +00:00:06,000 --> 00:00:07,000 +Now, as I mentioned before, + +4 +00:00:07,000 --> 00:00:10,000 +this is a sublet way of doing things, right? + +5 +00:00:10,000 --> 00:00:12,000 +Where you have to handle the request, + +6 +00:00:12,000 --> 00:00:13,000 +you have to create a sessional object, + +7 +00:00:13,000 --> 00:00:16,000 +but now in spring it'll make it bit easy. + +8 +00:00:16,000 --> 00:00:20,000 +How? See if we talk about this ad, which is a path, right? + +9 +00:00:20,000 --> 00:00:23,000 +So in the browser you can see it says there's an ad request + +10 +00:00:23,000 --> 00:00:28,000 +and then you are sending this two data in the URL itself. + +11 +00:00:28,000 --> 00:00:31,000 +So when you're sending this data here as a query parameter, + +12 +00:00:31,000 --> 00:00:33,000 +what we can also do is instead + +13 +00:00:33,000 --> 00:00:36,000 +of using this request object, we can delete this. + +14 +00:00:36,000 --> 00:00:40,000 +What if you can just take those two values in two variables? + +15 +00:00:40,000 --> 00:00:42,000 +Something like this, + +16 +00:00:42,000 --> 00:00:46,000 +You can simply say, int num1, int num2. + +17 +00:00:46,000 --> 00:00:49,000 +And what I'm expecting is it'll directly give + +18 +00:00:49,000 --> 00:00:51,000 +those values to these variables. + +19 +00:00:51,000 --> 00:00:53,000 +The question is, will it really work? + +20 +00:00:53,000 --> 00:00:55,000 +We'll do that in, we'll check that in some time, + +21 +00:00:55,000 --> 00:00:57,000 +but that also means that when you use + +22 +00:00:57,000 --> 00:00:59,000 +these two variables here, + +23 +00:00:59,000 --> 00:01:00,000 +then we don't have + +24 +00:01:00,000 --> 00:01:03,000 +to get the data like this from the request object. + +25 +00:01:03,000 --> 00:01:04,000 +Let's remember this. + +26 +00:01:04,000 --> 00:01:06,000 +So if we can get those data here, + +27 +00:01:06,000 --> 00:01:08,000 +we don't have to manually get the data, right? + +28 +00:01:08,000 --> 00:01:11,000 +We can simply say num1 + num2, + +29 +00:01:11,000 --> 00:01:13,000 +and then we can save that in result. + +30 +00:01:13,000 --> 00:01:15,000 +But will it work? Let's try. + +31 +00:01:15,000 --> 00:01:17,000 +So let me relaunch this application, + +32 +00:01:17,000 --> 00:01:19,000 +okay, application restarted. + +33 +00:01:19,000 --> 00:01:21,000 +Let's go back to the browser + +34 +00:01:21,000 --> 00:01:25,000 +and, okay, now this page, I want to go for the homepage + +35 +00:01:25,000 --> 00:01:26,000 +and here let me enter to values. + +36 +00:01:26,000 --> 00:01:28,000 +I will say 7 + 8. + +37 +00:01:28,000 --> 00:01:31,000 +If I click on submit, it works. + +38 +00:01:31,000 --> 00:01:32,000 +I mean that's weird, right? + +39 +00:01:32,000 --> 00:01:34,000 +Is this code really working? + +40 +00:01:34,000 --> 00:01:37,000 +What I would also do is let me just add a extra number here + +41 +00:01:37,000 --> 00:01:39,000 +just to verify. + +42 +00:01:39,000 --> 00:01:41,000 +If it works, then of course, right? + +43 +00:01:41,000 --> 00:01:44,000 +This is much better than the earlier code. + +44 +00:01:44,000 --> 00:01:46,000 +Let's go back, submit, and you can see we got 16. + +45 +00:01:46,000 --> 00:01:48,000 +So yes, this is working. + +46 +00:01:48,000 --> 00:01:49,000 +Now how it is working. + +47 +00:01:49,000 --> 00:01:52,000 +So what happens is when you send a request + +48 +00:01:52,000 --> 00:01:53,000 +for the ad method + +49 +00:01:53,000 --> 00:01:56,000 +and you're passing your those two query parameters + +50 +00:01:56,000 --> 00:02:00,000 +with the same name, they got the name num1 and num2, + +51 +00:02:00,000 --> 00:02:01,000 +and that's why it is working. + +52 +00:02:01,000 --> 00:02:03,000 +There is also one thing you can... + +53 +00:02:03,000 --> 00:02:05,000 +What if you want to have a different variable name. + +54 +00:02:05,000 --> 00:02:07,000 +Let's say you don't have num1 here we just have num. + +55 +00:02:07,000 --> 00:02:10,000 +And here also I'm using num, I'm not using num1 now. + +56 +00:02:10,000 --> 00:02:12,000 +Will this work with a different name? + +57 +00:02:12,000 --> 00:02:15,000 +Let's try and go back here, say refresh + +58 +00:02:15,000 --> 00:02:19,000 +and let's hit it with different values and say submit. + +59 +00:02:19,000 --> 00:02:22,000 +Okay, so you can see we got an error, which is 500. + +60 +00:02:22,000 --> 00:02:24,000 +Reason for this is it is not able + +61 +00:02:24,000 --> 00:02:26,000 +to match the variable name. + +62 +00:02:26,000 --> 00:02:29,000 +Let me just search for the reason. + +63 +00:02:29,000 --> 00:02:32,000 +It says optional int parameter num is present + +64 +00:02:32,000 --> 00:02:34,000 +but cannot be translated into a null value. + +65 +00:02:34,000 --> 00:02:36,000 +Okay, so this is optional, right? + +66 +00:02:36,000 --> 00:02:38,000 +Which is we are getting off this variable + +67 +00:02:38,000 --> 00:02:41,000 +and it's not matching with the data which we are sending. + +68 +00:02:41,000 --> 00:02:43,000 +So this by default it is null. + +69 +00:02:43,000 --> 00:02:45,000 +So we have to make sure it is num1. + +70 +00:02:45,000 --> 00:02:47,000 +But what if you don't want to give num1 there? + +71 +00:02:47,000 --> 00:02:49,000 +So in that case you can use + +72 +00:02:49,000 --> 00:02:52,000 +a annotation called RequestParam. + +73 +00:02:53,000 --> 00:02:56,000 +And in this bracket you can mention the actual variable + +74 +00:02:56,000 --> 00:02:59,000 +or actual name which is coming from the browser. + +75 +00:02:59,000 --> 00:03:01,000 +So in the URL, we are sending num1. + +76 +00:03:01,000 --> 00:03:03,000 +So what we are saying is + +77 +00:03:03,000 --> 00:03:05,000 +whatever data you are getting in num1, + +78 +00:03:05,000 --> 00:03:08,000 +just assign to that variable called num + +79 +00:03:08,000 --> 00:03:09,000 +and that's how you can do it. + +80 +00:03:09,000 --> 00:03:12,000 +So again, it is optional if you have a same variable name, + +81 +00:03:12,000 --> 00:03:14,000 +but it's better to write it + +82 +00:03:14,000 --> 00:03:16,000 +so it go back to the same variable. + +83 +00:03:16,000 --> 00:03:19,000 +And same you can apply here. + +84 +00:03:19,000 --> 00:03:21,000 +So we can say request, not request mapping. + +85 +00:03:21,000 --> 00:03:22,000 +RequestParam. + +86 +00:03:27,000 --> 00:03:29,000 +And here we can say this is for num2. + +87 +00:03:30,000 --> 00:03:32,000 +And even if you say they are same, + +88 +00:03:32,000 --> 00:03:34,000 +you can skip this name here + +89 +00:03:34,000 --> 00:03:37,000 +and you can keep it just RequestParam and that works. + +90 +00:03:37,000 --> 00:03:40,000 +So basically if you can directly get the value from the URL, + +91 +00:03:40,000 --> 00:03:44,000 +you don't have to use the CDP server request object. + +92 +00:03:44,000 --> 00:03:46,000 +And that's how basically you work with Param. + +93 +00:03:46,000 --> 00:03:48,000 +Let's again, for the last time, + +94 +00:03:48,000 --> 00:03:50,000 +let's run this for this particular video. + +95 +00:03:50,000 --> 00:03:52,000 +So let's go back to the browser. + +96 +00:03:52,000 --> 00:03:56,000 +Let's refresh this, of course with different values + +97 +00:03:56,000 --> 00:03:58,000 +and it works, okay? + +98 +00:03:58,000 --> 00:04:00,000 +So if we got this extra one + +99 +00:04:00,000 --> 00:04:02,000 +because of this extra edition we are doing, + +100 +00:04:02,000 --> 00:04:04,000 +but yeah, that's how you basically use RequestParam + +101 +00:04:04,000 --> 00:04:08,000 +so that you can simplify your code much more. + +102 +00:04:08,000 --> 00:04:09,000 +Now what else? + +103 +00:04:09,000 --> 00:04:12,000 +See we have removed the CDP request object, right? + +104 +00:04:12,000 --> 00:04:14,000 +Or the CDP server request object. + +105 +00:04:14,000 --> 00:04:15,000 +How about this sessional object? + +106 +00:04:15,000 --> 00:04:17,000 +I don't want to work with sessional object. + +107 +00:04:17,000 --> 00:04:21,000 +How can we remove that? So let's see that in the next video. + diff --git a/12 - Spring Boot Web/014 Source-Code.url b/12 - Spring Boot Web/014 Source-Code.url new file mode 100644 index 0000000000000000000000000000000000000000..599f906141990cdba47f9b70a216955c0e655ce0 --- /dev/null +++ b/12 - Spring Boot Web/014 Source-Code.url @@ -0,0 +1,2 @@ +[InternetShortcut] +URL=https://github.com/navinreddy20/spring6-course/tree/f1161e151ea06b68810b3cae03005d4955a96a8b/6%20Spring%20%20Boot%20Web/5.14%20RequestParam \ No newline at end of file diff --git a/12 - Spring Boot Web/015 Model Object_en.srt b/12 - Spring Boot Web/015 Model Object_en.srt new file mode 100644 index 0000000000000000000000000000000000000000..5f6b4f0a05eb95c4540aaeef2dc9dabb211ebfcf --- /dev/null +++ b/12 - Spring Boot Web/015 Model Object_en.srt @@ -0,0 +1,396 @@ +1 +00:00:00,000 --> 00:00:03,000 +(bright music) + +2 +00:00:03,000 --> 00:00:04,000 +-: So now it's time to get rid + +3 +00:00:04,000 --> 00:00:07,000 +of this HTTP session object here. + +4 +00:00:07,000 --> 00:00:08,000 +So before we do that, let's verify + +5 +00:00:08,000 --> 00:00:10,000 +what we are doing in results. + +6 +00:00:10,000 --> 00:00:13,000 +So basically here we are printing the result is, + +7 +00:00:13,000 --> 00:00:15,000 +and then we have used JSTL here just + +8 +00:00:15,000 --> 00:00:18,000 +to fetch the value of that particular data, + +9 +00:00:18,000 --> 00:00:20,000 +which is result in this case. + +10 +00:00:20,000 --> 00:00:22,000 +So when we talked about MVC, we had a model view controller, + +11 +00:00:22,000 --> 00:00:24,000 +right, where controller is responsible + +12 +00:00:24,000 --> 00:00:26,000 +to accept the user request, right? + +13 +00:00:26,000 --> 00:00:28,000 +So we've got a controller here + +14 +00:00:28,000 --> 00:00:31,000 +and then we have a view which is going to decline. + +15 +00:00:31,000 --> 00:00:33,000 +So we have talked about the controller and the view. + +16 +00:00:33,000 --> 00:00:35,000 +What about that data? + +17 +00:00:35,000 --> 00:00:37,000 +Remember we have talked about how do you transfer data + +18 +00:00:37,000 --> 00:00:41,000 +between the controller and the view? + +19 +00:00:41,000 --> 00:00:43,000 +So basically we have to use an object + +20 +00:00:43,000 --> 00:00:45,000 +and that is your model object. + +21 +00:00:45,000 --> 00:00:46,000 +And we are not using it here. + +22 +00:00:46,000 --> 00:00:48,000 +So instead of using session, I want to use + +23 +00:00:48,000 --> 00:00:51,000 +that model object and how do we use that? + +24 +00:00:51,000 --> 00:00:53,000 +As the name suggest, we can simply say, model, + +25 +00:00:53,000 --> 00:00:57,000 +let's input the package for this and say model. + +26 +00:00:57,000 --> 00:00:59,000 +That's it. You just get this model. + +27 +00:00:59,000 --> 00:01:02,000 +And now with this model object, instead + +28 +00:01:02,000 --> 00:01:04,000 +of using session, let me delete that. + +29 +00:01:04,000 --> 00:01:07,000 +I can simply say model.addAttribute. + +30 +00:01:08,000 --> 00:01:10,000 +So instead of said attribute, we have add attribute + +31 +00:01:10,000 --> 00:01:13,000 +because we can add multiple attributes, not just one. + +32 +00:01:13,000 --> 00:01:15,000 +And then we can give a name + +33 +00:01:15,000 --> 00:01:16,000 +the same way we have done before. + +34 +00:01:16,000 --> 00:01:19,000 +We can say result and we can say result. + +35 +00:01:19,000 --> 00:01:21,000 +Okay, and what is this model? + +36 +00:01:21,000 --> 00:01:23,000 +So basically model is interface, + +37 +00:01:23,000 --> 00:01:27,000 +which was introduced in 2.5 version of Spring. + +38 +00:01:27,000 --> 00:01:32,000 +It is basically used to transfer data between the things. + +39 +00:01:32,000 --> 00:01:35,000 +I just want to make sure I've imported the right package. + +40 +00:01:35,000 --> 00:01:37,000 +Yeah, so if you want to transfer between controller + +41 +00:01:37,000 --> 00:01:40,000 +and the JSP, we have to use something called model here. + +42 +00:01:40,000 --> 00:01:43,000 +Now, once we've got model, we just have to add attribute, + +43 +00:01:43,000 --> 00:01:45,000 +and let's see if this works. + +44 +00:01:45,000 --> 00:01:46,000 +Let's restart the application. + +45 +00:01:46,000 --> 00:01:47,000 +So now we are not using a HTTP session. + +46 +00:01:47,000 --> 00:01:50,000 +We are basically using a model. + +47 +00:01:50,000 --> 00:01:55,000 +And if you go back to your browser, let's go back here, + +48 +00:01:55,000 --> 00:01:56,000 +refresh + +49 +00:01:57,000 --> 00:02:02,000 +and say some big number, enter, and you've got the output. + +50 +00:02:02,000 --> 00:02:05,000 +Doesn't matter what the output is, but we got the output. + +51 +00:02:05,000 --> 00:02:08,000 +So that's how basically your model object works. + +52 +00:02:08,000 --> 00:02:09,000 +So instead of using SGP session, we are using model now. + +53 +00:02:12,000 --> 00:02:16,000 +Okay, so we have get, we got rid of the the request object. + +54 +00:02:16,000 --> 00:02:18,000 +We got rid of the HTTP session. + +55 +00:02:18,000 --> 00:02:20,000 +Now, this is how basically you build + +56 +00:02:21,000 --> 00:02:22,000 +application using spring NVC or spring. + +57 +00:02:22,000 --> 00:02:24,000 +Spring Boot. + +58 +00:02:24,000 --> 00:02:27,000 +You can say, okay, but also I want to change one more thing. + +59 +00:02:27,000 --> 00:02:28,000 +I know you'll be saying, + +60 +00:02:28,000 --> 00:02:30,000 +Hey, how many things you're changing? + +61 +00:02:30,000 --> 00:02:33,000 +Okay, let, let me do one last, I hope. + +62 +00:02:33,000 --> 00:02:35,000 +I just want + +63 +00:02:35,000 --> 00:02:36,000 +to get rid of this JSP page. + +64 +00:02:36,000 --> 00:02:39,000 +I mean not JSP page, but .JSP. I mean, think about this. + +65 +00:02:39,000 --> 00:02:41,000 +Remember when we talked about MVC, I said + +66 +00:02:41,000 --> 00:02:44,000 +for the view we have multiple options. + +67 +00:02:44,000 --> 00:02:49,000 +We got JSP, we got free marker, we got theme leaf. + +68 +00:02:49,000 --> 00:02:50,000 +So we have so many options, right? + +69 +00:02:50,000 --> 00:02:55,000 +And let's say one day I decided to move from let's say, JSP + +70 +00:02:55,000 --> 00:02:56,000 +to theme leaf. + +71 +00:02:56,000 --> 00:03:00,000 +In that case you will have to go to each controller + +72 +00:03:00,000 --> 00:03:02,000 +and check where, where are we using this + +73 +00:03:02,000 --> 00:03:04,000 +dot JSP extension. + +74 +00:03:04,000 --> 00:03:07,000 +So if you can get rid of this, will it still work? + +75 +00:03:07,000 --> 00:03:10,000 +Of course, we have to change both the side. + +76 +00:03:10,000 --> 00:03:13,000 +Nowhere. I want to mention the extension. + +77 +00:03:13,000 --> 00:03:14,000 +That's one. + +78 +00:03:14,000 --> 00:03:18,000 +Next, maybe I want to keep my files, + +79 +00:03:18,000 --> 00:03:21,000 +the web files, not in the web app folder, + +80 +00:03:21,000 --> 00:03:22,000 +but it's, but somewhere else. + +81 +00:03:22,000 --> 00:03:24,000 +Maybe I, I have a new view folder here. + +82 +00:03:24,000 --> 00:03:25,000 +So I will just right click here + +83 +00:03:25,000 --> 00:03:30,000 +and say I have a folder called views + +84 +00:03:30,000 --> 00:03:33,000 +and I want to move this things + +85 +00:03:34,000 --> 00:03:35,000 +inside this. + +86 +00:03:36,000 --> 00:03:37,000 +Now question arise. + +87 +00:03:37,000 --> 00:03:39,000 +After making these changes, will it work? + +88 +00:03:39,000 --> 00:03:40,000 +Let's try. + +89 +00:03:40,000 --> 00:03:42,000 +So I'll restart the application + +90 +00:03:42,000 --> 00:03:43,000 +and if I go back to the browser now, + +91 +00:03:43,000 --> 00:03:46,000 +let's say refresh the homepage. + +92 +00:03:46,000 --> 00:03:47,000 +And even the homepage, + +93 +00:03:47,000 --> 00:03:49,000 +you can see the url, I'm calling the homepage. + +94 +00:03:49,000 --> 00:03:51,000 +It's not able to find the homepage. + +95 +00:03:51,000 --> 00:03:53,000 +Why? The homepage is there. + +96 +00:03:53,000 --> 00:03:55,000 +It's just that it in different folder plus + +97 +00:03:55,000 --> 00:03:58,000 +we are not even specifying the extension. + +98 +00:03:58,000 --> 00:04:01,000 +So how do we solve this problem? + +99 +00:04:01,000 --> 00:04:03,000 +Let's talk about that in the next video. + diff --git a/12 - Spring Boot Web/015 Source-Code.url b/12 - Spring Boot Web/015 Source-Code.url new file mode 100644 index 0000000000000000000000000000000000000000..6eb541e3cfb87555dcffc8bb5235ac7d9ab7ed74 --- /dev/null +++ b/12 - Spring Boot Web/015 Source-Code.url @@ -0,0 +1,2 @@ +[InternetShortcut] +URL=https://github.com/navinreddy20/spring6-course/tree/f1161e151ea06b68810b3cae03005d4955a96a8b/6%20Spring%20%20Boot%20Web/5.15%20Model%20Object \ No newline at end of file diff --git a/12 - Spring Boot Web/016 Setting Prefix and Suffix_en.srt b/12 - Spring Boot Web/016 Setting Prefix and Suffix_en.srt new file mode 100644 index 0000000000000000000000000000000000000000..6e289d0e2e988dc67dca91e20360098e46743207 --- /dev/null +++ b/12 - Spring Boot Web/016 Setting Prefix and Suffix_en.srt @@ -0,0 +1,340 @@ +1 +00:00:00,000 --> 00:00:03,000 +(light music) + +2 +00:00:03,000 --> 00:00:04,000 +-: Okay, so let's solve this problem. + +3 +00:00:04,000 --> 00:00:07,000 +So basically now, our views, which are the jsp files, + +4 +00:00:07,000 --> 00:00:09,000 +are in other folder. + +5 +00:00:09,000 --> 00:00:12,000 +Additionally, we have changed the name of the view + +6 +00:00:12,000 --> 00:00:15,000 +directly with the name of the view, not with the extension. + +7 +00:00:15,000 --> 00:00:17,000 +So the question arise, how would you solve it? + +8 +00:00:17,000 --> 00:00:20,000 +The thing is, when you talk about your spring framework, + +9 +00:00:20,000 --> 00:00:23,000 +it also has a view resolver. + +10 +00:00:23,000 --> 00:00:24,000 +So basically, behind the scenes, + +11 +00:00:24,000 --> 00:00:27,000 +whenever you return a particular jsp file or something, + +12 +00:00:27,000 --> 00:00:29,000 +when you return a name here, + +13 +00:00:29,000 --> 00:00:31,000 +and if you see we are running a string, + +14 +00:00:31,000 --> 00:00:33,000 +so someone has to map it, right? + +15 +00:00:33,000 --> 00:00:36,000 +So there's also a component which helps you to resolve this + +16 +00:00:36,000 --> 00:00:39,000 +and that is called a view resolver. + +17 +00:00:39,000 --> 00:00:42,000 +So when you say, "Hey, I'm returning result here." + +18 +00:00:42,000 --> 00:00:44,000 +Now view resolver has no idea, + +19 +00:00:44,000 --> 00:00:46,000 +first of all, where this file is, + +20 +00:00:46,000 --> 00:00:48,000 +and next what is the extension. + +21 +00:00:48,000 --> 00:00:50,000 +So we can talk to view resolver by saying, + +22 +00:00:50,000 --> 00:00:51,000 +"Hey, don't worry, + +23 +00:00:51,000 --> 00:00:53,000 +let me tell you where will you find it + +24 +00:00:53,000 --> 00:00:55,000 +and what is the extension." + +25 +00:00:55,000 --> 00:00:57,000 +And the way you can do that, + +26 +00:00:57,000 --> 00:00:58,000 +is with the help of a property file. + +27 +00:00:58,000 --> 00:01:00,000 +Of course, we are conferring something, right? + +28 +00:01:00,000 --> 00:01:03,000 +And when you configure your spring framework, + +29 +00:01:03,000 --> 00:01:05,000 +spring boot basically gives you this amazing file + +30 +00:01:05,000 --> 00:01:07,000 +called application of properties. + +31 +00:01:07,000 --> 00:01:10,000 +This is where you can mention the properties, + +32 +00:01:10,000 --> 00:01:12,000 +but we don't know which property, right? + +33 +00:01:12,000 --> 00:01:15,000 +So for that, again, you don't have to buy hard disk, + +34 +00:01:15,000 --> 00:01:16,000 +the moment, the more you work, + +35 +00:01:16,000 --> 00:01:19,000 +the more you will remember the property names. + +36 +00:01:19,000 --> 00:01:21,000 +But if you search for spring application properties, + +37 +00:01:21,000 --> 00:01:24,000 +the first link here, the common application properties, + +38 +00:01:24,000 --> 00:01:27,000 +if you go there, there are so many properties you can set + +39 +00:01:27,000 --> 00:01:29,000 +to configure your application, okay? + +40 +00:01:29,000 --> 00:01:30,000 +Don't get stressed with this. + +41 +00:01:30,000 --> 00:01:33,000 +It's not, we don't have to remember everything. + +42 +00:01:33,000 --> 00:01:36,000 +Few of them we will be using most of the time. + +43 +00:01:36,000 --> 00:01:38,000 +And even if you don't remember anything, + +44 +00:01:38,000 --> 00:01:39,000 +you can just Google it. + +45 +00:01:39,000 --> 00:01:40,000 +Stackoverflow is there. + +46 +00:01:40,000 --> 00:01:41,000 +AI is there. + +47 +00:01:41,000 --> 00:01:44,000 +AI tools are available, they will give you the exact name. + +48 +00:01:44,000 --> 00:01:45,000 +But here what I will do + +49 +00:01:45,000 --> 00:01:48,000 +is I will search for the MVC property. + +50 +00:01:48,000 --> 00:01:51,000 +And in this MVC, we have to set the location + +51 +00:01:51,000 --> 00:01:53,000 +and we have to set the extension, right? + +52 +00:01:53,000 --> 00:01:56,000 +So the location is your prefix. + +53 +00:01:56,000 --> 00:01:59,000 +So the name, result, so prefix is the views + +54 +00:01:59,000 --> 00:02:03,000 +and the postfix is the extension, which is .jsp, okay? + +55 +00:02:03,000 --> 00:02:05,000 +And then we can search + +56 +00:02:05,000 --> 00:02:08,000 +for something called prefix and postfix. + +57 +00:02:08,000 --> 00:02:10,000 +So if you can see, not prefix and postfix, + +58 +00:02:10,000 --> 00:02:12,000 +prefix and suffix. + +59 +00:02:12,000 --> 00:02:14,000 +These are the properties we have to mention, okay? + +60 +00:02:14,000 --> 00:02:16,000 +So example, if you set the prefix, + +61 +00:02:16,000 --> 00:02:18,000 +let me just copy this. + +62 +00:02:18,000 --> 00:02:22,000 +So prefix, you have to set slash, views, slash, + +63 +00:02:22,000 --> 00:02:24,000 +that's the folder name. + +64 +00:02:24,000 --> 00:02:26,000 +And then we have to set this suffix as well. + +65 +00:02:26,000 --> 00:02:29,000 +And this is your extension, which is .jsp, that's it. + +66 +00:02:29,000 --> 00:02:31,000 +This, you have to mention these two things. + +67 +00:02:31,000 --> 00:02:32,000 +So what we are doing is we are specifying the prefix + +68 +00:02:32,000 --> 00:02:36,000 +and we are specifying the suffix, which is the extension. + +69 +00:02:36,000 --> 00:02:38,000 +Let's restart the application now. + +70 +00:02:38,000 --> 00:02:39,000 +I hope this will work. + +71 +00:02:39,000 --> 00:02:41,000 +Let's go back to your browser. + +72 +00:02:41,000 --> 00:02:44,000 +This page, let me just close the property files. + +73 +00:02:44,000 --> 00:02:49,000 +And now, if I go to localhost:8080, + +74 +00:02:50,000 --> 00:02:52,000 +okay, it's not, + +75 +00:02:52,000 --> 00:02:54,000 +it's not running the CSS. + +76 +00:02:54,000 --> 00:02:56,000 +Let me reload my entire IntelliJ Idea. + +77 +00:02:56,000 --> 00:02:57,000 +Let's run this now. + +78 +00:02:57,000 --> 00:02:59,000 +Okay, go back to your browser, reload. + +79 +00:02:59,000 --> 00:03:02,000 +Okay, some issue with the CSS, we will resolve that later. + +80 +00:03:02,000 --> 00:03:04,000 +And let me just try the values. + +81 +00:03:04,000 --> 00:03:05,000 +Click on submit. + +82 +00:03:05,000 --> 00:03:06,000 +And you can see it worked. + +83 +00:03:06,000 --> 00:03:09,000 +We got result is 13. + +84 +00:03:09,000 --> 00:03:10,000 +So basically it was able to find the view, + +85 +00:03:10,000 --> 00:03:13,000 +it was able to find the JSP as well. + diff --git a/12 - Spring Boot Web/016 Source-Code.url b/12 - Spring Boot Web/016 Source-Code.url new file mode 100644 index 0000000000000000000000000000000000000000..032aa6e06be2823b44df0bfd21b7ed640fe7db61 --- /dev/null +++ b/12 - Spring Boot Web/016 Source-Code.url @@ -0,0 +1,2 @@ +[InternetShortcut] +URL=https://github.com/navinreddy20/spring6-course/tree/f1161e151ea06b68810b3cae03005d4955a96a8b/6%20Spring%20%20Boot%20Web/5.16%20Setting%20Prefix%20and%20Suffix \ No newline at end of file diff --git a/12 - Spring Boot Web/017 ModelAndView_en.srt b/12 - Spring Boot Web/017 ModelAndView_en.srt new file mode 100644 index 0000000000000000000000000000000000000000..c925ce7e9743504b7aabac2ac8a3270859251b7b --- /dev/null +++ b/12 - Spring Boot Web/017 ModelAndView_en.srt @@ -0,0 +1,456 @@ +1 +00:00:00,000 --> 00:00:03,000 +(gentle music) + +2 +00:00:03,000 --> 00:00:06,000 +-: Now in this video, we'll talk about ModelAndView. + +3 +00:00:06,000 --> 00:00:08,000 +So basically we have talked about Model before. + +4 +00:00:08,000 --> 00:00:11,000 +So if you want to pass data between the pages, + +5 +00:00:11,000 --> 00:00:13,000 +you can use a Model object. + +6 +00:00:13,000 --> 00:00:15,000 +So what we are doing till now is we got a Model object. + +7 +00:00:15,000 --> 00:00:17,000 +We are adding this data, which is "result", + +8 +00:00:17,000 --> 00:00:20,000 +and then this data is going to the .jsp page, + +9 +00:00:20,000 --> 00:00:21,000 +which you have mentioned here. + +10 +00:00:21,000 --> 00:00:23,000 +Okay, so before we talk about the ModelAndView, + +11 +00:00:23,000 --> 00:00:25,000 +because that View is important, + +12 +00:00:25,000 --> 00:00:27,000 +and the view is not working the way we want it. + +13 +00:00:27,000 --> 00:00:31,000 +So what I did is basically when I was moving the .jsp files, + +14 +00:00:31,000 --> 00:00:33,000 +I've also moved the .css file. + +15 +00:00:33,000 --> 00:00:35,000 +Now, .css is a public file, right? + +16 +00:00:35,000 --> 00:00:38,000 +Basically it is only for the styling purpose. + +17 +00:00:38,000 --> 00:00:42,000 +So you can put the .css file inside the webapp. + +18 +00:00:42,000 --> 00:00:43,000 +So, what? + +19 +00:00:43,000 --> 00:00:46,000 +You have to move a .jsp but not the static files. + +20 +00:00:46,000 --> 00:00:47,000 +So you can put the static files here + +21 +00:00:47,000 --> 00:00:51,000 +and then this should resolve the problem. + +22 +00:00:51,000 --> 00:00:53,000 +So let's go back to my browser + +23 +00:00:53,000 --> 00:00:55,000 +and you can see it I've refreshed. + +24 +00:00:55,000 --> 00:00:57,000 +And if I type two numbers, + +25 +00:00:57,000 --> 00:00:59,000 +now it is able to basically load this .css, right? + +26 +00:00:59,000 --> 00:01:01,000 +So that was the issue last time. + +27 +00:01:01,000 --> 00:01:06,000 +Also, you can also put this .css file in this static folder. + +28 +00:01:06,000 --> 00:01:09,000 +Now, static is a folder which you can see in the resources. + +29 +00:01:09,000 --> 00:01:10,000 +So we have a static folder, which will be there. + +30 +00:01:10,000 --> 00:01:13,000 +And if you want to put any static resources like images, + +31 +00:01:13,000 --> 00:01:16,000 +.css files, you can put that here. + +32 +00:01:16,000 --> 00:01:17,000 +Okay? So you have a choice. + +33 +00:01:17,000 --> 00:01:21,000 +You can either put that in the static file or in the webapp. + +34 +00:01:21,000 --> 00:01:23,000 +It makes sense to put that in static file + +35 +00:01:23,000 --> 00:01:26,000 +is because all the styling and static content + +36 +00:01:26,000 --> 00:01:28,000 +will be there in the static folder. + +37 +00:01:28,000 --> 00:01:30,000 +In the View, you will be having your .jsp. + +38 +00:01:30,000 --> 00:01:33,000 +It's more about structuring your project, right? + +39 +00:01:33,000 --> 00:01:36,000 +So if I refresh or restart the application once again, + +40 +00:01:36,000 --> 00:01:37,000 +let's see if that works. + +41 +00:01:37,000 --> 00:01:39,000 +Let's go back to the browser and refresh. + +42 +00:01:39,000 --> 00:01:40,000 +Okay, no problem. + +43 +00:01:40,000 --> 00:01:42,000 +You can see we are able to load the .css. + +44 +00:01:42,000 --> 00:01:44,000 +Okay, now let's talk about ModelAndView. + +45 +00:01:44,000 --> 00:01:47,000 +So when we talk about Model, it's only for data, right? + +46 +00:01:47,000 --> 00:01:50,000 +So we are using Model here to add the data + +47 +00:01:50,000 --> 00:01:54,000 +and also we are specifying a View name in the result. + +48 +00:01:54,000 --> 00:01:57,000 +What if you can put that review name in the object itself? + +49 +00:01:57,000 --> 00:02:00,000 +What I'm saying is, instead of using Model, + +50 +00:02:00,000 --> 00:02:01,000 +if you can use ModelAndView. + +51 +00:02:03,000 --> 00:02:04,000 +Which is this. + +52 +00:02:04,000 --> 00:02:06,000 +Instead of saying Model, I will say .mv. + +53 +00:02:06,000 --> 00:02:08,000 +.mv represents ModelAndView. + +54 +00:02:08,000 --> 00:02:12,000 +And with this ModelAndView object, I can add the attribute. + +55 +00:02:12,000 --> 00:02:14,000 +Okay, so we have a different name. + +56 +00:02:15,000 --> 00:02:18,000 +So I will say "addObject" + +57 +00:02:18,000 --> 00:02:21,000 +and then we can say the object is "result". + +58 +00:02:21,000 --> 00:02:23,000 +And then I can pass the data, which is "result", + +59 +00:02:23,000 --> 00:02:25,000 +that's done. + +60 +00:02:25,000 --> 00:02:28,000 +Okay, but then what about the return here? + +61 +00:02:28,000 --> 00:02:31,000 +So, of course we can still work with this, it will work. + +62 +00:02:31,000 --> 00:02:35,000 +But the best option is, instead of returning a name, + +63 +00:02:35,000 --> 00:02:36,000 +return the .mv object + +64 +00:02:36,000 --> 00:02:39,000 +because the ViewResolver will look at .mv object + +65 +00:02:39,000 --> 00:02:42,000 +and it will have two things: the data, as well as the View. + +66 +00:02:42,000 --> 00:02:44,000 +It makes much more sense now, right? + +67 +00:02:44,000 --> 00:02:46,000 +Because you are returning only one thing, not two. + +68 +00:02:46,000 --> 00:02:48,000 +Initially, you are returning the Model object + +69 +00:02:48,000 --> 00:02:50,000 +and also the View name. + +70 +00:02:50,000 --> 00:02:53,000 +But now we are returning only one object. + +71 +00:02:53,000 --> 00:02:54,000 +Now, since we are changing it here .mv, + +72 +00:02:54,000 --> 00:02:57,000 +we have to also make sure that you change it here + +73 +00:02:57,000 --> 00:03:02,000 +by saying we are returning a ModelAndView object + +74 +00:03:02,000 --> 00:03:02,000 +and that's done. + +75 +00:03:02,000 --> 00:03:05,000 +So okay, we got some angular bracket there. + +76 +00:03:05,000 --> 00:03:06,000 +And this should work. + +77 +00:03:06,000 --> 00:03:07,000 +Let's try. + +78 +00:03:07,000 --> 00:03:10,000 +Let's refresh this or restart the application. + +79 +00:03:10,000 --> 00:03:12,000 +Let's go back to our browser. + +80 +00:03:12,000 --> 00:03:14,000 +And if I refresh the page, + +81 +00:03:14,000 --> 00:03:16,000 +you can see there's no problem on the homepage. + +82 +00:03:16,000 --> 00:03:17,000 +But if I add the values, + +83 +00:03:17,000 --> 00:03:20,000 +and if I say submit, you can see we got an error, + +84 +00:03:20,000 --> 00:03:21,000 +which is 404. + +85 +00:03:21,000 --> 00:03:23,000 +So basically, it is not able to find the "result" page. + +86 +00:03:23,000 --> 00:03:24,000 +You know why? + +87 +00:03:24,000 --> 00:03:25,000 +Because nowhere, + +88 +00:03:25,000 --> 00:03:28,000 +we are saying that we have to call a "result" page. + +89 +00:03:28,000 --> 00:03:31,000 +So that means when you add the data, + +90 +00:03:31,000 --> 00:03:33,000 +you have to also set the ViewName. + +91 +00:03:34,000 --> 00:03:36,000 +So you have to mention the ViewName as "result". + +92 +00:03:36,000 --> 00:03:38,000 +Now it should work. + +93 +00:03:38,000 --> 00:03:41,000 +Let's restart the application and go back to the browser. + +94 +00:03:41,000 --> 00:03:43,000 +Let's go to the homepage first + +95 +00:03:45,000 --> 00:03:47,000 +and let's say 6 and 7. + +96 +00:03:47,000 --> 00:03:48,000 +Submit. + +97 +00:03:48,000 --> 00:03:49,000 +And you can see it works. + +98 +00:03:49,000 --> 00:03:51,000 +So basically you can use a Model object + +99 +00:03:51,000 --> 00:03:53,000 +if you just want to work with Data, + +100 +00:03:53,000 --> 00:03:55,000 +but if you want to return the ViewName as well, + +101 +00:03:55,000 --> 00:03:58,000 +ModelAndView makes much more sense. + +102 +00:03:58,000 --> 00:04:00,000 +So yeah, that's it about ModelAndView + +103 +00:04:00,000 --> 00:04:03,000 +where you can add the object and not just one object. + +104 +00:04:03,000 --> 00:04:05,000 +You can add multiple objects + +105 +00:04:05,000 --> 00:04:07,000 +and you can set the ViewName as well. + +106 +00:04:07,000 --> 00:04:09,000 +And this is how basically you build an application. + +107 +00:04:09,000 --> 00:04:12,000 +You can do the same thing here. + +108 +00:04:12,000 --> 00:04:13,000 +Instead of saying String, + +109 +00:04:13,000 --> 00:04:15,000 +we should also return ModelAndView here. + +110 +00:04:15,000 --> 00:04:17,000 +But again, that's something you can decide on, + +111 +00:04:17,000 --> 00:04:18,000 +which one to use. + +112 +00:04:18,000 --> 00:04:19,000 +But you have both the options. + +113 +00:04:19,000 --> 00:04:22,000 +You can use String or you can use, + +114 +00:04:22,000 --> 00:04:24,000 +you can return the ModelAndView object. + diff --git a/12 - Spring Boot Web/017 Source-Code.url b/12 - Spring Boot Web/017 Source-Code.url new file mode 100644 index 0000000000000000000000000000000000000000..19191239686b96e574ef4171e2a3355d2f947c06 --- /dev/null +++ b/12 - Spring Boot Web/017 Source-Code.url @@ -0,0 +1,2 @@ +[InternetShortcut] +URL=https://github.com/navinreddy20/spring6-course/tree/f1161e151ea06b68810b3cae03005d4955a96a8b/6%20Spring%20%20Boot%20Web/5.17%20ModelAndView \ No newline at end of file diff --git a/12 - Spring Boot Web/018 Need for ModelAttribute_en.srt b/12 - Spring Boot Web/018 Need for ModelAttribute_en.srt new file mode 100644 index 0000000000000000000000000000000000000000..05ec260f4bec319407bdbd07e926d24e970242cb --- /dev/null +++ b/12 - Spring Boot Web/018 Need for ModelAttribute_en.srt @@ -0,0 +1,748 @@ +1 +00:00:00,000 --> 00:00:03,000 +(upbeat music) + +2 +00:00:03,000 --> 00:00:06,000 +-: So we are happy with whatever we have learned till now. + +3 +00:00:06,000 --> 00:00:09,000 +Basically we have talked about model, object, + +4 +00:00:09,000 --> 00:00:10,000 +model and view. + +5 +00:00:10,000 --> 00:00:13,000 +There is one more called model attribute. + +6 +00:00:13,000 --> 00:00:16,000 +So let's understand why do we need a model attribute here. + +7 +00:00:16,000 --> 00:00:20,000 +So what I will do for that is I will go back to my index.jsp + +8 +00:00:20,000 --> 00:00:23,000 +and what we are doing here is to add two numbers. + +9 +00:00:23,000 --> 00:00:25,000 +Now basically if I go to my output page, + +10 +00:00:25,000 --> 00:00:26,000 +and if I go to the homepage, + +11 +00:00:26,000 --> 00:00:29,000 +basically you can see we are saying, "Hey, you know, + +12 +00:00:29,000 --> 00:00:31,000 +enter two numbers and we will add them". + +13 +00:00:31,000 --> 00:00:32,000 +And that's what we are doing. + +14 +00:00:32,000 --> 00:00:36,000 +But let's say you are not just want to add two numbers. + +15 +00:00:36,000 --> 00:00:39,000 +Let's maybe you want to send some data to the server so + +16 +00:00:39,000 --> 00:00:41,000 +that we can store that in database. + +17 +00:00:41,000 --> 00:00:43,000 +So now let's say you have an entity. + +18 +00:00:43,000 --> 00:00:46,000 +Now when you say entity, it means you are representing some + +19 +00:00:46,000 --> 00:00:50,000 +real life entities like laptop or a house or a office + +20 +00:00:50,000 --> 00:00:53,000 +or a factory or a mobile phone. + +21 +00:00:53,000 --> 00:00:55,000 +Now all this are entity, even humans. + +22 +00:00:55,000 --> 00:00:57,000 +When you say you are a student, you're a teacher, + +23 +00:00:57,000 --> 00:00:59,000 +you're an engineer, you are a doctor, + +24 +00:00:59,000 --> 00:01:02,000 +you are basically representing an entity + +25 +00:01:02,000 --> 00:01:04,000 +and then you, maybe you want + +26 +00:01:04,000 --> 00:01:06,000 +to show this entity in a database. + +27 +00:01:06,000 --> 00:01:09,000 +But again, we are not talking about database as of now, + +28 +00:01:09,000 --> 00:01:12,000 +but let's say from this page, I want to send a data + +29 +00:01:12,000 --> 00:01:16,000 +regarding an entity and then I want to directly accept + +30 +00:01:16,000 --> 00:01:19,000 +that entity as an object on the server side. + +31 +00:01:19,000 --> 00:01:21,000 +Okay, I know a lot of things to imagine. + +32 +00:01:21,000 --> 00:01:24,000 +Let's go step by step, what I'm talking about is, + +33 +00:01:24,000 --> 00:01:26,000 +let's say we have a alien class. + +34 +00:01:26,000 --> 00:01:28,000 +Now, when I say alien for this context, + +35 +00:01:28,000 --> 00:01:30,000 +alien simply means programmers. + +36 +00:01:30,000 --> 00:01:34,000 +Okay, so I refer programmers as aliens and why? + +37 +00:01:34,000 --> 00:01:36,000 +If you want to know, just go to YouTube + +38 +00:01:36,000 --> 00:01:39,000 +and search for why I call Alien. + +39 +00:01:39,000 --> 00:01:42,000 +So you will get the idea, but anyway, that's not important. + +40 +00:01:42,000 --> 00:01:45,000 +Important is, let's say we have this form here. + +41 +00:01:45,000 --> 00:01:49,000 +Now instead of asking for a number, maybe I want to ask + +42 +00:01:49,000 --> 00:01:51,000 +for a particular ID. + +43 +00:01:51,000 --> 00:01:53,000 +So every alien will have let's say two things, an ID + +44 +00:01:53,000 --> 00:01:57,000 +which is a number which represents you and your name. + +45 +00:01:57,000 --> 00:01:59,000 +So I'm saying enter ID + +46 +00:01:59,000 --> 00:02:01,000 +and this is for a ID, which is alien ID. + +47 +00:02:01,000 --> 00:02:03,000 +The ID is aid. + +48 +00:02:03,000 --> 00:02:08,000 +The name is aid, and I'm saying enter the name. + +49 +00:02:08,000 --> 00:02:12,000 +So I'm saying enter name and then this is for, aname. + +50 +00:02:12,000 --> 00:02:16,000 +Let's say that's the idea, I want to go for aname. + +51 +00:02:16,000 --> 00:02:19,000 +This is for aname, and then I'm saying submit. + +52 +00:02:19,000 --> 00:02:22,000 +Instead of saying add these two numbers, let's say I want + +53 +00:02:22,000 --> 00:02:24,000 +to add a new entry for the alien. + +54 +00:02:24,000 --> 00:02:26,000 +Okay, so what is an alien? + +55 +00:02:26,000 --> 00:02:29,000 +Alien is an entity which has two things, ID and a name. + +56 +00:02:29,000 --> 00:02:32,000 +And you are entering those details here. + +57 +00:02:32,000 --> 00:02:35,000 +And when you click on submit, you are requesting + +58 +00:02:35,000 --> 00:02:36,000 +for add alien. + +59 +00:02:36,000 --> 00:02:38,000 +Okay, now how will this look? + +60 +00:02:38,000 --> 00:02:40,000 +So if I go back, refresh this page + +61 +00:02:40,000 --> 00:02:42,000 +or restart the application first, + +62 +00:02:42,000 --> 00:02:45,000 +and if I go back to my output page, refresh this + +63 +00:02:45,000 --> 00:02:47,000 +so you can see I'm asking for the ID. + +64 +00:02:47,000 --> 00:02:50,000 +Let's say ID is 101 and name here is Navin. + +65 +00:02:50,000 --> 00:02:53,000 +Now when I say submit, you can see it says 404. + +66 +00:02:53,000 --> 00:02:56,000 +You know why, it's because we don't have + +67 +00:02:56,000 --> 00:02:57,000 +the controller for this. + +68 +00:02:57,000 --> 00:02:59,000 +So what I will do is I will, + +69 +00:02:59,000 --> 00:03:01,000 +I need a controller for add alien. + +70 +00:03:01,000 --> 00:03:04,000 +So I will just reuse my code, I mean that's what you say. + +71 +00:03:04,000 --> 00:03:08,000 +Instead of copy pasting, I will say add alien. + +72 +00:03:08,000 --> 00:03:11,000 +And this time the method name is also add alien. + +73 +00:03:11,000 --> 00:03:13,000 +So basically I'm requesting for this particular + +74 +00:03:13,000 --> 00:03:15,000 +UL here, this is my part. + +75 +00:03:15,000 --> 00:03:17,000 +But what about the parameters? + +76 +00:03:17,000 --> 00:03:20,000 +Of course I'm not sending num one, I'm sending aid. + +77 +00:03:20,000 --> 00:03:23,000 +The variable is also an ID, I'm not sending num two. + +78 +00:03:23,000 --> 00:03:28,000 +What I'm sending is aname and aname is of type string + +79 +00:03:28,000 --> 00:03:31,000 +and I'm saying aname here. + +80 +00:03:31,000 --> 00:03:33,000 +Now basically what we're doing is we are accepting + +81 +00:03:33,000 --> 00:03:34,000 +that particular alien + +82 +00:03:34,000 --> 00:03:39,000 +and the values are ID and aname. + +83 +00:03:39,000 --> 00:03:40,000 +That's what we are fetching from the URL + +84 +00:03:40,000 --> 00:03:43,000 +because if you see the URL here, + +85 +00:03:43,000 --> 00:03:46,000 +we are sending this data in the URL, so it should work. + +86 +00:03:46,000 --> 00:03:48,000 +So this data is coming here, + +87 +00:03:48,000 --> 00:03:49,000 +but then what we are doing with data, + +88 +00:03:49,000 --> 00:03:52,000 +of course we don't want to add basically let's say I want + +89 +00:03:52,000 --> 00:03:56,000 +to create an aided object and save this data. + +90 +00:03:56,000 --> 00:03:57,000 +Of course, right, in the Java world, + +91 +00:03:57,000 --> 00:03:59,000 +everything should be in the object + +92 +00:03:59,000 --> 00:04:01,000 +and we don't have a object yet. + +93 +00:04:01,000 --> 00:04:03,000 +So even if I try to create the object of alien + +94 +00:04:03,000 --> 00:04:07,000 +by saying object alien equal to new alien, + +95 +00:04:07,000 --> 00:04:10,000 +unfortunately we don't have this object + +96 +00:04:10,000 --> 00:04:11,000 +or this class itself. + +97 +00:04:11,000 --> 00:04:15,000 +So what we can do is we can create a class. + +98 +00:04:15,000 --> 00:04:17,000 +So you can get a class in the same package. + +99 +00:04:17,000 --> 00:04:18,000 +Normally it should be a different package, + +100 +00:04:18,000 --> 00:04:20,000 +but we'll do that packaging part later. + +101 +00:04:20,000 --> 00:04:22,000 +Let's say everything is in the same package. + +102 +00:04:22,000 --> 00:04:26,000 +So if I go back here, SRC, main, Java, + +103 +00:04:26,000 --> 00:04:28,000 +I have everything in this package, okay? + +104 +00:04:28,000 --> 00:04:31,000 +If I go back to alien, alien needs two things. + +105 +00:04:31,000 --> 00:04:34,000 +One is private into ID + +106 +00:04:34,000 --> 00:04:38,000 +and private string name, + +107 +00:04:38,000 --> 00:04:39,000 +in fact not aname. + +108 +00:04:39,000 --> 00:04:43,000 +And I want this to be aid and aname. + +109 +00:04:43,000 --> 00:04:46,000 +And then for these two private variables, + +110 +00:04:46,000 --> 00:04:47,000 +I need getters and setters. + +111 +00:04:47,000 --> 00:04:50,000 +So I will right click here, say generate getters + +112 +00:04:50,000 --> 00:04:53,000 +for these two variables, click on, okay, we got that. + +113 +00:04:53,000 --> 00:04:55,000 +Also, I need a method for toString. + +114 +00:04:55,000 --> 00:04:59,000 +So I will say right click here, generate toString + +115 +00:04:59,000 --> 00:05:02,000 +for which will return both these values. + +116 +00:05:02,000 --> 00:05:04,000 +So basically we've got a toString method, + +117 +00:05:04,000 --> 00:05:06,000 +which will return this data here. + +118 +00:05:06,000 --> 00:05:07,000 +Okay, now what did it'll return? + +119 +00:05:07,000 --> 00:05:11,000 +It'll print alien, the alien ID and the alien name. + +120 +00:05:11,000 --> 00:05:14,000 +That's what we want, nothing fancy, + +121 +00:05:14,000 --> 00:05:15,000 +simple class, simple pojo. + +122 +00:05:15,000 --> 00:05:17,000 +Go back to the controller, now you can see we do have this + +123 +00:05:17,000 --> 00:05:19,000 +class and we've got the object now. + +124 +00:05:19,000 --> 00:05:23,000 +I want to send the same object in this. + +125 +00:05:23,000 --> 00:05:24,000 +So I'm sending alien now + +126 +00:05:24,000 --> 00:05:28,000 +and maybe in short result I want to send the alien itself. + +127 +00:05:28,000 --> 00:05:30,000 +So whatever data I'm receiving, + +128 +00:05:30,000 --> 00:05:32,000 +I'm calling the same page, which is result. + +129 +00:05:32,000 --> 00:05:36,000 +But then the data which I'm sending now is alien data. + +130 +00:05:36,000 --> 00:05:38,000 +So of course in the result I have + +131 +00:05:38,000 --> 00:05:40,000 +to make changes instead of printing result here + +132 +00:05:40,000 --> 00:05:42,000 +I will print alien. + +133 +00:05:42,000 --> 00:05:44,000 +Or maybe we can have some fancy message here. + +134 +00:05:44,000 --> 00:05:46,000 +Let's do in the H2 tag, I want to say + +135 +00:05:46,000 --> 00:05:49,000 +Welcome to Telusko, okay, so this is data. + +136 +00:05:49,000 --> 00:05:51,000 +I want to, this is what I want to print on the screen. + +137 +00:05:51,000 --> 00:05:55,000 +And then I want to print the alien object, not result. + +138 +00:05:55,000 --> 00:05:58,000 +Let's say just a simple alien object + +139 +00:05:58,000 --> 00:05:59,000 +and maybe we can put that in a P tag. + +140 +00:05:59,000 --> 00:06:02,000 +I hope I have CSS for P. + +141 +00:06:02,000 --> 00:06:04,000 +Let's say I want to go for P tag here. + +142 +00:06:04,000 --> 00:06:08,000 +Just need to check if I have a P tag in the CSS. + +143 +00:06:09,000 --> 00:06:12,000 +Yeah, I do have, and now if I want to print this, + +144 +00:06:12,000 --> 00:06:14,000 +basically this should work, right? + +145 +00:06:14,000 --> 00:06:16,000 +So what I'm doing is from the index.jsp, + +146 +00:06:16,000 --> 00:06:17,000 +this is my homepage. + +147 +00:06:17,000 --> 00:06:19,000 +I got two entries. + +148 +00:06:19,000 --> 00:06:22,000 +I'm calling the add alien, which will, the request goes + +149 +00:06:22,000 --> 00:06:23,000 +to the controller, which is here. + +150 +00:06:23,000 --> 00:06:25,000 +And here we are saying add alien. + +151 +00:06:25,000 --> 00:06:28,000 +It'll accept these two values, aid and aname. + +152 +00:06:28,000 --> 00:06:31,000 +Save that in two variables, aid and aname. + +153 +00:06:31,000 --> 00:06:33,000 +And then we are creating an alien object. + +154 +00:06:33,000 --> 00:06:36,000 +But you know, we forgot one thing. + +155 +00:06:36,000 --> 00:06:38,000 +In the alien, we need to set the id, + +156 +00:06:38,000 --> 00:06:41,000 +let's say aid is whatever you're sending from there. + +157 +00:06:41,000 --> 00:06:43,000 +And we have to also set the aname. + +158 +00:06:43,000 --> 00:06:47,000 +I will set the aname as aname, okay? + +159 +00:06:47,000 --> 00:06:49,000 +So whatever data I've received here, I will just put + +160 +00:06:49,000 --> 00:06:52,000 +that in the object and that object I'm sending here. + +161 +00:06:52,000 --> 00:06:54,000 +But the question is, will it work, let's try it out. + +162 +00:06:54,000 --> 00:06:57,000 +So I'll just run this and go back to the browser. + +163 +00:06:57,000 --> 00:07:00,000 +Let's say I want to go to the homepage, let's refresh. + +164 +00:07:00,000 --> 00:07:02,000 +Or maybe I can click on submit. + +165 +00:07:02,000 --> 00:07:05,000 +So when you click on submit, you can see we got data. + +166 +00:07:05,000 --> 00:07:07,000 +This is working, right, so it says, Welcome to Telusko, + +167 +00:07:07,000 --> 00:07:11,000 +and then we are also printing the data. + +168 +00:07:11,000 --> 00:07:13,000 +Okay, so this is working, but, but, but. + +169 +00:07:13,000 --> 00:07:15,000 +We have one little problem here. + +170 +00:07:15,000 --> 00:07:17,000 +The problem is actually not a problem, + +171 +00:07:17,000 --> 00:07:19,000 +but then a better way to do it, don't you think? + +172 +00:07:19,000 --> 00:07:22,000 +We are accepting value one by one anyway, + +173 +00:07:22,000 --> 00:07:23,000 +we are sending this data + +174 +00:07:23,000 --> 00:07:25,000 +and then we do have the alien object + +175 +00:07:25,000 --> 00:07:28,000 +or alien class, which can represent these two values. + +176 +00:07:28,000 --> 00:07:31,000 +What if you have, your class has 10 values? + +177 +00:07:31,000 --> 00:07:33,000 +What if your class has, okay, hyper example, + +178 +00:07:33,000 --> 00:07:35,000 +let's say your class has 10 variables. + +179 +00:07:35,000 --> 00:07:38,000 +In that case, in this particular bracket, you have + +180 +00:07:38,000 --> 00:07:42,000 +to write 10 times at the rate request per not cool, right? + +181 +00:07:42,000 --> 00:07:45,000 +So can we just remove this + +182 +00:07:45,000 --> 00:07:49,000 +and accept with one particular object? + +183 +00:07:49,000 --> 00:07:51,000 +Okay, that will be good, right, so how do we do that? + +184 +00:07:51,000 --> 00:07:53,000 +Let's see, the next video again, you know the title + +185 +00:07:53,000 --> 00:07:58,000 +of the video it says Need for Model Attribute. + +186 +00:07:58,000 --> 00:07:59,000 +So yeah, we are going to use model attribute + +187 +00:07:59,000 --> 00:08:00,000 +to solve this problem. + diff --git a/12 - Spring Boot Web/018 Source-Code.url b/12 - Spring Boot Web/018 Source-Code.url new file mode 100644 index 0000000000000000000000000000000000000000..20f5713a15fb3df3beaca9f2397129a9a10c4f6c --- /dev/null +++ b/12 - Spring Boot Web/018 Source-Code.url @@ -0,0 +1,2 @@ +[InternetShortcut] +URL=https://github.com/navinreddy20/spring6-course/tree/f1161e151ea06b68810b3cae03005d4955a96a8b/6%20Spring%20%20Boot%20Web/5.18%20Need%20for%20ModelAttribute \ No newline at end of file diff --git a/12 - Spring Boot Web/019 Source-Code.url b/12 - Spring Boot Web/019 Source-Code.url new file mode 100644 index 0000000000000000000000000000000000000000..4eb84ec86daca91659f9833244d17330fbe0cfa3 --- /dev/null +++ b/12 - Spring Boot Web/019 Source-Code.url @@ -0,0 +1,2 @@ +[InternetShortcut] +URL=https://github.com/navinreddy20/spring6-course/tree/f1161e151ea06b68810b3cae03005d4955a96a8b/6%20Spring%20%20Boot%20Web/5.19%20Using%20ModelAttribute \ No newline at end of file diff --git a/12 - Spring Boot Web/019 Using ModelAttribute_en.srt b/12 - Spring Boot Web/019 Using ModelAttribute_en.srt new file mode 100644 index 0000000000000000000000000000000000000000..7b7afa72fc8eca2b7ad76e27fd00f982cc5ebc09 --- /dev/null +++ b/12 - Spring Boot Web/019 Using ModelAttribute_en.srt @@ -0,0 +1,616 @@ +1 +00:00:00,000 --> 00:00:03,000 +(soft music) + +2 +00:00:03,000 --> 00:00:06,000 +-: So let's use the model attribute to solve this problem. + +3 +00:00:06,000 --> 00:00:10,000 +So instead of using request param for these two variables, + +4 +00:00:10,000 --> 00:00:12,000 +I can just remove them. + +5 +00:00:12,000 --> 00:00:15,000 +And what if I can simply use alien, alien? + +6 +00:00:15,000 --> 00:00:16,000 +Our job is done. + +7 +00:00:16,000 --> 00:00:18,000 +So what I'm expecting is from the form, + +8 +00:00:18,000 --> 00:00:20,000 +when then this data is coming, + +9 +00:00:20,000 --> 00:00:22,000 +it'll directly assign the value to the alien object. + +10 +00:00:22,000 --> 00:00:26,000 +So basically I want Spring to create this object. + +11 +00:00:26,000 --> 00:00:27,000 +Basically I don't want to do this step, + +12 +00:00:27,000 --> 00:00:29,000 +I want to skip this steps. + +13 +00:00:29,000 --> 00:00:31,000 +So I want Spring to create this object + +14 +00:00:31,000 --> 00:00:34,000 +and then assign those two values + +15 +00:00:34,000 --> 00:00:37,000 +which is coming from the browser. + +16 +00:00:37,000 --> 00:00:40,000 +So that is, not the browser but the request. + +17 +00:00:40,000 --> 00:00:41,000 +So can we do that? + +18 +00:00:41,000 --> 00:00:44,000 +So to achieve that we have to use something called + +19 +00:00:44,000 --> 00:00:46,000 +a model attribute. + +20 +00:00:46,000 --> 00:00:48,000 +Now this is the annotation which is responsible + +21 +00:00:48,000 --> 00:00:51,000 +to assign the value to the alien object. + +22 +00:00:51,000 --> 00:00:52,000 +Of course you can assign a different name to it. + +23 +00:00:52,000 --> 00:00:55,000 +So even this becomes optional. + +24 +00:00:55,000 --> 00:00:56,000 +Model view, + +25 +00:00:56,000 --> 00:00:59,000 +you can simply return the result here, lemme show you that. + +26 +00:00:59,000 --> 00:01:03,000 +So I can just remove this and instead of model and view + +27 +00:01:03,000 --> 00:01:04,000 +let's return a string again. + +28 +00:01:04,000 --> 00:01:06,000 +So you don't have to return the object. + +29 +00:01:06,000 --> 00:01:10,000 +So here we can mention I'm calling the result page. + +30 +00:01:10,000 --> 00:01:11,000 +So this object I'm receiving here + +31 +00:01:11,000 --> 00:01:14,000 +and that object will go to the JSB page. + +32 +00:01:14,000 --> 00:01:16,000 +Okay, that's what I'm expecting now. + +33 +00:01:16,000 --> 00:01:18,000 +So this step is also optional + +34 +00:01:18,000 --> 00:01:20,000 +and that can be done with the helper model object, + +35 +00:01:20,000 --> 00:01:21,000 +which we have talked about. + +36 +00:01:21,000 --> 00:01:23,000 +And now let's refresh this. + +37 +00:01:23,000 --> 00:01:24,000 +Let's see if it works. + +38 +00:01:24,000 --> 00:01:27,000 +Okay, no problem on the server, we are running it. + +39 +00:01:27,000 --> 00:01:29,000 +Let's go back to the homepage + +40 +00:01:29,000 --> 00:01:31,000 +and this time we'll enter some different data. + +41 +00:01:31,000 --> 00:01:33,000 +101, Harsh, click on submit and it worked. + +42 +00:01:33,000 --> 00:01:37,000 +You can see that we got 101 and we also got Harsh there. + +43 +00:01:37,000 --> 00:01:38,000 +So this is working. + +44 +00:01:38,000 --> 00:01:40,000 +So basically we can use a model attribute. + +45 +00:01:40,000 --> 00:01:42,000 +So let's say I want to change something. + +46 +00:01:42,000 --> 00:01:45,000 +So instead of alien, which I'm printing here, + +47 +00:01:45,000 --> 00:01:46,000 +what if I want to print alien1? + +48 +00:01:47,000 --> 00:01:48,000 +Now basically when I'm printing alien1, + +49 +00:01:48,000 --> 00:01:51,000 +let's see what happens if I restart my server + +50 +00:01:51,000 --> 00:01:52,000 +and let's go back to the homepage. + +51 +00:01:52,000 --> 00:01:55,000 +If I click on submit here with different data, + +52 +00:01:55,000 --> 00:01:57,000 +you can see it's not working. + +53 +00:01:57,000 --> 00:02:01,000 +Reason you are sending this data with a name alien + +54 +00:02:01,000 --> 00:02:04,000 +but what you are receiving here is alien1. + +55 +00:02:04,000 --> 00:02:06,000 +So what if you want to have alien1 here? + +56 +00:02:06,000 --> 00:02:10,000 +So what you can do is you can give that name here. + +57 +00:02:10,000 --> 00:02:11,000 +So you can say alien1. + +58 +00:02:11,000 --> 00:02:14,000 +So now this name will be representing there. + +59 +00:02:14,000 --> 00:02:18,000 +So let's try and go back, say submit. + +60 +00:02:18,000 --> 00:02:19,000 +So you can see it works. + +61 +00:02:19,000 --> 00:02:21,000 +So basically if you want to have a different name + +62 +00:02:21,000 --> 00:02:24,000 +than alien, then you have to mention that thing here. + +63 +00:02:24,000 --> 00:02:25,000 +But what if it's the same name? + +64 +00:02:25,000 --> 00:02:29,000 +What if it is alien and go back here + +65 +00:02:29,000 --> 00:02:31,000 +and let's remove this. + +66 +00:02:31,000 --> 00:02:32,000 +So this will work, right? + +67 +00:02:32,000 --> 00:02:36,000 +But what if I also remove the model attribute? + +68 +00:02:36,000 --> 00:02:37,000 +Is it really compulsory? + +69 +00:02:37,000 --> 00:02:38,000 +Let's try. + +70 +00:02:38,000 --> 00:02:40,000 +So I'm removing model attribute now, + +71 +00:02:40,000 --> 00:02:41,000 +so there's no model attribute. + +72 +00:02:41,000 --> 00:02:46,000 +Let's go back and submit, it still works. + +73 +00:02:46,000 --> 00:02:48,000 +So basically the model attribute is optional. + +74 +00:02:48,000 --> 00:02:50,000 +It is something which comes behind the scene. + +75 +00:02:50,000 --> 00:02:53,000 +It is responsible to add your data to the alien. + +76 +00:02:53,000 --> 00:02:55,000 +So when you don't want to have a different name, + +77 +00:02:55,000 --> 00:02:57,000 +you can completely skip model attribute. + +78 +00:02:57,000 --> 00:02:59,000 +And that's why most of the time you will not see + +79 +00:02:59,000 --> 00:03:01,000 +model attribute annotation there + +80 +00:03:01,000 --> 00:03:03,000 +because most of the time we are using the same name. + +81 +00:03:03,000 --> 00:03:06,000 +But yes, if you want to have a different name here, + +82 +00:03:06,000 --> 00:03:09,000 +then we have to use the model attribute annotation. + +83 +00:03:09,000 --> 00:03:11,000 +Not just that, we can also use model attribute + +84 +00:03:11,000 --> 00:03:12,000 +on method level. + +85 +00:03:12,000 --> 00:03:16,000 +Basically we have used that for the method arguments. + +86 +00:03:16,000 --> 00:03:18,000 +But what if you want to use on a method level, + +87 +00:03:18,000 --> 00:03:20,000 +something like this. + +88 +00:03:20,000 --> 00:03:22,000 +Let's say I have this page here. + +89 +00:03:22,000 --> 00:03:23,000 +Now I'm saying welcome to Telusko, + +90 +00:03:23,000 --> 00:03:25,000 +I'm also printing the alien name + +91 +00:03:25,000 --> 00:03:29,000 +and maybe I also want to print that welcome to the course. + +92 +00:03:29,000 --> 00:03:31,000 +So I will use a P tag here + +93 +00:03:31,000 --> 00:03:32,000 +and close the P tag. + +94 +00:03:32,000 --> 00:03:36,000 +And inside this I want to say + +95 +00:03:36,000 --> 00:03:41,000 +welcome to the Java world. + +96 +00:03:41,000 --> 00:03:42,000 +Okay? + +97 +00:03:42,000 --> 00:03:44,000 +Now of course this is a Java course + +98 +00:03:44,000 --> 00:03:45,000 +so it makes sense to print this. + +99 +00:03:45,000 --> 00:03:48,000 +But what if I want to print different things + +100 +00:03:48,000 --> 00:03:49,000 +for different courses? + +101 +00:03:49,000 --> 00:03:51,000 +Let's say for blockchain it should be + +102 +00:03:51,000 --> 00:03:52,000 +welcome to the blockchain world, + +103 +00:03:52,000 --> 00:03:54,000 +welcome to the AI world, + +104 +00:03:54,000 --> 00:03:57,000 +welcome to the .NET world, something like this. + +105 +00:03:57,000 --> 00:03:58,000 +So I want this to be dynamic, + +106 +00:03:58,000 --> 00:04:01,000 +not something like Java everywhere. + +107 +00:04:01,000 --> 00:04:03,000 +So we can put that in as a variable. + +108 +00:04:03,000 --> 00:04:05,000 +So you can say variable name is course + +109 +00:04:05,000 --> 00:04:09,000 +and I can just use a dollar symbol here, right? + +110 +00:04:09,000 --> 00:04:10,000 +So we have to provide this value + +111 +00:04:10,000 --> 00:04:12,000 +because if you don't provide this value, + +112 +00:04:12,000 --> 00:04:14,000 +you can see in the home controller nowhere we are specifying + +113 +00:04:14,000 --> 00:04:16,000 +the value for the course. + +114 +00:04:16,000 --> 00:04:19,000 +And if we don't specify the value for it, + +115 +00:04:19,000 --> 00:04:22,000 +let's read on this application without specifying + +116 +00:04:22,000 --> 00:04:23,000 +any value for course. + +117 +00:04:23,000 --> 00:04:25,000 +And let's refresh the result page. + +118 +00:04:25,000 --> 00:04:28,000 +You can see it says welcome to the world, which world? + +119 +00:04:28,000 --> 00:04:30,000 +Basically it's not printing the course. + +120 +00:04:30,000 --> 00:04:31,000 +So how do I assign the value? + +121 +00:04:31,000 --> 00:04:33,000 +Of course you can assign the value from here, + +122 +00:04:33,000 --> 00:04:35,000 +you can create a model view object + +123 +00:04:35,000 --> 00:04:38,000 +or maybe you can create a model object, add the data there, + +124 +00:04:38,000 --> 00:04:42,000 +or we can create a separate method which will return + +125 +00:04:42,000 --> 00:04:43,000 +the course names. + +126 +00:04:43,000 --> 00:04:46,000 +I will say public string course name. + +127 +00:04:46,000 --> 00:04:48,000 +And of course this can be dynamic. + +128 +00:04:48,000 --> 00:04:49,000 +Now you can write some JDBC code, + +129 +00:04:49,000 --> 00:04:52,000 +you can write some database code to create your database + +130 +00:04:52,000 --> 00:04:54,000 +and check which course this person is enrolled into. + +131 +00:04:54,000 --> 00:04:58,000 +But at this point I'll just make it static. + +132 +00:04:58,000 --> 00:05:00,000 +At least we have a control now, right? + +133 +00:05:00,000 --> 00:05:01,000 +I want to return Java here + +134 +00:05:02,000 --> 00:05:04,000 +and you can return whatever you want. + +135 +00:05:04,000 --> 00:05:06,000 +You can write the complete code as I mentioned before. + +136 +00:05:06,000 --> 00:05:09,000 +But here just to keep it simple, I'm saying Java. + +137 +00:05:09,000 --> 00:05:12,000 +And here I can use a model attribute + +138 +00:05:12,000 --> 00:05:15,000 +and in the bracket I can mention the course. + +139 +00:05:15,000 --> 00:05:18,000 +So basically what we are doing is the value for the course + +140 +00:05:18,000 --> 00:05:20,000 +is whatever this particular method returns. + +141 +00:05:20,000 --> 00:05:22,000 +It is Java, so it'll say Java. + +142 +00:05:22,000 --> 00:05:25,000 +If we return something else, it'll be that particular value. + +143 +00:05:25,000 --> 00:05:28,000 +So we can use model attribute on top of the method as well. + +144 +00:05:28,000 --> 00:05:30,000 +And that's why we use it most of the time. + +145 +00:05:30,000 --> 00:05:34,000 +If you want to have some values in the result page, + +146 +00:05:34,000 --> 00:05:37,000 +which is not generated by a method or some other methods + +147 +00:05:39,000 --> 00:05:42,000 +or which is common for most of the requests. + +148 +00:05:42,000 --> 00:05:44,000 +So you can see I'm restarting the application, + +149 +00:05:44,000 --> 00:05:48,000 +let's refresh this and it worked. + +150 +00:05:48,000 --> 00:05:51,000 +Now this basically that's how you use the model attribute + +151 +00:05:51,000 --> 00:05:53,000 +on top of this. + +152 +00:05:53,000 --> 00:05:54,000 +So yeah, that's it about model attribute. + +153 +00:05:54,000 --> 00:05:57,000 +I hope it makes sense, some sense now. + +154 +00:05:57,000 --> 00:05:59,000 +When to use, when not to use the model attribute. + diff --git a/12 - Spring Boot Web/external-links.txt b/12 - Spring Boot Web/external-links.txt new file mode 100644 index 0000000000000000000000000000000000000000..656cb8e72eeda89b80ae1566caaad4a2c693e41e --- /dev/null +++ b/12 - Spring Boot Web/external-links.txt @@ -0,0 +1,51 @@ + +002 Source-Code +https://github.com/navinreddy20/spring6-course/tree/f1161e151ea06b68810b3cae03005d4955a96a8b/6%20Spring%20%20Boot%20Web/5.2%20Creating%20A%20Servlet%20Project%201 + +003 Source-Code +https://github.com/navinreddy20/spring6-course/tree/f1161e151ea06b68810b3cae03005d4955a96a8b/6%20Spring%20%20Boot%20Web/5.3%20Running%20Tomcat + +004 Source-Code +https://github.com/navinreddy20/spring6-course/tree/f1161e151ea06b68810b3cae03005d4955a96a8b/6%20Spring%20%20Boot%20Web/5.4%20Servlet%20Mapping + +005 Source-Code +https://github.com/navinreddy20/spring6-course/tree/f1161e151ea06b68810b3cae03005d4955a96a8b/6%20Spring%20%20Boot%20Web/5.5%20Responding%20To%20The%20Client + +007 Source-Code +https://github.com/navinreddy20/spring6-course/tree/f1161e151ea06b68810b3cae03005d4955a96a8b/6%20Spring%20%20Boot%20Web/5.7%20Creating%20a%20Spring%20Boot%20Web%20App%20Project + +008 Source-Code +https://github.com/navinreddy20/spring6-course/tree/f1161e151ea06b68810b3cae03005d4955a96a8b/6%20Spring%20%20Boot%20Web/5.8%20Creating%20a%20JSP%20Page + +009 Source-Code +https://github.com/navinreddy20/spring6-course/tree/f1161e151ea06b68810b3cae03005d4955a96a8b/6%20Spring%20%20Boot%20Web/5.9%20Creating%20a%20Controller + +010 Source-Code +https://github.com/navinreddy20/spring6-course/tree/f1161e151ea06b68810b3cae03005d4955a96a8b/6%20Spring%20%20Boot%20Web/5.10%20RequestMapping + +011 Source-Code +https://github.com/navinreddy20/spring6-course/tree/f1161e151ea06b68810b3cae03005d4955a96a8b/6%20Spring%20%20Boot%20Web/5.11%20Sending%20data%20to%20Controller + +012 Source-Code +https://github.com/navinreddy20/spring6-course/tree/f1161e151ea06b68810b3cae03005d4955a96a8b/6%20Spring%20%20Boot%20Web/5.12%20Accepting%20Data%20the%20servlet%20way + +013 Source-Code +https://github.com/navinreddy20/spring6-course/tree/f1161e151ea06b68810b3cae03005d4955a96a8b/6%20Spring%20%20Boot%20Web/5.13%20Display%20Data%20on%20Result%20Page + +014 Source-Code +https://github.com/navinreddy20/spring6-course/tree/f1161e151ea06b68810b3cae03005d4955a96a8b/6%20Spring%20%20Boot%20Web/5.14%20RequestParam + +015 Source-Code +https://github.com/navinreddy20/spring6-course/tree/f1161e151ea06b68810b3cae03005d4955a96a8b/6%20Spring%20%20Boot%20Web/5.15%20Model%20Object + +016 Source-Code +https://github.com/navinreddy20/spring6-course/tree/f1161e151ea06b68810b3cae03005d4955a96a8b/6%20Spring%20%20Boot%20Web/5.16%20Setting%20Prefix%20and%20Suffix + +017 Source-Code +https://github.com/navinreddy20/spring6-course/tree/f1161e151ea06b68810b3cae03005d4955a96a8b/6%20Spring%20%20Boot%20Web/5.17%20ModelAndView + +018 Source-Code +https://github.com/navinreddy20/spring6-course/tree/f1161e151ea06b68810b3cae03005d4955a96a8b/6%20Spring%20%20Boot%20Web/5.18%20Need%20for%20ModelAttribute + +019 Source-Code +https://github.com/navinreddy20/spring6-course/tree/f1161e151ea06b68810b3cae03005d4955a96a8b/6%20Spring%20%20Boot%20Web/5.19%20Using%20ModelAttribute diff --git a/13 - Exploring Web MVC without Spring Boot/001 Spring MVC Introduction_en.srt b/13 - Exploring Web MVC without Spring Boot/001 Spring MVC Introduction_en.srt new file mode 100644 index 0000000000000000000000000000000000000000..cb07411f546f20ca73cb80125598185126167848 --- /dev/null +++ b/13 - Exploring Web MVC without Spring Boot/001 Spring MVC Introduction_en.srt @@ -0,0 +1,316 @@ +1 +00:00:00,000 --> 00:00:03,000 +(gentle music) + +2 +00:00:03,000 --> 00:00:06,000 +-: In this module, we'll talk about Spring MVC. + +3 +00:00:06,000 --> 00:00:07,000 +Now you will say, "Hey, we have done that before," right? + +4 +00:00:07,000 --> 00:00:10,000 +We have talked about Spring MVC. + +5 +00:00:10,000 --> 00:00:12,000 +Actually we talked about Spring Boot MVC. + +6 +00:00:12,000 --> 00:00:14,000 +So basically, we have used MVC, + +7 +00:00:14,000 --> 00:00:16,000 +but then with the help of Spring Boot. + +8 +00:00:16,000 --> 00:00:19,000 +Now, what it does is it makes our job easy + +9 +00:00:19,000 --> 00:00:20,000 +and that's what we have done, right? + +10 +00:00:20,000 --> 00:00:23,000 +So basically, we were able to build the controller. + +11 +00:00:23,000 --> 00:00:24,000 +We were able to go to our page. + +12 +00:00:24,000 --> 00:00:25,000 +So, what page I'm talking about? + +13 +00:00:25,000 --> 00:00:28,000 +So if I run this application once again, + +14 +00:00:28,000 --> 00:00:31,000 +just show you what we have done till now. + +15 +00:00:31,000 --> 00:00:33,000 +If I go to the homepage, + +16 +00:00:33,000 --> 00:00:34,000 +you can say it is giving you this page + +17 +00:00:34,000 --> 00:00:38,000 +because we have done with the UI, with the controllers, + +18 +00:00:38,000 --> 00:00:41,000 +I mean controllers, property files, + +19 +00:00:41,000 --> 00:00:43,000 +we have done some configuration here, right? + +20 +00:00:43,000 --> 00:00:44,000 +Now, this works, + +21 +00:00:44,000 --> 00:00:47,000 +but then we have talked about Spring Boot, right? + +22 +00:00:47,000 --> 00:00:49,000 +It makes your work easy. + +23 +00:00:49,000 --> 00:00:51,000 +There's another way of doing the same thing + +24 +00:00:51,000 --> 00:00:52,000 +without Spring Boot. + +25 +00:00:52,000 --> 00:00:56,000 +That is, with the help of Spring Framework directly. + +26 +00:00:56,000 --> 00:00:58,000 +So, we have a component called Spring MVC + +27 +00:00:58,000 --> 00:01:00,000 +which we're going to focus in this section. + +28 +00:01:00,000 --> 00:01:02,000 +Now here, we'll do the same thing, okay? + +29 +00:01:02,000 --> 00:01:04,000 +Same project, maybe we'll reuse the code, + +30 +00:01:04,000 --> 00:01:06,000 +but we'll not be using Spring Boot. + +31 +00:01:06,000 --> 00:01:11,000 +That means we have to do lot of configuration by ourself + +32 +00:01:11,000 --> 00:01:14,000 +and in the entire section, of course, nothing will be new + +33 +00:01:14,000 --> 00:01:17,000 +because the flow will be same, the controller will be same. + +34 +00:01:17,000 --> 00:01:19,000 +What will change is the configuration. + +35 +00:01:19,000 --> 00:01:21,000 +So I want your focus mostly on the configuration, + +36 +00:01:21,000 --> 00:01:23,000 +not on the other things. + +37 +00:01:23,000 --> 00:01:24,000 +So, what are the things we need? + +38 +00:01:24,000 --> 00:01:26,000 +Now, first of all, if you want to build web application + +39 +00:01:26,000 --> 00:01:27,000 +without Spring Boot, + +40 +00:01:27,000 --> 00:01:30,000 +basically in this project we have used a embedded Tomcat. + +41 +00:01:30,000 --> 00:01:31,000 +But then in Spring Framework, + +42 +00:01:31,000 --> 00:01:34,000 +we'll be using a external Tomcat. + +43 +00:01:34,000 --> 00:01:35,000 +So what you need, + +44 +00:01:35,000 --> 00:01:37,000 +the first thing is the external Tomcat. + +45 +00:01:37,000 --> 00:01:39,000 +How will you get that? It's very easy. + +46 +00:01:39,000 --> 00:01:42,000 +You can just go to the Google + +47 +00:01:42,000 --> 00:01:45,000 +and search for Apache Tomcat download, + +48 +00:01:45,000 --> 00:01:47,000 +and you can get the version 10, which works. + +49 +00:01:47,000 --> 00:01:50,000 +In fact, I'll be using version 10 here. + +50 +00:01:50,000 --> 00:01:51,000 +And depend upon which OS you are using, + +51 +00:01:51,000 --> 00:01:55,000 +you can get this and it'd work. + +52 +00:01:55,000 --> 00:01:58,000 +So basically, I've got the zip folder, + +53 +00:01:58,000 --> 00:01:59,000 +then I unzipped it, + +54 +00:01:59,000 --> 00:02:01,000 +and now I have that in my Download folder. + +55 +00:02:01,000 --> 00:02:02,000 +That's the first thing you need. + +56 +00:02:02,000 --> 00:02:04,000 +The next thing you will need is a IDE. + +57 +00:02:04,000 --> 00:02:07,000 +Okay, we are using the IntelliJ, right? + +58 +00:02:07,000 --> 00:02:09,000 +But then, IntelliJ IDEA which we are using + +59 +00:02:09,000 --> 00:02:09,000 +is a community version, + +60 +00:02:09,000 --> 00:02:12,000 +which means basically we have to use... + +61 +00:02:12,000 --> 00:02:15,000 +It doesn't, by default, support the external servers. + +62 +00:02:15,000 --> 00:02:16,000 +If you want to use IntelliJ, + +63 +00:02:16,000 --> 00:02:19,000 +you can use the Ultimate version. + +64 +00:02:19,000 --> 00:02:21,000 +Now, since we want to focus on the free softwares here, + +65 +00:02:21,000 --> 00:02:23,000 +so I'm going to use Eclipse for this section + +66 +00:02:23,000 --> 00:02:26,000 +because Eclipse is free and we can run the servers. + +67 +00:02:26,000 --> 00:02:27,000 +Okay, before we go ahead, + +68 +00:02:27,000 --> 00:02:30,000 +I want to show you one more thing regarding the Tomcat. + +69 +00:02:30,000 --> 00:02:32,000 +So, you can see it says Tomcat 10. + +70 +00:02:32,000 --> 00:02:35,000 +They have made some changes from Java EE to Jakarta EE. + +71 +00:02:35,000 --> 00:02:38,000 +So basically, certain things will change in Tomcat 10. + +72 +00:02:38,000 --> 00:02:41,000 +So instead of using Java X, we are going to use Jakarta X, + +73 +00:02:41,000 --> 00:02:43,000 +I mean Jakarta, not X. + +74 +00:02:43,000 --> 00:02:45,000 +So if you don't want to use Jakarta, + +75 +00:02:45,000 --> 00:02:48,000 +you can still go back to Tomcat 9 which uses Java X, + +76 +00:02:48,000 --> 00:02:51,000 +and you can still use it. + +77 +00:02:51,000 --> 00:02:52,000 +Okay, anyway, once we got this software, + +78 +00:02:52,000 --> 00:02:54,000 +it doesn't matter which one you get, + +79 +00:02:54,000 --> 00:02:57,000 +we can start working on the same project. + diff --git a/13 - Exploring Web MVC without Spring Boot/002 Creating a Spring MVC Project_en.srt b/13 - Exploring Web MVC without Spring Boot/002 Creating a Spring MVC Project_en.srt new file mode 100644 index 0000000000000000000000000000000000000000..a3a01c8f7e56f37d68d54981d09c652bf8868d18 --- /dev/null +++ b/13 - Exploring Web MVC without Spring Boot/002 Creating a Spring MVC Project_en.srt @@ -0,0 +1,776 @@ +1 +00:00:00,000 --> 00:00:03,000 +(gentle music) + +2 +00:00:03,000 --> 00:00:05,000 +-: So the first step here is to get IDE. + +3 +00:00:05,000 --> 00:00:07,000 +We have talked about we can use Eclipse here, + +4 +00:00:07,000 --> 00:00:08,000 +and it's very easy. + +5 +00:00:08,000 --> 00:00:10,000 +You can just go to Google, download the Eclipse version, + +6 +00:00:10,000 --> 00:00:14,000 +but make sure you get the Eclipse Java EE version, + +7 +00:00:14,000 --> 00:00:17,000 +not normal Eclipse for Java developers. + +8 +00:00:17,000 --> 00:00:17,000 +So you have to make sure + +9 +00:00:17,000 --> 00:00:19,000 +that you get it for enterprise developers. + +10 +00:00:19,000 --> 00:00:21,000 +And once you have that, you can open Eclipse + +11 +00:00:21,000 --> 00:00:23,000 +and I'm opening Eclipse now. + +12 +00:00:23,000 --> 00:00:25,000 +Okay, so this is my Eclipse here + +13 +00:00:25,000 --> 00:00:29,000 +and then I'm using a workspace name as spring. + +14 +00:00:29,000 --> 00:00:31,000 +Of course, when you open Eclipse, it will ask you + +15 +00:00:31,000 --> 00:00:33,000 +for a name, for the workspace, + +16 +00:00:33,000 --> 00:00:34,000 +just mention whatever you want. + +17 +00:00:34,000 --> 00:00:36,000 +I have a workspace here with name spring. + +18 +00:00:36,000 --> 00:00:38,000 +Okay, so in this, let's create a project. + +19 +00:00:38,000 --> 00:00:40,000 +Now since we are not using Spring Boot, + +20 +00:00:40,000 --> 00:00:43,000 +so we'll not be going to the official Spring initializer, + +21 +00:00:43,000 --> 00:00:45,000 +we will be using the Maven project. + +22 +00:00:45,000 --> 00:00:48,000 +So here let me create a Maven project. + +23 +00:00:48,000 --> 00:00:52,000 +So I will just go to the File, and say New, Maven Project. + +24 +00:00:52,000 --> 00:00:53,000 +Now since this will be a web application, + +25 +00:00:53,000 --> 00:00:54,000 +we'll choose a different doc type. + +26 +00:00:54,000 --> 00:00:56,000 +So just observe what I'm doing. + +27 +00:00:56,000 --> 00:00:57,000 +So I will click on Next here, + +28 +00:00:57,000 --> 00:00:59,000 +and this is where it says catalog. + +29 +00:00:59,000 --> 00:01:01,000 +I will be clicking on Internal. + +30 +00:01:01,000 --> 00:01:04,000 +In the Internal catalog, instead of going for quickstart, + +31 +00:01:04,000 --> 00:01:06,000 +we'll be going for a web application, + +32 +00:01:06,000 --> 00:01:09,000 +because we are building a Spring web application + +33 +00:01:09,000 --> 00:01:10,000 +using Spring MVC. + +34 +00:01:10,000 --> 00:01:12,000 +So select this, click on Next. + +35 +00:01:12,000 --> 00:01:13,000 +It will ask you for the group ID. + +36 +00:01:13,000 --> 00:01:15,000 +I will say group ID is com.telusko, + +37 +00:01:15,000 --> 00:01:18,000 +and the artifact ID, you can name anything you want, + +38 +00:01:18,000 --> 00:01:21,000 +but I will say SpringMVCDemo, + +39 +00:01:21,000 --> 00:01:23,000 +and nothing much, click on Finish. + +40 +00:01:23,000 --> 00:01:25,000 +This will give you a beautiful Maven project. + +41 +00:01:25,000 --> 00:01:27,000 +So by the time it is happening, what I will do is + +42 +00:01:27,000 --> 00:01:29,000 +I will go back to my download + +43 +00:01:29,000 --> 00:01:32,000 +and show you how your Tomcat folder looks like. + +44 +00:01:32,000 --> 00:01:34,000 +So this is the Tomcat which I'm using, + +45 +00:01:34,000 --> 00:01:38,000 +which is Apache Tomcat 10.1.16. + +46 +00:01:38,000 --> 00:01:40,000 +And in this you can see there are different folders. + +47 +00:01:40,000 --> 00:01:43,000 +One of the important folder is bin, because in this folder, + +48 +00:01:43,000 --> 00:01:46,000 +you will find the start and stop .sh. + +49 +00:01:46,000 --> 00:01:48,000 +This is how you basically run your Tomcat. + +50 +00:01:48,000 --> 00:01:49,000 +But do we really have to use this? + +51 +00:01:49,000 --> 00:01:51,000 +We'll see that in some time. + +52 +00:01:51,000 --> 00:01:53,000 +So looks like Maven is taking some time. + +53 +00:01:53,000 --> 00:01:55,000 +So my Eclipse just crashed. Let me just do that once again. + +54 +00:01:57,000 --> 00:01:59,000 +Click on Finish. It is creating the project. + +55 +00:01:59,000 --> 00:02:01,000 +So when it's creating the project, you can see it is asking + +56 +00:02:01,000 --> 00:02:04,000 +for the group ID, artifact ID, version, and package. + +57 +00:02:04,000 --> 00:02:07,000 +I will say yes, this is what I want to go for, and done. + +58 +00:02:07,000 --> 00:02:09,000 +You can see we have project is done, + +59 +00:02:09,000 --> 00:02:11,000 +which we can see our project section here + +60 +00:02:11,000 --> 00:02:12,000 +on the left hand side. + +61 +00:02:12,000 --> 00:02:14,000 +And this is your console, this is your outline. + +62 +00:02:14,000 --> 00:02:16,000 +We'll see later. Not needed now. + +63 +00:02:16,000 --> 00:02:18,000 +Okay, so this is the project which we got. + +64 +00:02:18,000 --> 00:02:20,000 +Now in this, if you open your pom.xml, + +65 +00:02:20,000 --> 00:02:23,000 +no where we are saying this is a Spring project. + +66 +00:02:23,000 --> 00:02:25,000 +So if you want this to work, we have to make sure + +67 +00:02:25,000 --> 00:02:28,000 +that you get your Spring dependencies here, okay? + +68 +00:02:28,000 --> 00:02:30,000 +Now why? I will show you in some time. + +69 +00:02:30,000 --> 00:02:31,000 +Let's see the folder structure. + +70 +00:02:31,000 --> 00:02:35,000 +So if you see, if you expand src, you have a main folder. + +71 +00:02:35,000 --> 00:02:38,000 +You don't have a Java folder here, that's weird. + +72 +00:02:38,000 --> 00:02:40,000 +And in this you have a webapp. + +73 +00:02:40,000 --> 00:02:43,000 +Inside this, you have index.jsp, which is this page. + +74 +00:02:43,000 --> 00:02:45,000 +And the good thing is we'll not be needing this JSP, + +75 +00:02:45,000 --> 00:02:47,000 +because we already have our two pages. + +76 +00:02:47,000 --> 00:02:50,000 +So I will delete this particular page here. + +77 +00:02:50,000 --> 00:02:52,000 +And if you go to the Java Resources, + +78 +00:02:52,000 --> 00:02:55,000 +you can see we don't have a java folder yet. + +79 +00:02:55,000 --> 00:02:57,000 +So what I will do is I will just go back to main, + +80 +00:02:57,000 --> 00:02:59,000 +and make sure that I create a java folder, + +81 +00:02:59,000 --> 00:03:02,000 +it's because I'll be putting my code there. + +82 +00:03:02,000 --> 00:03:04,000 +So you can see I got a java folder now, + +83 +00:03:04,000 --> 00:03:06,000 +and now from where you will get the code? + +84 +00:03:06,000 --> 00:03:09,000 +So first of all, even before we do any configuration, + +85 +00:03:09,000 --> 00:03:11,000 +let's get the code from our Spring Boot project + +86 +00:03:11,000 --> 00:03:15,000 +and put it here and let's see how it fails, okay? + +87 +00:03:15,000 --> 00:03:17,000 +So I will go back to my IDE, + +88 +00:03:17,000 --> 00:03:20,000 +and from here, we are going to get some files. + +89 +00:03:20,000 --> 00:03:21,000 +So first of all we'll get the files, + +90 +00:03:21,000 --> 00:03:23,000 +which is these three files. + +91 +00:03:23,000 --> 00:03:24,000 +In fact, we don't need the main code, + +92 +00:03:24,000 --> 00:03:27,000 +we just need Alien and HomeController. + +93 +00:03:27,000 --> 00:03:29,000 +So let's get that. Go back to Eclipse. + +94 +00:03:29,000 --> 00:03:31,000 +And in this you can see, we don't have a package yet. + +95 +00:03:31,000 --> 00:03:33,000 +So let me create a package first. + +96 +00:03:33,000 --> 00:03:36,000 +So in the java folder, I will have the same package name + +97 +00:03:36,000 --> 00:03:37,000 +which we were using earlier, + +98 +00:03:39,000 --> 00:03:44,000 +which is com.telusko.SpringMVCDemo. + +99 +00:03:44,000 --> 00:03:47,000 +Of course, we have different end package, + +100 +00:03:47,000 --> 00:03:48,000 +but the structure will be same. + +101 +00:03:48,000 --> 00:03:50,000 +So if we can see we don't have a package here. + +102 +00:03:50,000 --> 00:03:51,000 +So first of all, before copying this + +103 +00:03:51,000 --> 00:03:54,000 +or pasting this, we'll create a package. + +104 +00:03:54,000 --> 00:03:56,000 +So it's a New, Package, + +105 +00:03:56,000 --> 00:04:00,000 +and we'll name this package as com.telusko.SpringMVCDemo. + +106 +00:04:02,000 --> 00:04:03,000 +So you can see we've got our package here, + +107 +00:04:03,000 --> 00:04:06,000 +and it should also give the folder structure in this case. + +108 +00:04:06,000 --> 00:04:10,000 +Okay, now we can simply paste it in this. So paste. + +109 +00:04:10,000 --> 00:04:11,000 +And now you can see + +110 +00:04:11,000 --> 00:04:14,000 +you will have those two particular files there. + +111 +00:04:14,000 --> 00:04:16,000 +We got Alien, and we got HomeController. + +112 +00:04:17,000 --> 00:04:19,000 +Okay, nothing fancy, simple stuff, + +113 +00:04:19,000 --> 00:04:21,000 +but we just have to make sure + +114 +00:04:21,000 --> 00:04:25,000 +that we use a proper packaging now, which is SpringBootDemo, + +115 +00:04:25,000 --> 00:04:27,000 +I mean SpringMVCDemo, not boot, done. + +116 +00:04:27,000 --> 00:04:29,000 +So you can see we got the packages, + +117 +00:04:29,000 --> 00:04:31,000 +but if you go back to the HomeController, + +118 +00:04:31,000 --> 00:04:33,000 +there are lot of errors here. + +119 +00:04:33,000 --> 00:04:36,000 +And what are the errors? It says Jakarta not found, okay? + +120 +00:04:36,000 --> 00:04:38,000 +In fact, we don't even need this servlet code, + +121 +00:04:38,000 --> 00:04:39,000 +or do we have? + +122 +00:04:39,000 --> 00:04:43,000 +HttpServlet is used nowhere. We can remove that. + +123 +00:04:43,000 --> 00:04:45,000 +Next we want this Spring Framework. + +124 +00:04:45,000 --> 00:04:48,000 +And in this project we don't have Spring Framework. + +125 +00:04:48,000 --> 00:04:49,000 +So we'll do that in some time. + +126 +00:04:49,000 --> 00:04:52,000 +Next, I want to make sure that I get my JSP files. + +127 +00:04:52,000 --> 00:04:56,000 +So if you can see, we do have a webapp folder here, webapp. + +128 +00:04:56,000 --> 00:04:59,000 +Inside this, I want to paste my JSP files. + +129 +00:04:59,000 --> 00:05:03,000 +So if you can go back here, pick up the views folder itself + +130 +00:05:03,000 --> 00:05:04,000 +and paste in this webapp. + +131 +00:05:04,000 --> 00:05:06,000 +And you can see we got views here. + +132 +00:05:06,000 --> 00:05:08,000 +Some issue with the Eclipse, doesn't matter. + +133 +00:05:08,000 --> 00:05:10,000 +We'll see if this works or not. + +134 +00:05:10,000 --> 00:05:11,000 +But we ought to make sure, + +135 +00:05:11,000 --> 00:05:13,000 +I mean we have copied the important files, right? + +136 +00:05:13,000 --> 00:05:15,000 +Apart from this, there's no other file we have to copy. + +137 +00:05:15,000 --> 00:05:17,000 +Of course you can get CSS, + +138 +00:05:17,000 --> 00:05:19,000 +but in this particular section we'll skip CSS, + +139 +00:05:19,000 --> 00:05:21,000 +because it needs additional configuration. + +140 +00:05:21,000 --> 00:05:24,000 +And our motto is not to build beautiful UI here, right? + +141 +00:05:24,000 --> 00:05:27,000 +Our motto here is to build a better backend. + +142 +00:05:27,000 --> 00:05:28,000 +In the application.properties, + +143 +00:05:28,000 --> 00:05:29,000 +we don't have to set anything here, + +144 +00:05:29,000 --> 00:05:31,000 +because in the Spring MVC project, + +145 +00:05:31,000 --> 00:05:33,000 +we are not going to use property files. + +146 +00:05:33,000 --> 00:05:37,000 +We'll be using the old pattern of XML files, we'll use that. + +147 +00:05:37,000 --> 00:05:39,000 +Next we have to get the dependencies. + +148 +00:05:39,000 --> 00:05:42,000 +And you can see, here, we have used the Jasper + +149 +00:05:42,000 --> 00:05:47,000 +to convert the JSPs and we got the spring-boot-starter-web. + +150 +00:05:48,000 --> 00:05:50,000 +Anything else we need? Nothing. + +151 +00:05:50,000 --> 00:05:52,000 +But then we are not going to use the Spring Boot, right? + +152 +00:05:52,000 --> 00:05:54,000 +So what dependency I need? + +153 +00:05:54,000 --> 00:05:57,000 +So we need three dependencies first of all. + +154 +00:05:57,000 --> 00:05:59,000 +Depend upon which Tomcat version you're using. + +155 +00:05:59,000 --> 00:06:01,000 +If you are working with Tomcat 9, + +156 +00:06:01,000 --> 00:06:04,000 +you might not need the JSTL dependency. + +157 +00:06:04,000 --> 00:06:06,000 +But let's start with the first one. + +158 +00:06:06,000 --> 00:06:08,000 +The first dependency you need is Spring Framework, + +159 +00:06:08,000 --> 00:06:11,000 +but then Spring MVC, actually not framework. + +160 +00:06:11,000 --> 00:06:14,000 +So when you search for Spring MVC, this is what you need. + +161 +00:06:14,000 --> 00:06:16,000 +Spring Web MVC, click on this, + +162 +00:06:16,000 --> 00:06:19,000 +and you can get this one, 6.1.0, + +163 +00:06:19,000 --> 00:06:20,000 +depending on when you're watching this. + +164 +00:06:20,000 --> 00:06:24,000 +If you're watching after some time, pick up the second last + +165 +00:06:24,000 --> 00:06:27,000 +or third last one, which has a more usage. + +166 +00:06:27,000 --> 00:06:31,000 +So click on 6.1.0, get this dependency. + +167 +00:06:31,000 --> 00:06:33,000 +And in the Eclipse, make sure + +168 +00:06:33,000 --> 00:06:36,000 +that you go to your pom.xml file. + +169 +00:06:36,000 --> 00:06:39,000 +And inside this, just add this dependency. + +170 +00:06:39,000 --> 00:06:40,000 +So that's the first dependency we need, + +171 +00:06:40,000 --> 00:06:42,000 +which is for Spring MVC. + +172 +00:06:42,000 --> 00:06:45,000 +And the moment you do that in the Eclipse, + +173 +00:06:45,000 --> 00:06:49,000 +if you see the libraries here in the Maven Dependencies, + +174 +00:06:49,000 --> 00:06:51,000 +you will get all the Spring dependencies. + +175 +00:06:51,000 --> 00:06:51,000 +That's the first step. + +176 +00:06:51,000 --> 00:06:54,000 +And if you go back to HomeController, + +177 +00:06:54,000 --> 00:06:56,000 +you can see we don't have any errors now. + +178 +00:06:56,000 --> 00:06:58,000 +We got all the things which are needed. + +179 +00:06:58,000 --> 00:07:00,000 +Okay, that's good. So that's it. + +180 +00:07:00,000 --> 00:07:03,000 +You know, we got the pages, we got the Java code, + +181 +00:07:03,000 --> 00:07:05,000 +and we also got the dependency. + +182 +00:07:05,000 --> 00:07:06,000 +Let's see if this works, + +183 +00:07:06,000 --> 00:07:08,000 +and if it fails, let's see, how do we solve it? + +184 +00:07:08,000 --> 00:07:11,000 +But before running this, we have to make sure + +185 +00:07:11,000 --> 00:07:13,000 +that in your Eclipse we have a server. + +186 +00:07:13,000 --> 00:07:14,000 +Because when you try to run this, + +187 +00:07:14,000 --> 00:07:15,000 +how would you run this project? + +188 +00:07:15,000 --> 00:07:17,000 +If you say right click here, and Run As, + +189 +00:07:17,000 --> 00:07:19,000 +if you click on Run on Server, + +190 +00:07:19,000 --> 00:07:22,000 +we don't have a server here, we have to connect it. + +191 +00:07:22,000 --> 00:07:24,000 +So how do we do that? Simple step. + +192 +00:07:24,000 --> 00:07:27,000 +You can click on this no server, + +193 +00:07:27,000 --> 00:07:29,000 +but we'll see that in the next video, + +194 +00:07:29,000 --> 00:07:30,000 +how do you set up a Tomcat here. + diff --git a/13 - Exploring Web MVC without Spring Boot/002 Source-Code.url b/13 - Exploring Web MVC without Spring Boot/002 Source-Code.url new file mode 100644 index 0000000000000000000000000000000000000000..dfaa3c0c01ce28652ed100bfdcbe7d72d7cdf379 --- /dev/null +++ b/13 - Exploring Web MVC without Spring Boot/002 Source-Code.url @@ -0,0 +1,2 @@ +[InternetShortcut] +URL=https://github.com/navinreddy20/spring6-course/tree/f1161e151ea06b68810b3cae03005d4955a96a8b/7%20Exploring%20Web%20MVC%20without%20Spring%20Boot/6.2%20Creating%20a%20Spring%20MVC%20Project_1 \ No newline at end of file diff --git a/13 - Exploring Web MVC without Spring Boot/003 Running Tomcat in Eclipse_en.srt b/13 - Exploring Web MVC without Spring Boot/003 Running Tomcat in Eclipse_en.srt new file mode 100644 index 0000000000000000000000000000000000000000..46496fb1d21a9cda3ccb9aaa82ecf495abbe1d99 --- /dev/null +++ b/13 - Exploring Web MVC without Spring Boot/003 Running Tomcat in Eclipse_en.srt @@ -0,0 +1,228 @@ +1 +00:00:00,000 --> 00:00:03,000 +(gentle music) + +2 +00:00:03,000 --> 00:00:04,000 +-: Now, let's see, + +3 +00:00:04,000 --> 00:00:06,000 +how do you set up a Tomcat in Eclipse + +4 +00:00:06,000 --> 00:00:08,000 +and how do you connect your project to that Tomcat? + +5 +00:00:08,000 --> 00:00:10,000 +So if you go to the Servers tabs here, + +6 +00:00:10,000 --> 00:00:12,000 +you can click on "No servers are available". + +7 +00:00:12,000 --> 00:00:13,000 +It will give you a prompt. + +8 +00:00:13,000 --> 00:00:14,000 +Now, we have to add a server. + +9 +00:00:14,000 --> 00:00:17,000 +Now you can select the server which you want to add. + +10 +00:00:17,000 --> 00:00:19,000 +This time we want to go for Tomcat. + +11 +00:00:19,000 --> 00:00:21,000 +So I will click on Apache and scroll down. + +12 +00:00:21,000 --> 00:00:24,000 +We are going for Tomcat v10.1, click next. + +13 +00:00:24,000 --> 00:00:27,000 +Now this is where you have to select a path + +14 +00:00:27,000 --> 00:00:29,000 +where you have your Tomcat downloaded. + +15 +00:00:29,000 --> 00:00:30,000 +If you don't have a downloaded version, + +16 +00:00:30,000 --> 00:00:33,000 +you can click on Download and install, even that works. + +17 +00:00:33,000 --> 00:00:35,000 +But I have a setup, so we click on browse. + +18 +00:00:35,000 --> 00:00:37,000 +And just navigate to Tomcat. + +19 +00:00:37,000 --> 00:00:40,000 +So basically search for this particular folder. + +20 +00:00:40,000 --> 00:00:41,000 +So I have it in my downloads. + +21 +00:00:41,000 --> 00:00:44,000 +You can just get it from the path, select the path, + +22 +00:00:44,000 --> 00:00:46,000 +and click on Next. + +23 +00:00:46,000 --> 00:00:47,000 +Do you want to, so it will ask you, + +24 +00:00:47,000 --> 00:00:49,000 +do you want to add any project to your Tomcat? + +25 +00:00:49,000 --> 00:00:52,000 +If you don't do that, so your Tomcat will run, + +26 +00:00:52,000 --> 00:00:53,000 +but not your project. + +27 +00:00:53,000 --> 00:00:57,000 +So we can shift our project inside this and click on Finish. + +28 +00:00:57,000 --> 00:01:00,000 +So now we have a Tomcat, which is in Stopped stage. + +29 +00:01:00,000 --> 00:01:03,000 +But if we expand this, we have a Spring project there. + +30 +00:01:03,000 --> 00:01:07,000 +And if you start this Tomcat, let's see if that works. + +31 +00:01:07,000 --> 00:01:08,000 +I will click on start. + +32 +00:01:08,000 --> 00:01:10,000 +Okay, it says it's already in use. + +33 +00:01:10,000 --> 00:01:14,000 +It's because in the IntelliJ, I have not stopped it. + +34 +00:01:14,000 --> 00:01:15,000 +We are using the same port number. + +35 +00:01:15,000 --> 00:01:17,000 +If you want to change the port number, you can do that. + +36 +00:01:17,000 --> 00:01:18,000 +But here I don't want to do that. + +37 +00:01:18,000 --> 00:01:20,000 +So I will just, you can see we have an icon here. + +38 +00:01:20,000 --> 00:01:22,000 +Restart the server, Relaunch. + +39 +00:01:22,000 --> 00:01:24,000 +Okay, we'll start it from here + +40 +00:01:25,000 --> 00:01:27,000 +and you can see the Tomcat started. + +41 +00:01:27,000 --> 00:01:29,000 +Okay, so that's good, + +42 +00:01:29,000 --> 00:01:30,000 +but now we have to run the project. + +43 +00:01:30,000 --> 00:01:32,000 +So I will just right-click here. + +44 +00:01:32,000 --> 00:01:34,000 +Say Run As, Run on Server. + +45 +00:01:34,000 --> 00:01:36,000 +We already have a Tomcat server here. + +46 +00:01:36,000 --> 00:01:40,000 +Click on Next, Finish, and boom. + +47 +00:01:40,000 --> 00:01:43,000 +So you can see, it has opened a browser for us. + +48 +00:01:43,000 --> 00:01:45,000 +I'll be using my own browser. + +49 +00:01:45,000 --> 00:01:49,000 +And the URL is localhost:8080, enter. + +50 +00:01:49,000 --> 00:01:50,000 +It's not working. + +51 +00:01:50,000 --> 00:01:51,000 +Something is not working. + +52 +00:01:51,000 --> 00:01:52,000 +Okay, what is that? + +53 +00:01:52,000 --> 00:01:55,000 +So let's search if it is working, + +54 +00:01:55,000 --> 00:01:56,000 +you can see it is not working. + +55 +00:01:56,000 --> 00:01:59,000 +It says "resource is not available". + +56 +00:01:59,000 --> 00:02:00,000 +Okay, so it is not working. + +57 +00:02:00,000 --> 00:02:03,000 +But why? Let's understand that in the next video. + diff --git a/13 - Exploring Web MVC without Spring Boot/003 Source-Code.url b/13 - Exploring Web MVC without Spring Boot/003 Source-Code.url new file mode 100644 index 0000000000000000000000000000000000000000..0e1cb0bf3785127e913f25d5668e247b83d14859 --- /dev/null +++ b/13 - Exploring Web MVC without Spring Boot/003 Source-Code.url @@ -0,0 +1,2 @@ +[InternetShortcut] +URL=https://github.com/navinreddy20/spring6-course/tree/f1161e151ea06b68810b3cae03005d4955a96a8b/7%20Exploring%20Web%20MVC%20without%20Spring%20Boot/6.3%20Running%20Tomcat%20in%20Eclipse \ No newline at end of file diff --git a/13 - Exploring Web MVC without Spring Boot/004 Dispatcher Servlet_en.srt b/13 - Exploring Web MVC without Spring Boot/004 Dispatcher Servlet_en.srt new file mode 100644 index 0000000000000000000000000000000000000000..6b9d98cdbeaa2b2385a01f2cc931be76551a4df1 --- /dev/null +++ b/13 - Exploring Web MVC without Spring Boot/004 Dispatcher Servlet_en.srt @@ -0,0 +1,812 @@ +1 +00:00:00,000 --> 00:00:03,000 +(gentle music) + +2 +00:00:03,000 --> 00:00:06,000 +-: So, we have created this project off SpringMVC, + +3 +00:00:06,000 --> 00:00:07,000 +and that is a Maven project, right? + +4 +00:00:07,000 --> 00:00:09,000 +And then, when we were trying to run the project, + +5 +00:00:09,000 --> 00:00:10,000 +it is not working. + +6 +00:00:10,000 --> 00:00:12,000 +Now, mind you, we do have a controller. + +7 +00:00:12,000 --> 00:00:15,000 +So if you see the code, we do have a controller here, + +8 +00:00:15,000 --> 00:00:16,000 +which is HomeController. + +9 +00:00:16,000 --> 00:00:20,000 +And then, we do have a mapping for the homepage. + +10 +00:00:20,000 --> 00:00:22,000 +It should return the index.jsp, + +11 +00:00:22,000 --> 00:00:25,000 +but what you got here is not found. + +12 +00:00:25,000 --> 00:00:26,000 +What went wrong here? + +13 +00:00:26,000 --> 00:00:29,000 +See, the thing is, this is not a Spring Boot project. + +14 +00:00:29,000 --> 00:00:31,000 +This is a normal Maven project. + +15 +00:00:31,000 --> 00:00:34,000 +Now even if you added your Spring dependencies here, + +16 +00:00:34,000 --> 00:00:37,000 +your Maven has no idea that it has to call + +17 +00:00:37,000 --> 00:00:38,000 +this particular controller. + +18 +00:00:38,000 --> 00:00:40,000 +It's because in this Maven project, + +19 +00:00:40,000 --> 00:00:42,000 +which we are running on Tomcat, + +20 +00:00:42,000 --> 00:00:44,000 +now Tomcat being a Servlet Container, + +21 +00:00:44,000 --> 00:00:47,000 +it is responsible to run the servlets. + +22 +00:00:47,000 --> 00:00:49,000 +But then there has to be mapping, right? + +23 +00:00:49,000 --> 00:00:53,000 +So there have to be a mapping for a request and a servlet. + +24 +00:00:53,000 --> 00:00:54,000 +And we are not doing that. + +25 +00:00:54,000 --> 00:00:56,000 +Of course, we will say there is a controller, + +26 +00:00:56,000 --> 00:00:59,000 +but then your Tomcat has no idea. + +27 +00:00:59,000 --> 00:01:00,000 +The thing is, in Spring Framework, + +28 +00:01:00,000 --> 00:01:02,000 +we can have multiple controllers, right? + +29 +00:01:02,000 --> 00:01:04,000 +As I mentioned before, for different requests, + +30 +00:01:04,000 --> 00:01:05,000 +we'll be having different controllers. + +31 +00:01:05,000 --> 00:01:07,000 +And to navigate to different controllers, + +32 +00:01:07,000 --> 00:01:09,000 +we have our Front controllers. + +33 +00:01:09,000 --> 00:01:11,000 +So basically, you have a client, + +34 +00:01:11,000 --> 00:01:13,000 +and then you have a lot of controllers on the other side. + +35 +00:01:13,000 --> 00:01:15,000 +But when a client sends a request, + +36 +00:01:15,000 --> 00:01:17,000 +the request will not directly go to a particular controller. + +37 +00:01:17,000 --> 00:01:20,000 +The request will go to something called a Front controller. + +38 +00:01:20,000 --> 00:01:22,000 +Now, this sits in between. + +39 +00:01:22,000 --> 00:01:24,000 +And your Front controller is responsible + +40 +00:01:24,000 --> 00:01:26,000 +to send a particular request + +41 +00:01:26,000 --> 00:01:27,000 +to a particular controller. + +42 +00:01:27,000 --> 00:01:29,000 +So let's say if you request for the homepage, + +43 +00:01:29,000 --> 00:01:31,000 +it is a job of your Front controller to know + +44 +00:01:31,000 --> 00:01:32,000 +that I have a controller here + +45 +00:01:32,000 --> 00:01:35,000 +who can accept the request for the homepage. + +46 +00:01:35,000 --> 00:01:37,000 +Let's say you request for an addition of two numbers. + +47 +00:01:37,000 --> 00:01:38,000 +You are saying add. + +48 +00:01:38,000 --> 00:01:39,000 +Now, you have a controller there + +49 +00:01:39,000 --> 00:01:41,000 +who is responsible to add two numbers. + +50 +00:01:41,000 --> 00:01:43,000 +Now, your front controller will know that, + +51 +00:01:43,000 --> 00:01:45,000 +hey, we have a controller there who can add two numbers + +52 +00:01:45,000 --> 00:01:47,000 +with a request "add". + +53 +00:01:47,000 --> 00:01:48,000 +Now, this controller, + +54 +00:01:48,000 --> 00:01:50,000 +the Front controller in Spring Framework + +55 +00:01:50,000 --> 00:01:53,000 +is called a DispatcherServlet. + +56 +00:01:53,000 --> 00:01:56,000 +So this is the first servlet which you have to go to. + +57 +00:01:56,000 --> 00:01:59,000 +And then this will navigate to different controllers. + +58 +00:01:59,000 --> 00:02:01,000 +Now, in this project, we do have a controller, + +59 +00:02:01,000 --> 00:02:03,000 +but we don't have a DispatcherServlet. + +60 +00:02:03,000 --> 00:02:07,000 +Now, do we have to create our own DispatcherServlet? No. + +61 +00:02:07,000 --> 00:02:08,000 +Basically, Spring says, + +62 +00:02:08,000 --> 00:02:10,000 +don't worry, I do have a DispatcherServlet, + +63 +00:02:10,000 --> 00:02:11,000 +you just have to configure it. + +64 +00:02:11,000 --> 00:02:13,000 +So you have to tell your Tomcat, + +65 +00:02:13,000 --> 00:02:15,000 +hey, you know, every time you send a request, + +66 +00:02:15,000 --> 00:02:18,000 +send the request to the DispatcherServlet. + +67 +00:02:18,000 --> 00:02:19,000 +DispatcherServlet will take care + +68 +00:02:19,000 --> 00:02:21,000 +of the remaining operations. + +69 +00:02:21,000 --> 00:02:22,000 +Now, how will you configure that? + +70 +00:02:22,000 --> 00:02:25,000 +Now see, one of the file which goes, + +71 +00:02:25,000 --> 00:02:26,000 +I mean every time you run this project, + +72 +00:02:26,000 --> 00:02:29,000 +your Tomcat goes to one file, + +73 +00:02:29,000 --> 00:02:31,000 +which is the web.xml. + +74 +00:02:31,000 --> 00:02:32,000 +Now, this is where you have to mention, + +75 +00:02:32,000 --> 00:02:33,000 +hey, you know, when you send a request, + +76 +00:02:33,000 --> 00:02:36,000 +send request to this particular servlet. + +77 +00:02:36,000 --> 00:02:39,000 +And the way you do that is by providing two tags. + +78 +00:02:39,000 --> 00:02:43,000 +So basically the first tag is the servlet tag + +79 +00:02:43,000 --> 00:02:47,000 +and the second one is the servlet-mapping tag. + +80 +00:02:47,000 --> 00:02:49,000 +So basically, we have to use this too, + +81 +00:02:49,000 --> 00:02:51,000 +which is servlet tag and servlet-mapping tag. + +82 +00:02:51,000 --> 00:02:53,000 +Now, in this servlet mapping, + +83 +00:02:53,000 --> 00:02:57,000 +basically this is where you mention the url-pattern. + +84 +00:02:57,000 --> 00:02:59,000 +So you can say for all the requests, + +85 +00:02:59,000 --> 00:03:01,000 +doesn't matter what request we are getting. + +86 +00:03:01,000 --> 00:03:03,000 +For all the requests, + +87 +00:03:03,000 --> 00:03:05,000 +send the request to this particular servlet. + +88 +00:03:05,000 --> 00:03:07,000 +Now, which servlet I am talking about? + +89 +00:03:07,000 --> 00:03:10,000 +I'm talking about the DispatcherServlet. + +90 +00:03:10,000 --> 00:03:11,000 +Now, how do you get DispatcherServlet? + +91 +00:03:11,000 --> 00:03:13,000 +So, if you go to your dependency, + +92 +00:03:13,000 --> 00:03:14,000 +of course, I know the full name, + +93 +00:03:14,000 --> 00:03:16,000 +but if you want to know the full name, + +94 +00:03:16,000 --> 00:03:18,000 +even we can forgot that, right? + +95 +00:03:18,000 --> 00:03:20,000 +So if you expand your Maven Dependencies, + +96 +00:03:20,000 --> 00:03:22,000 +we see something called webmvc. + +97 +00:03:22,000 --> 00:03:24,000 +If you expand this, + +98 +00:03:24,000 --> 00:03:28,000 +there's something called "org.springframework.web.servlet." + +99 +00:03:28,000 --> 00:03:29,000 +And if you expand this, + +100 +00:03:29,000 --> 00:03:32,000 +you will find a DispatcherServlet here. + +101 +00:03:32,000 --> 00:03:34,000 +This is the class you have to use. + +102 +00:03:34,000 --> 00:03:38,000 +So I can simply copy the qualified name for it + +103 +00:03:38,000 --> 00:03:42,000 +and paste it here without the ".class" extension. + +104 +00:03:42,000 --> 00:03:42,000 +And that's done. + +105 +00:03:42,000 --> 00:03:44,000 +So what we are saying is, + +106 +00:03:44,000 --> 00:03:46,000 +every time someone sends a request for the url-mapping + +107 +00:03:46,000 --> 00:03:49,000 +or this particular URL, which is the homepage, + +108 +00:03:49,000 --> 00:03:52,000 +you have to call the DispatcherServlet. + +109 +00:03:52,000 --> 00:03:54,000 +In fact, not just the homepage, any request. + +110 +00:03:54,000 --> 00:03:56,000 +But then to map these two, + +111 +00:03:56,000 --> 00:03:57,000 +basically there are different tags, right? + +112 +00:03:57,000 --> 00:04:00,000 +Servlet and servlet-mapping are two different tags. + +113 +00:04:00,000 --> 00:04:01,000 +If you want to connect these two, + +114 +00:04:01,000 --> 00:04:03,000 +you have to add one more tag here, + +115 +00:04:03,000 --> 00:04:06,000 +which is your servlet-name. + +116 +00:04:06,000 --> 00:04:07,000 +Of course, you can name anything here. + +117 +00:04:07,000 --> 00:04:09,000 +I can say "dispatcher" or I can say "telusko". + +118 +00:04:09,000 --> 00:04:12,000 +Let's say I'm going for the servlet name as "telusko". + +119 +00:04:12,000 --> 00:04:14,000 +And here also, you have to do the same thing, + +120 +00:04:14,000 --> 00:04:16,000 +"telusko". + +121 +00:04:16,000 --> 00:04:18,000 +You have to make sure these two are the same + +122 +00:04:18,000 --> 00:04:20,000 +because you can have multiple servlet tags + +123 +00:04:20,000 --> 00:04:21,000 +in this particular file + +124 +00:04:21,000 --> 00:04:23,000 +for different URL or mapping. + +125 +00:04:23,000 --> 00:04:26,000 +But at this point, I want to make sure that I only have one. + +126 +00:04:26,000 --> 00:04:30,000 +So for all of the requests, call the display servlet. + +127 +00:04:30,000 --> 00:04:33,000 +And to map these two, we have to use "telusko", "telusko". + +128 +00:04:33,000 --> 00:04:35,000 +Okay, now we have done the mapping. + +129 +00:04:35,000 --> 00:04:37,000 +Now we are saying, hey Tomcat, + +130 +00:04:37,000 --> 00:04:38,000 +every time you get a request, + +131 +00:04:38,000 --> 00:04:40,000 +send the request to the DispatcherServlet. + +132 +00:04:40,000 --> 00:04:43,000 +DispatcherServlet will take care of the other operations. + +133 +00:04:43,000 --> 00:04:45,000 +I hope this time this will work now. + +134 +00:04:45,000 --> 00:04:47,000 +Let's run this application. + +135 +00:04:47,000 --> 00:04:49,000 +You can see there is no problem. + +136 +00:04:49,000 --> 00:04:50,000 +Tomcat started. + +137 +00:04:50,000 --> 00:04:53,000 +So let me go to the browser and run. + +138 +00:04:53,000 --> 00:04:55,000 +Okay, I think I missed one more. + +139 +00:04:55,000 --> 00:04:56,000 +Let me just change the configuration, + +140 +00:04:56,000 --> 00:04:57,000 +this is still not working. + +141 +00:04:57,000 --> 00:04:58,000 +So I will go to the Build Path. + +142 +00:04:58,000 --> 00:05:02,000 +I'm not sure if it is accepting our Tomcat data. + +143 +00:05:02,000 --> 00:05:02,000 +We'll go to library. + +144 +00:05:02,000 --> 00:05:05,000 +Okay, so we have forgot to add the Tomcat library here. + +145 +00:05:05,000 --> 00:05:07,000 +So sometimes, if it doesn't work, + +146 +00:05:07,000 --> 00:05:09,000 +please check your Build Path. + +147 +00:05:09,000 --> 00:05:13,000 +So what I did, is I right-clicked on my project, + +148 +00:05:13,000 --> 00:05:14,000 +go to the Build Path. + +149 +00:05:14,000 --> 00:05:15,000 +And that's what, you know, + +150 +00:05:15,000 --> 00:05:17,000 +when you work with normal SpringMVC + +151 +00:05:17,000 --> 00:05:18,000 +or normal Spring Framework, + +152 +00:05:18,000 --> 00:05:19,000 +you have to do a lot of configuration. + +153 +00:05:19,000 --> 00:05:21,000 +And if you're thinking you'll be doing this every time, + +154 +00:05:21,000 --> 00:05:22,000 +not exactly. + +155 +00:05:22,000 --> 00:05:24,000 +This configuration will be done only once + +156 +00:05:24,000 --> 00:05:25,000 +when you start the project. + +157 +00:05:25,000 --> 00:05:26,000 +So click on library. + +158 +00:05:26,000 --> 00:05:29,000 +First of all, I will change my Java version to Java 21 + +159 +00:05:29,000 --> 00:05:30,000 +because that's what I'm using. + +160 +00:05:30,000 --> 00:05:31,000 +Finish. + +161 +00:05:31,000 --> 00:05:35,000 +And then here, I want to add the Runtime as well. + +162 +00:05:35,000 --> 00:05:36,000 +Just on the safer side. + +163 +00:05:36,000 --> 00:05:38,000 +Click on Apply and Close. + +164 +00:05:38,000 --> 00:05:40,000 +Let's see if this works now. + +165 +00:05:40,000 --> 00:05:42,000 +Restart the server, go back, refresh. + +166 +00:05:42,000 --> 00:05:43,000 +Still not working. + +167 +00:05:43,000 --> 00:05:45,000 +Okay, so now when I'm running this, + +168 +00:05:45,000 --> 00:05:48,000 +there was some issue with the cashier or something. + +169 +00:05:48,000 --> 00:05:50,000 +So you can see when I run this now, + +170 +00:05:50,000 --> 00:05:51,000 +we got a different error. + +171 +00:05:51,000 --> 00:05:53,000 +So this time you're not getting 404. + +172 +00:05:53,000 --> 00:05:54,000 +That means it was able to find it. + +173 +00:05:54,000 --> 00:05:56,000 +We got a different error, which is the 500. + +174 +00:05:56,000 --> 00:05:59,000 +It says "Internal Server Error". + +175 +00:05:59,000 --> 00:06:01,000 +Now, if you read the error + +176 +00:06:01,000 --> 00:06:03,000 +and that's what you do when you get the errors, right? + +177 +00:06:03,000 --> 00:06:06,000 +So it says, if you see the Root Cause, + +178 +00:06:06,000 --> 00:06:09,000 +it says there is a problem with the IOException + +179 +00:06:09,000 --> 00:06:10,000 +with the XML file. + +180 +00:06:10,000 --> 00:06:12,000 +It's because it is not able to. + +181 +00:06:12,000 --> 00:06:16,000 +I mean, from this file, which is called telusko-servlet.xml. + +182 +00:06:16,000 --> 00:06:17,000 +Okay, now this is weird + +183 +00:06:17,000 --> 00:06:19,000 +because we don't even have this file + +184 +00:06:19,000 --> 00:06:21,000 +and if you go down it actually says + +185 +00:06:21,000 --> 00:06:23,000 +you don't have this file. + +186 +00:06:23,000 --> 00:06:25,000 +But why do we need this file? + +187 +00:06:25,000 --> 00:06:28,000 +I mean that's crazy, right? We got the DispatcherServlet. + +188 +00:06:28,000 --> 00:06:30,000 +It should send the request to DispatcherServlet. + +189 +00:06:30,000 --> 00:06:31,000 +And you know what? + +190 +00:06:31,000 --> 00:06:34,000 +It is actually sending the request to the DispatcherServlet. + +191 +00:06:34,000 --> 00:06:36,000 +But DispatcherServlet has its own problem. + +192 +00:06:36,000 --> 00:06:37,000 +DispatcherServlet says, if you want me to work, + +193 +00:06:37,000 --> 00:06:40,000 +and if you want me to understand different controllers + +194 +00:06:40,000 --> 00:06:43,000 +and mapping, you have to configure me. + +195 +00:06:43,000 --> 00:06:46,000 +Of course, we were expecting that the DispatcherServlet + +196 +00:06:46,000 --> 00:06:50,000 +will be a magician to know all the controllers, but not. + +197 +00:06:50,000 --> 00:06:51,000 +We have to configure that as well. + +198 +00:06:51,000 --> 00:06:53,000 +And how do you configure? + +199 +00:06:53,000 --> 00:06:55,000 +How do you talk to dispatch servlet? + +200 +00:06:55,000 --> 00:06:57,000 +And that's where we have to create this file, + +201 +00:06:57,000 --> 00:06:59,000 +which is telusko-servlet. + +202 +00:06:59,000 --> 00:07:00,000 +How do we do that? + +203 +00:07:00,000 --> 00:07:01,000 +Let's see in the next video. + diff --git a/13 - Exploring Web MVC without Spring Boot/004 Source-Code.url b/13 - Exploring Web MVC without Spring Boot/004 Source-Code.url new file mode 100644 index 0000000000000000000000000000000000000000..97053be509d52e1ed1c32061d4e755fc5f1f8afe --- /dev/null +++ b/13 - Exploring Web MVC without Spring Boot/004 Source-Code.url @@ -0,0 +1,2 @@ +[InternetShortcut] +URL=https://github.com/navinreddy20/spring6-course/tree/f1161e151ea06b68810b3cae03005d4955a96a8b/7%20Exploring%20Web%20MVC%20without%20Spring%20Boot/6.4%20Dispatcher%20Servlet \ No newline at end of file diff --git a/13 - Exploring Web MVC without Spring Boot/005 Configuring the DispatcherServlet_en.srt b/13 - Exploring Web MVC without Spring Boot/005 Configuring the DispatcherServlet_en.srt new file mode 100644 index 0000000000000000000000000000000000000000..8f3ff0abc0224b99d671def6a7a6eb332173e7f2 --- /dev/null +++ b/13 - Exploring Web MVC without Spring Boot/005 Configuring the DispatcherServlet_en.srt @@ -0,0 +1,548 @@ +1 +00:00:00,000 --> 00:00:03,000 +(gentle music) + +2 +00:00:03,000 --> 00:00:06,000 +-: It's time to configure our DispatcherServlet. + +3 +00:00:06,000 --> 00:00:08,000 +And the way you do that, the way you talk + +4 +00:00:08,000 --> 00:00:10,000 +to a DispatcherServlet is with the help of this file. + +5 +00:00:10,000 --> 00:00:12,000 +See, there are multiple ways of doing this. + +6 +00:00:12,000 --> 00:00:15,000 +You can also use the Java based configuration + +7 +00:00:15,000 --> 00:00:18,000 +using annotations, but then we'll be using XML here, + +8 +00:00:18,000 --> 00:00:20,000 +just to understand what happens behind the scene. + +9 +00:00:20,000 --> 00:00:22,000 +Okay, so I will create this file. + +10 +00:00:22,000 --> 00:00:25,000 +So this is telusko-servlet.xml. + +11 +00:00:25,000 --> 00:00:27,000 +I will create this file. But then where? + +12 +00:00:27,000 --> 00:00:29,000 +The folder is /WEB-INF. + +13 +00:00:29,000 --> 00:00:31,000 +This is where it is expecting it to be. + +14 +00:00:31,000 --> 00:00:32,000 +That's the first thing. + +15 +00:00:32,000 --> 00:00:35,000 +Second, why it has this name, telusko-servlet? + +16 +00:00:35,000 --> 00:00:37,000 +Why not something else? + +17 +00:00:37,000 --> 00:00:41,000 +It's because if you look at your project, the name + +18 +00:00:41,000 --> 00:00:43,000 +of your servlet we are mentioning as telusko, right? + +19 +00:00:43,000 --> 00:00:46,000 +That's why it says telusko-servlet. + +20 +00:00:46,000 --> 00:00:48,000 +If you give a different name, let's say + +21 +00:00:48,000 --> 00:00:51,000 +if you give a name, t1, t2, or whatever you want to, + +22 +00:00:51,000 --> 00:00:55,000 +so it will be that, what the name, -servlet.xml. + +23 +00:00:55,000 --> 00:00:57,000 +And that's why we got that particular file. + +24 +00:00:57,000 --> 00:01:00,000 +So let's create the file. So I will just right click here. + +25 +00:01:00,000 --> 00:01:01,000 +And say, "Hey, + +26 +00:01:01,000 --> 00:01:06,000 +I want to create a new XML file," which is here. + +27 +00:01:06,000 --> 00:01:11,000 +Click on Next. Name this file, which is telusko-servlet. + +28 +00:01:11,000 --> 00:01:13,000 +And if you Enter, you got your file. + +29 +00:01:13,000 --> 00:01:15,000 +And now in this, we have to do the configuration. + +30 +00:01:15,000 --> 00:01:17,000 +Now what configuration I'm talking about? + +31 +00:01:17,000 --> 00:01:19,000 +See, basically we are not, we don't have + +32 +00:01:19,000 --> 00:01:22,000 +to actually manually mention each controller. + +33 +00:01:22,000 --> 00:01:26,000 +Reason being, we are using annotations here, + +34 +00:01:26,000 --> 00:01:28,000 +you can see we are doing the mapping here. + +35 +00:01:28,000 --> 00:01:29,000 +But what if you don't want to do mapping + +36 +00:01:29,000 --> 00:01:31,000 +in the controller or in the class? + +37 +00:01:31,000 --> 00:01:33,000 +In that case, in this particular file, + +38 +00:01:33,000 --> 00:01:34,000 +you have to do all the mapping. + +39 +00:01:34,000 --> 00:01:36,000 +For this request, call this particular method, + +40 +00:01:36,000 --> 00:01:39,000 +for this request, call this particular method. + +41 +00:01:39,000 --> 00:01:40,000 +And I don't wanna do that, right? + +42 +00:01:40,000 --> 00:01:42,000 +So we do have annotation there. + +43 +00:01:42,000 --> 00:01:45,000 +So we just have to mention to your DispatcherServlet + +44 +00:01:45,000 --> 00:01:47,000 +by saying, "Hey, you know, I'm using annotations + +45 +00:01:47,000 --> 00:01:49,000 +on the controllers, just use them." + +46 +00:01:49,000 --> 00:01:51,000 +And the way you can do that is + +47 +00:01:51,000 --> 00:01:52,000 +first of all, you can mention that "Hey, you know," + +48 +00:01:52,000 --> 00:01:54,000 +you can say, "Hey, DispatcherServlet," + +49 +00:01:54,000 --> 00:01:59,000 +I can say DS, "Find the classes in this package." + +50 +00:01:59,000 --> 00:02:00,000 +You can mention the package name. + +51 +00:02:00,000 --> 00:02:02,000 +That's the first thing you have to mention. + +52 +00:02:02,000 --> 00:02:06,000 +And second, you have to mention that I'm using annotations. + +53 +00:02:06,000 --> 00:02:11,000 +So you can say, "I'm using annotations," that's it. + +54 +00:02:11,000 --> 00:02:13,000 +DispatcherServlet will know that I have + +55 +00:02:13,000 --> 00:02:15,000 +to find this file in this package, + +56 +00:02:15,000 --> 00:02:16,000 +whatever package you mention here. + +57 +00:02:16,000 --> 00:02:19,000 +And then you are saying that I'm using annotations. + +58 +00:02:19,000 --> 00:02:20,000 +Will it work? Of course not. + +59 +00:02:20,000 --> 00:02:23,000 +You know, this is XML file, not a essay book, right? + +60 +00:02:23,000 --> 00:02:26,000 +This will not work, so this is not how you write a letter + +61 +00:02:26,000 --> 00:02:27,000 +to DispatcherServlet, okay? + +62 +00:02:27,000 --> 00:02:29,000 +But then we have to do the same thing. + +63 +00:02:29,000 --> 00:02:31,000 +For that, we have to use some tags. + +64 +00:02:31,000 --> 00:02:33,000 +And whenever you use tags in XML, + +65 +00:02:33,000 --> 00:02:36,000 +we have to also define those tags. + +66 +00:02:36,000 --> 00:02:39,000 +So for definition, I don't want to type it, everything, + +67 +00:02:39,000 --> 00:02:41,000 +because a lengthy file, so I do have a file with me. + +68 +00:02:41,000 --> 00:02:42,000 +You will find that in resources. + +69 +00:02:42,000 --> 00:02:45,000 +So this is the definition for those beans + +70 +00:02:45,000 --> 00:02:47,000 +or to those tags which you are going to use. + +71 +00:02:47,000 --> 00:02:51,000 +So let's end this. So this is what we wanted, right? + +72 +00:02:51,000 --> 00:02:53,000 +So this is the bean definition, + +73 +00:02:53,000 --> 00:02:57,000 +and now we can talk to the DispatcherServlet. + +74 +00:02:57,000 --> 00:02:59,000 +So the first thing you will mention is component scan. + +75 +00:02:59,000 --> 00:03:03,000 +Now you want to mention which package you have + +76 +00:03:03,000 --> 00:03:04,000 +to scan for the components. + +77 +00:03:04,000 --> 00:03:07,000 +So you will say ctx. So what is ctx here? Just context. + +78 +00:03:07,000 --> 00:03:11,000 +You can see we are defining the context definition as well. + +79 +00:03:11,000 --> 00:03:12,000 +So that's it, refer with ctx, + +80 +00:03:12,000 --> 00:03:14,000 +and that's what we are mentioning here. + +81 +00:03:14,000 --> 00:03:16,000 +So ctx:component-scan, and then the base package, you have + +82 +00:03:16,000 --> 00:03:20,000 +to mention the package name, which is com.telusko here. + +83 +00:03:20,000 --> 00:03:21,000 +You can be specific here, + +84 +00:03:21,000 --> 00:03:23,000 +you can mention the exact package name. + +85 +00:03:23,000 --> 00:03:27,000 +But com.telusko works. And that's the first thing. + +86 +00:03:27,000 --> 00:03:30,000 +Next you have to mention that you are using annotations. + +87 +00:03:30,000 --> 00:03:33,000 +And for that, you'll be using annotation-config. + +88 +00:03:33,000 --> 00:03:36,000 +In fact, you can also do a self-closing tags here + +89 +00:03:36,000 --> 00:03:37,000 +instead of typing everything. + +90 +00:03:37,000 --> 00:03:39,000 +That's it, these two things you have to mention + +91 +00:03:39,000 --> 00:03:42,000 +that you have to scan the package in this package. + +92 +00:03:42,000 --> 00:03:45,000 +And then you have to use, + +93 +00:03:45,000 --> 00:03:47,000 +I mean we are using annotation configuration, that's it. + +94 +00:03:47,000 --> 00:03:49,000 +Now this is how you talk to DispatcherServlet, + +95 +00:03:49,000 --> 00:03:52,000 +not by writing those two lines, but will this work? + +96 +00:03:52,000 --> 00:03:54,000 +Let's try it out. Of course we learn from the errors. + +97 +00:03:54,000 --> 00:03:56,000 +So I will just rerun this application, + +98 +00:03:56,000 --> 00:03:59,000 +and go back + +99 +00:03:59,000 --> 00:04:02,000 +to my code, run. + +100 +00:04:02,000 --> 00:04:04,000 +Okay, now this time we got a different error, + +101 +00:04:04,000 --> 00:04:06,000 +but at least every time we do something, + +102 +00:04:06,000 --> 00:04:08,000 +errors are changing, so that's a good thing, right? + +103 +00:04:08,000 --> 00:04:11,000 +But what is the problem now? + +104 +00:04:11,000 --> 00:04:13,000 +Is it the DispatcherServlet is not able to find? + +105 +00:04:13,000 --> 00:04:15,000 +Yes, DispatcherServlet was able + +106 +00:04:15,000 --> 00:04:17,000 +to find this particular file. + +107 +00:04:17,000 --> 00:04:20,000 +Now it knows that which package you have to scan, + +108 +00:04:20,000 --> 00:04:21,000 +which annotation you have to, I mean + +109 +00:04:21,000 --> 00:04:24,000 +we have been using annotation configuration, what's wrong? + +110 +00:04:24,000 --> 00:04:25,000 +And if you observe here, + +111 +00:04:25,000 --> 00:04:29,000 +in the console it says home method called, + +112 +00:04:29,000 --> 00:04:33,000 +which means it was able to call the controller. + +113 +00:04:33,000 --> 00:04:37,000 +So we have reached till here, but it's not going after that. + +114 +00:04:37,000 --> 00:04:39,000 +You know what's going wrong? + +115 +00:04:39,000 --> 00:04:44,000 +Let's go back to our page and it says 404. That's right. + +116 +00:04:44,000 --> 00:04:45,000 +But look at the message. + +117 +00:04:45,000 --> 00:04:48,000 +It says, no endpoint GET, for the GET request, + +118 +00:04:48,000 --> 00:04:51,000 +and the URL you're searching for is index. + +119 +00:04:51,000 --> 00:04:55,000 +Now from where we got index? Let's go back. + +120 +00:04:55,000 --> 00:04:58,000 +We are returning a index. + +121 +00:04:58,000 --> 00:05:01,000 +DispatcherServlet says, "You are telling me to call index. + +122 +00:05:01,000 --> 00:05:02,000 +But what is index?" + +123 +00:05:02,000 --> 00:05:04,000 +If you remember, when we were working + +124 +00:05:04,000 --> 00:05:08,000 +with this Spring Boot application, we did the same thing. + +125 +00:05:08,000 --> 00:05:10,000 +We are returning index there, + +126 +00:05:10,000 --> 00:05:13,000 +but in the property files we have mentioned + +127 +00:05:13,000 --> 00:05:16,000 +that you have to find the index in this particular folder, + +128 +00:05:17,000 --> 00:05:20,000 +and the extension for that index is .jsp. + +129 +00:05:20,000 --> 00:05:23,000 +Nowhere we are doing that in this particular project. + +130 +00:05:23,000 --> 00:05:26,000 +So that means you have to also configure the resolver. + +131 +00:05:26,000 --> 00:05:28,000 +Remember when I mentioned that, when you return this, + +132 +00:05:28,000 --> 00:05:31,000 +behind the scene, it uses something called a resolver. + +133 +00:05:31,000 --> 00:05:33,000 +So there's something called view resolver, or in full name, + +134 +00:05:33,000 --> 00:05:36,000 +it is called InternalResourceViewResolver. + +135 +00:05:36,000 --> 00:05:39,000 +So we have to configure that. Okay, how do we do that? + +136 +00:05:39,000 --> 00:05:42,000 +How do we configure the InternalResourceViewResolver? + +137 +00:05:42,000 --> 00:05:44,000 +Let's see that in the next video. + diff --git a/13 - Exploring Web MVC without Spring Boot/005 Source-Code.url b/13 - Exploring Web MVC without Spring Boot/005 Source-Code.url new file mode 100644 index 0000000000000000000000000000000000000000..73f306d639824e359e526c5173ba2c7f887e565a --- /dev/null +++ b/13 - Exploring Web MVC without Spring Boot/005 Source-Code.url @@ -0,0 +1,2 @@ +[InternetShortcut] +URL=https://github.com/navinreddy20/spring6-course/tree/f1161e151ea06b68810b3cae03005d4955a96a8b/7%20Exploring%20Web%20MVC%20without%20Spring%20Boot/6.5%20Configuring%20the%20DispatcherServlet \ No newline at end of file diff --git a/13 - Exploring Web MVC without Spring Boot/006 Internal Resource View Resolver_en.srt b/13 - Exploring Web MVC without Spring Boot/006 Internal Resource View Resolver_en.srt new file mode 100644 index 0000000000000000000000000000000000000000..a136378917c7ea96ed9ffd3cdff58afd913207ea --- /dev/null +++ b/13 - Exploring Web MVC without Spring Boot/006 Internal Resource View Resolver_en.srt @@ -0,0 +1,408 @@ +1 +00:00:00,000 --> 00:00:03,000 +(bright music) + +2 +00:00:03,000 --> 00:00:05,000 +-: Now it's time to configure + +3 +00:00:05,000 --> 00:00:08,000 +the Internal Resource View Resolver. + +4 +00:00:08,000 --> 00:00:09,000 +It's because when you return index here, + +5 +00:00:09,000 --> 00:00:12,000 +despite server has no idea where this index is + +6 +00:00:12,000 --> 00:00:14,000 +and what is extension for this, okay. + +7 +00:00:14,000 --> 00:00:17,000 +And the way you do that is again, go back to the the server + +8 +00:00:18,000 --> 00:00:20,000 +teluskoserver.xml because this is where you + +9 +00:00:20,000 --> 00:00:22,000 +talk to your dispatch satellite. + +10 +00:00:22,000 --> 00:00:26,000 +Now to configure that, we have to use a bean tag here. + +11 +00:00:26,000 --> 00:00:29,000 +So I have to say bean. Now, which bean I'm talking about? + +12 +00:00:29,000 --> 00:00:31,000 +So let's enter this. Now, which bean I'm talking about? + +13 +00:00:31,000 --> 00:00:34,000 +So there's something called internal resource resolver + +14 +00:00:34,000 --> 00:00:38,000 +and we have to mention the qualified path, + +15 +00:00:38,000 --> 00:00:40,000 +which is the full path for the class. + +16 +00:00:40,000 --> 00:00:41,000 +And the way you get that + +17 +00:00:41,000 --> 00:00:43,000 +is if you go back to Maven Dependencies + +18 +00:00:43,000 --> 00:00:44,000 +The same package. + +19 +00:00:44,000 --> 00:00:45,000 +Again, we have to go with this + +20 +00:00:45,000 --> 00:00:50,000 +org.springframework.web.servlet, but a different sub folder. + +21 +00:00:50,000 --> 00:00:53,000 +If you go down, you can see something called view. + +22 +00:00:53,000 --> 00:00:55,000 +And if you expand this, you will get the name, + +23 +00:00:55,000 --> 00:00:58,000 +which is Internal Resource View Resolver, which is this. + +24 +00:00:58,000 --> 00:01:02,000 +I will copy this name, qualified copy, qualified name. + +25 +00:01:02,000 --> 00:01:05,000 +And in this you have to mention the class equal to + +26 +00:01:05,000 --> 00:01:08,000 +and in the double codes, just mention + +27 +00:01:08,000 --> 00:01:10,000 +that without the class extension. + +28 +00:01:10,000 --> 00:01:11,000 +That's it. + +29 +00:01:11,000 --> 00:01:12,000 +This is how you mention that. + +30 +00:01:12,000 --> 00:01:15,000 +I'm going to configure the internal view resolver, + +31 +00:01:15,000 --> 00:01:17,000 +but you have to set two properties. + +32 +00:01:17,000 --> 00:01:20,000 +The first is prefix and the second is suffix. + +33 +00:01:20,000 --> 00:01:23,000 +So properties, and again we have used the same thing. + +34 +00:01:23,000 --> 00:01:27,000 +If you remember prefix suffix, let's set that. + +35 +00:01:27,000 --> 00:01:29,000 +So property is prefix. + +36 +00:01:29,000 --> 00:01:31,000 +The value is slash views slash + +37 +00:01:31,000 --> 00:01:33,000 +because that's a folder I think. + +38 +00:01:33,000 --> 00:01:36,000 +Let's see, yeah, the folder name is views. + +39 +00:01:36,000 --> 00:01:40,000 +And next we have to mention the property, + +40 +00:01:40,000 --> 00:01:43,000 +which is the suffix, which is in this case is .gsp. + +41 +00:01:43,000 --> 00:01:44,000 +That's it. + +42 +00:01:44,000 --> 00:01:47,000 +That's how basically you configure things + +43 +00:01:47,000 --> 00:01:49,000 +and now you know the importance of Spring Boot, right? + +44 +00:01:49,000 --> 00:01:52,000 +How easy it is to do everything in Spring Boot. + +45 +00:01:52,000 --> 00:01:56,000 +So now after making the changes, let's reload + +46 +00:01:56,000 --> 00:01:58,000 +or relaunch the application. + +47 +00:01:58,000 --> 00:02:01,000 +Let's go back and refresh. + +48 +00:02:01,000 --> 00:02:03,000 +Oh, and this time we got a different error. + +49 +00:02:03,000 --> 00:02:04,000 +Good thing, right? + +50 +00:02:04,000 --> 00:02:05,000 +Every time we do something you get + +51 +00:02:05,000 --> 00:02:07,000 +different error, but it looks like I made a mistake. + +52 +00:02:07,000 --> 00:02:10,000 +Line number 20. Let's see, line number 20. + +53 +00:02:10,000 --> 00:02:14,000 +It says perfect property things are looking good. + +54 +00:02:14,000 --> 00:02:17,000 +What is wrong there? Oh, this is not how you do it. + +55 +00:02:17,000 --> 00:02:19,000 +I still went into a different way. + +56 +00:02:19,000 --> 00:02:20,000 +So I have to set the value. + +57 +00:02:20,000 --> 00:02:22,000 +Remember in Spring Boot we have talked about the values. + +58 +00:02:22,000 --> 00:02:25,000 +I will say slash views slash, + +59 +00:02:25,000 --> 00:02:27,000 +and this should be also value.jsp. + +60 +00:02:27,000 --> 00:02:30,000 +Sometime you just go with the intuitions, right? + +61 +00:02:30,000 --> 00:02:32,000 +And then it doesn't work. Anyway. + +62 +00:02:32,000 --> 00:02:35,000 +So you have to set the values like this, not in the bracket. + +63 +00:02:35,000 --> 00:02:39,000 +Let's relaunch and go back here, relaunch the application + +64 +00:02:39,000 --> 00:02:41,000 +and voila, we got our page. + +65 +00:02:41,000 --> 00:02:43,000 +So this is working, but let's see + +66 +00:02:43,000 --> 00:02:45,000 +if the actual output also works. + +67 +00:02:45,000 --> 00:02:48,000 +So I will say 121. + +68 +00:02:48,000 --> 00:02:51,000 +And here I will say, Navin, enter, submit. And you got it. + +69 +00:02:51,000 --> 00:02:53,000 +You got the output. Not exactly, + +70 +00:02:53,000 --> 00:02:55,000 +I mean we have not seen this problem before, + +71 +00:02:55,000 --> 00:02:57,000 +but you can see we are not getting the value. + +72 +00:02:57,000 --> 00:02:59,000 +We wanted the value, which is data + +73 +00:02:59,000 --> 00:03:01,000 +and we wanted it to print. + +74 +00:03:01,000 --> 00:03:03,000 +Welcome to the Java world. What is not working? + +75 +00:03:03,000 --> 00:03:06,000 +Let's go back to our code. + +76 +00:03:06,000 --> 00:03:08,000 +And if you go to the home controller, + +77 +00:03:08,000 --> 00:03:12,000 +if you can see we do have this alien object here + +78 +00:03:13,000 --> 00:03:15,000 +and we are returning the result page. + +79 +00:03:15,000 --> 00:03:17,000 +And we do have the course model attribute, + +80 +00:03:17,000 --> 00:03:18,000 +which returns Java. + +81 +00:03:18,000 --> 00:03:20,000 +So it should work, right? See, sometime + +82 +00:03:20,000 --> 00:03:23,000 +what happens is in your JSP because of some, + +83 +00:03:25,000 --> 00:03:27,000 +because of some support, JSTL might not work. + +84 +00:03:27,000 --> 00:03:29,000 +So if you go back to result page, you have + +85 +00:03:29,000 --> 00:03:33,000 +to add one more attribute here, which is isELIgnored. + +86 +00:03:33,000 --> 00:03:35,000 +So you have to make sure this is always false + +87 +00:03:35,000 --> 00:03:37,000 +and you have to put that in double quotes. + +88 +00:03:37,000 --> 00:03:39,000 +So sometime the expression language, + +89 +00:03:39,000 --> 00:03:41,000 +so this is called the expression language + +90 +00:03:41,000 --> 00:03:43,000 +and sometime your framework ignores it. + +91 +00:03:43,000 --> 00:03:46,000 +So you have to make sure that you say, Hey, don't ignore it, + +92 +00:03:46,000 --> 00:03:48,000 +convert this value and let's see if this works. + +93 +00:03:48,000 --> 00:03:53,000 +Let's go back to the output page refresh. And it worked. + +94 +00:03:53,000 --> 00:03:55,000 +So that's how basically it works. + +95 +00:03:55,000 --> 00:03:58,000 +And we were able to convert our project, + +96 +00:03:58,000 --> 00:04:01,000 +the entire project from Spring Boot + +97 +00:04:01,000 --> 00:04:03,000 +to normal spring MVC without using Spring Boot of course. + +98 +00:04:03,000 --> 00:04:08,000 +And we have done a lot of configuration. + +99 +00:04:08,000 --> 00:04:10,000 +So let's do a quick recap in the next video. + +100 +00:04:10,000 --> 00:04:11,000 +Whatever we have done, step by step so + +101 +00:04:11,000 --> 00:04:13,000 +that you will remember what to do when you want + +102 +00:04:13,000 --> 00:04:15,000 +to build a Spring MBC application. + diff --git a/13 - Exploring Web MVC without Spring Boot/006 Source-Code.url b/13 - Exploring Web MVC without Spring Boot/006 Source-Code.url new file mode 100644 index 0000000000000000000000000000000000000000..9487b58b603c6415f4930d4598ec4a91d31adbd8 --- /dev/null +++ b/13 - Exploring Web MVC without Spring Boot/006 Source-Code.url @@ -0,0 +1,2 @@ +[InternetShortcut] +URL=https://github.com/navinreddy20/spring6-course/tree/f1161e151ea06b68810b3cae03005d4955a96a8b/7%20Exploring%20Web%20MVC%20without%20Spring%20Boot/6.6%20Internal%20Resource%20View%20Resolver \ No newline at end of file diff --git a/13 - Exploring Web MVC without Spring Boot/007 Summary_en.srt b/13 - Exploring Web MVC without Spring Boot/007 Summary_en.srt new file mode 100644 index 0000000000000000000000000000000000000000..acf5c47a014aeff5ba5dd09d40b45509e8404281 --- /dev/null +++ b/13 - Exploring Web MVC without Spring Boot/007 Summary_en.srt @@ -0,0 +1,308 @@ +1 +00:00:00,000 --> 00:00:03,000 +(gentle music) + +2 +00:00:03,000 --> 00:00:05,000 +-: So let's do a quick recap of this app. + +3 +00:00:05,000 --> 00:00:07,000 +So what we have done is, + +4 +00:00:07,000 --> 00:00:08,000 +initially when you build this project, + +5 +00:00:08,000 --> 00:00:10,000 +you will get a Maven project. + +6 +00:00:10,000 --> 00:00:12,000 +You have to make sure that you add + +7 +00:00:12,000 --> 00:00:14,000 +this dependency for SpringMVC. + +8 +00:00:14,000 --> 00:00:17,000 +Now this is SpringMVC, not Spring Boot, + +9 +00:00:17,000 --> 00:00:19,000 +and the version I'm going for is 6.1. + +10 +00:00:19,000 --> 00:00:20,000 +Now. depending upon when you're watching this, + +11 +00:00:20,000 --> 00:00:22,000 +you can try out your own version. + +12 +00:00:22,000 --> 00:00:26,000 +And once we do this, we can create our controller. + +13 +00:00:26,000 --> 00:00:28,000 +So if you can see, I am creating a home controller here + +14 +00:00:28,000 --> 00:00:30,000 +in which I have different methods. + +15 +00:00:30,000 --> 00:00:32,000 +Of course, we are using annotations here for the mapping. + +16 +00:00:32,000 --> 00:00:34,000 +But then to make this work, + +17 +00:00:34,000 --> 00:00:37,000 +we have to make sure that you ask your Tomcat, + +18 +00:00:37,000 --> 00:00:40,000 +because Tomcat by default have no idea + +19 +00:00:40,000 --> 00:00:43,000 +that you are using a Spring project or SpringMVC project. + +20 +00:00:43,000 --> 00:00:45,000 +So you have to tell, "Hey, you know, + +21 +00:00:45,000 --> 00:00:47,000 +I want to use SpringMVC here." + +22 +00:00:47,000 --> 00:00:49,000 +And the first controller + +23 +00:00:49,000 --> 00:00:51,000 +or the first servlet you have to interact with + +24 +00:00:51,000 --> 00:00:53,000 +is a DispatcherServlet + +25 +00:00:53,000 --> 00:00:55,000 +which is given by the Spring Framework. + +26 +00:00:55,000 --> 00:00:59,000 +For all the requests, you have to call a DispatcherServlet. + +27 +00:00:59,000 --> 00:01:02,000 +That's what we are doing in the web.xml file. + +28 +00:01:02,000 --> 00:01:04,000 +Now, whom we are talking to using web.xml? + +29 +00:01:04,000 --> 00:01:05,000 +We are talking to Tomcat, okay? + +30 +00:01:05,000 --> 00:01:08,000 +So every file here is responsible for talking to something. + +31 +00:01:08,000 --> 00:01:11,000 +So web.xml is a way to talk to Tomcat. + +32 +00:01:11,000 --> 00:01:14,000 +And then when you call DispatcherServlet, + +33 +00:01:14,000 --> 00:01:15,000 +now DispatcherServlet has no idea + +34 +00:01:15,000 --> 00:01:16,000 +that you're using a controller. + +35 +00:01:16,000 --> 00:01:18,000 +Now, we have to talk to DispatcherServlet. + +36 +00:01:18,000 --> 00:01:21,000 +And the way you do that is using the DispatcherServlet name, + +37 +00:01:21,000 --> 00:01:24,000 +which is TELUSKO in this case, -servlet.xml. + +38 +00:01:24,000 --> 00:01:27,000 +This is our file which will be there in the WEB-INF folder. + +39 +00:01:27,000 --> 00:01:31,000 +In this, you have to mention that I am using annotations + +40 +00:01:31,000 --> 00:01:32,000 +using annotation-config. + +41 +00:01:32,000 --> 00:01:34,000 +And the package you will find all these classes + +42 +00:01:34,000 --> 00:01:36,000 +is com.telusko. + +43 +00:01:36,000 --> 00:01:38,000 +And then this basically knows that, hey, + +44 +00:01:38,000 --> 00:01:40,000 +I have to look at this controller, + +45 +00:01:40,000 --> 00:01:42,000 +I have to map it, + +46 +00:01:42,000 --> 00:01:44,000 +and then I have to call a particular page. + +47 +00:01:44,000 --> 00:01:46,000 +So like I'm calling the home method here, + +48 +00:01:46,000 --> 00:01:48,000 +which is calling "index". + +49 +00:01:48,000 --> 00:01:50,000 +So DispatcherServlet has no idea what "index" is. + +50 +00:01:50,000 --> 00:01:52,000 +So I have to mention the location of Index + +51 +00:01:52,000 --> 00:01:53,000 +and the extension. + +52 +00:01:53,000 --> 00:01:55,000 +The way you can do that + +53 +00:01:55,000 --> 00:01:57,000 +is with the help of Internal View Resolver, + +54 +00:01:57,000 --> 00:01:59,000 +which we have configured here. + +55 +00:01:59,000 --> 00:02:01,000 +So Internal Resource View Resolver. + +56 +00:02:01,000 --> 00:02:02,000 +In which you have to mention the prefix, + +57 +00:02:02,000 --> 00:02:04,000 +that means the location of the file, + +58 +00:02:04,000 --> 00:02:06,000 +and the extension for the file, which is suffix, + +59 +00:02:06,000 --> 00:02:08,000 +and that is your .jsp. + +60 +00:02:08,000 --> 00:02:11,000 +And that's how the entire project is working. + +61 +00:02:11,000 --> 00:02:13,000 +So again, you have to do this configuration, + +62 +00:02:13,000 --> 00:02:15,000 +but remember, for a big project, + +63 +00:02:15,000 --> 00:02:17,000 +you will do this configuration only once. + +64 +00:02:17,000 --> 00:02:20,000 +As you add more features, you have to do more configuration. + +65 +00:02:20,000 --> 00:02:21,000 +But again, remember, + +66 +00:02:21,000 --> 00:02:22,000 +you will do this configuration only once + +67 +00:02:22,000 --> 00:02:24,000 +for the entire project. + +68 +00:02:24,000 --> 00:02:26,000 +So is it worth building project in SpringMVC? + +69 +00:02:26,000 --> 00:02:28,000 +Yes, you get more controls. + +70 +00:02:28,000 --> 00:02:30,000 +And is it worth building project in Spring Boot? + +71 +00:02:30,000 --> 00:02:31,000 +Yes, if it will save your time. + +72 +00:02:31,000 --> 00:02:34,000 +So it depends upon what kind of project you're building. + +73 +00:02:34,000 --> 00:02:37,000 +I have seen projects also built in normal SpringMVC, + +74 +00:02:37,000 --> 00:02:38,000 +without Spring Boot. + +75 +00:02:38,000 --> 00:02:40,000 +But most of the projects are using Spring Boot. + +76 +00:02:40,000 --> 00:02:44,000 +So after this, we'll add some more features into Spring, + +77 +00:02:44,000 --> 00:02:46,000 +but with the help of Spring Boot. + diff --git a/13 - Exploring Web MVC without Spring Boot/external-links.txt b/13 - Exploring Web MVC without Spring Boot/external-links.txt new file mode 100644 index 0000000000000000000000000000000000000000..3e8ea7a70ad11de0dfe1db2d5bf4abcc467f293f --- /dev/null +++ b/13 - Exploring Web MVC without Spring Boot/external-links.txt @@ -0,0 +1,15 @@ + +002 Source-Code +https://github.com/navinreddy20/spring6-course/tree/f1161e151ea06b68810b3cae03005d4955a96a8b/7%20Exploring%20Web%20MVC%20without%20Spring%20Boot/6.2%20Creating%20a%20Spring%20MVC%20Project_1 + +003 Source-Code +https://github.com/navinreddy20/spring6-course/tree/f1161e151ea06b68810b3cae03005d4955a96a8b/7%20Exploring%20Web%20MVC%20without%20Spring%20Boot/6.3%20Running%20Tomcat%20in%20Eclipse + +004 Source-Code +https://github.com/navinreddy20/spring6-course/tree/f1161e151ea06b68810b3cae03005d4955a96a8b/7%20Exploring%20Web%20MVC%20without%20Spring%20Boot/6.4%20Dispatcher%20Servlet + +005 Source-Code +https://github.com/navinreddy20/spring6-course/tree/f1161e151ea06b68810b3cae03005d4955a96a8b/7%20Exploring%20Web%20MVC%20without%20Spring%20Boot/6.5%20Configuring%20the%20DispatcherServlet + +006 Source-Code +https://github.com/navinreddy20/spring6-course/tree/f1161e151ea06b68810b3cae03005d4955a96a8b/7%20Exploring%20Web%20MVC%20without%20Spring%20Boot/6.6%20Internal%20Resource%20View%20Resolver diff --git a/14 - Building a Project/001 Building Job App_en.srt b/14 - Building a Project/001 Building Job App_en.srt new file mode 100644 index 0000000000000000000000000000000000000000..ff40137c26f4c5613f7c78e2086b048f3b3b640b --- /dev/null +++ b/14 - Building a Project/001 Building Job App_en.srt @@ -0,0 +1,296 @@ +1 +00:00:00,000 --> 00:00:03,000 +(bright music) + +2 +00:00:03,000 --> 00:00:04,000 +-: With whatever we have learned 'til now, + +3 +00:00:04,000 --> 00:00:07,000 +basically we have talked about Spring, Spring Boot, + +4 +00:00:07,000 --> 00:00:09,000 +and we also know how do you build a web application + +5 +00:00:09,000 --> 00:00:10,000 +with the help of Spring framework. + +6 +00:00:10,000 --> 00:00:12,000 +Now, when you talk about web application + +7 +00:00:12,000 --> 00:00:15,000 +and if you try to build a view + +8 +00:00:15,000 --> 00:00:16,000 +inside your Spring project as well, + +9 +00:00:16,000 --> 00:00:18,000 +we can do that with the help of JSP. + +10 +00:00:18,000 --> 00:00:20,000 +And that's what we have done 'til now, right? + +11 +00:00:20,000 --> 00:00:22,000 +Now on that, let's build an application. + +12 +00:00:22,000 --> 00:00:25,000 +Now what we are building, we are building a job application, + +13 +00:00:25,000 --> 00:00:27,000 +or you can say a job portal, + +14 +00:00:27,000 --> 00:00:29,000 +where people can, or companies can post + +15 +00:00:29,000 --> 00:00:31,000 +about a particular job. + +16 +00:00:31,000 --> 00:00:35,000 +And then as a job seeker, you can search for a job. + +17 +00:00:35,000 --> 00:00:37,000 +So this is what we are building here. + +18 +00:00:37,000 --> 00:00:38,000 +So let's say if you are searching for a job + +19 +00:00:38,000 --> 00:00:40,000 +and then you want to see + +20 +00:00:40,000 --> 00:00:41,000 +what are the different jobs available, + +21 +00:00:41,000 --> 00:00:43,000 +or the the requirements, + +22 +00:00:43,000 --> 00:00:45,000 +you can simply click on View All Jobs here. + +23 +00:00:45,000 --> 00:00:48,000 +And this will list the number of jobs available. + +24 +00:00:48,000 --> 00:00:51,000 +You can see they're looking for Java developers + +25 +00:00:51,000 --> 00:00:53,000 +with the experience in core Java, advanced Java, + +26 +00:00:53,000 --> 00:00:56,000 +experience two years, and then the tech stack. + +27 +00:00:56,000 --> 00:00:58,000 +Then we have front developer, three years. + +28 +00:00:58,000 --> 00:01:02,000 +Now all these are just data which we randomly inserted, + +29 +00:01:02,000 --> 00:01:03,000 +but it doesn't matter, right? + +30 +00:01:03,000 --> 00:01:04,000 +We got this data here, + +31 +00:01:04,000 --> 00:01:07,000 +and now if you want to apply for a job, + +32 +00:01:07,000 --> 00:01:08,000 +you can see a particular thing. + +33 +00:01:08,000 --> 00:01:09,000 +And of course there should be a button here + +34 +00:01:09,000 --> 00:01:10,000 +for applying a job. + +35 +00:01:10,000 --> 00:01:12,000 +And also there should be a company name. + +36 +00:01:12,000 --> 00:01:13,000 +But just to keep it simple, + +37 +00:01:13,000 --> 00:01:15,000 +we went for these different profiles here. + +38 +00:01:15,000 --> 00:01:16,000 +That's one. + +39 +00:01:16,000 --> 00:01:20,000 +Next, what if you are an employer, + +40 +00:01:20,000 --> 00:01:21,000 +and you want to post about a job? + +41 +00:01:21,000 --> 00:01:22,000 +So you can click on this Add Job + +42 +00:01:22,000 --> 00:01:24,000 +and you can post a requirement. + +43 +00:01:24,000 --> 00:01:26,000 +Of course this should be auto-generated, + +44 +00:01:26,000 --> 00:01:27,000 +but at this point, + +45 +00:01:27,000 --> 00:01:29,000 +let's say we have some hardware values there, + +46 +00:01:29,000 --> 00:01:30,000 +and then we have a post profile. + +47 +00:01:30,000 --> 00:01:35,000 +Let's say we are looking for a Spring dev + +48 +00:01:35,000 --> 00:01:36,000 +and some requirement, + +49 +00:01:36,000 --> 00:01:38,000 +let's say experience of one year in Spring. + +50 +00:01:38,000 --> 00:01:42,000 +And I want the person to know Java, + +51 +00:01:42,000 --> 00:01:44,000 +and there should be Spring as well here. + +52 +00:01:44,000 --> 00:01:45,000 +And I'm not able to find. + +53 +00:01:45,000 --> 00:01:47,000 +Let's say I want someone who knows Java and TypeScript. + +54 +00:01:47,000 --> 00:01:49,000 +I will click on Submit and we got an error. + +55 +00:01:49,000 --> 00:01:52,000 +Not expected, but it should bring something, right? + +56 +00:01:52,000 --> 00:01:54,000 +So there's something wrong with the code. + +57 +00:01:54,000 --> 00:01:55,000 +Again, we'll figure it out, and we'll make it work, + +58 +00:01:55,000 --> 00:01:57,000 +but it should add the job. + +59 +00:01:57,000 --> 00:01:59,000 +And when you go back to View All Jobs, + +60 +00:01:59,000 --> 00:02:00,000 +of course it should be there, right? + +61 +00:02:00,000 --> 00:02:02,000 +This is what we want to build now. + +62 +00:02:02,000 --> 00:02:04,000 +It's not complete, and that's why we got the error. + +63 +00:02:04,000 --> 00:02:05,000 +But let's build this. + +64 +00:02:05,000 --> 00:02:07,000 +Now, how we are going to start this? + +65 +00:02:07,000 --> 00:02:09,000 +Of course, we don't want to focus on the views here + +66 +00:02:09,000 --> 00:02:11,000 +because there are a lot of CSS involved here. + +67 +00:02:11,000 --> 00:02:13,000 +So I have the view theories. + +68 +00:02:13,000 --> 00:02:15,000 +We want to build the backend, okay? + +69 +00:02:15,000 --> 00:02:17,000 +So in the next video I will show you + +70 +00:02:17,000 --> 00:02:19,000 +how we have built that view. + +71 +00:02:19,000 --> 00:02:20,000 +In fact, we'll create the project first, + +72 +00:02:20,000 --> 00:02:23,000 +and then we'll add some views which I've already created, + +73 +00:02:23,000 --> 00:02:25,000 +and we'll see how those views looks like. + +74 +00:02:25,000 --> 00:02:28,000 +And then we'll start coding the Java part of it. + diff --git a/14 - Building a Project/002 Creating a Project_en.srt b/14 - Building a Project/002 Creating a Project_en.srt new file mode 100644 index 0000000000000000000000000000000000000000..3447e42a9e7dc038cf444ac904aafd09270bf7d3 --- /dev/null +++ b/14 - Building a Project/002 Creating a Project_en.srt @@ -0,0 +1,508 @@ +1 +00:00:00,000 --> 00:00:03,000 +(gentle music) + +2 +00:00:03,000 --> 00:00:04,000 +-: So let's create a project now. + +3 +00:00:04,000 --> 00:00:06,000 +Now, how do we create a project in Spring? + +4 +00:00:06,000 --> 00:00:08,000 +Of course, we are building a Spring Boot project. + +5 +00:00:08,000 --> 00:00:09,000 +And if you're using the community version + +6 +00:00:09,000 --> 00:00:10,000 +of IntelliJ IDEA, + +7 +00:00:10,000 --> 00:00:13,000 +we have to use the start.spring.io, + +8 +00:00:13,000 --> 00:00:15,000 +which is the Spring Initializr. + +9 +00:00:15,000 --> 00:00:17,000 +So what I will do is I will just create, + +10 +00:00:17,000 --> 00:00:18,000 +I will just go to a new tab + +11 +00:00:18,000 --> 00:00:21,000 +and I will go to the start.spring.io + +12 +00:00:21,000 --> 00:00:22,000 +and let's create a project. + +13 +00:00:22,000 --> 00:00:24,000 +So I want to create a Maven project, + +14 +00:00:24,000 --> 00:00:27,000 +and the language is Java, the snapshot version is this. + +15 +00:00:27,000 --> 00:00:29,000 +So while we're making this video, + +16 +00:00:29,000 --> 00:00:31,000 +we got a new sub version, which is 3.2.1. + +17 +00:00:32,000 --> 00:00:33,000 +Let's use that. + +18 +00:00:33,000 --> 00:00:36,000 +And then this should become score. + +19 +00:00:36,000 --> 00:00:39,000 +The artifact is I'm making a job app. + +20 +00:00:39,000 --> 00:00:42,000 +And okay, let's skip it as it is. + +21 +00:00:42,000 --> 00:00:44,000 +I'm using the version Java21. + +22 +00:00:44,000 --> 00:00:46,000 +Okay, now what are the dependencies we have to add? + +23 +00:00:46,000 --> 00:00:48,000 +So the first dependency I want to add is spring web, + +24 +00:00:48,000 --> 00:00:50,000 +because that's what we're building, web application. + +25 +00:00:50,000 --> 00:00:53,000 +And next I want to also use Lombok. + +26 +00:00:53,000 --> 00:00:56,000 +Now again, once we start coding, I will talk about Lombok. + +27 +00:00:56,000 --> 00:00:57,000 +What is Lombok? + +28 +00:00:57,000 --> 00:00:59,000 +So Lombok basically helps reduce the number of lines + +29 +00:00:59,000 --> 00:01:00,000 +you write in your code. + +30 +00:01:00,000 --> 00:01:01,000 +Okay, how? + +31 +00:01:01,000 --> 00:01:02,000 +We'll see that in some time, + +32 +00:01:02,000 --> 00:01:05,000 +but we have added two libraries here, or two dependencies. + +33 +00:01:05,000 --> 00:01:08,000 +One is Spring Web and second is Lombok. + +34 +00:01:08,000 --> 00:01:11,000 +After doing these changes, click on generate + +35 +00:01:11,000 --> 00:01:15,000 +and okay, allow, it'll download the project + +36 +00:01:15,000 --> 00:01:16,000 +and you can see I got it. + +37 +00:01:16,000 --> 00:01:17,000 +I have to unzip it + +38 +00:01:17,000 --> 00:01:21,000 +and open that in IntelliJ IDEA committee version. + +39 +00:01:21,000 --> 00:01:24,000 +So I will open this, let me open my IntelliJ IDEA + +40 +00:01:24,000 --> 00:01:25,000 +and open this project. + +41 +00:01:25,000 --> 00:01:27,000 +And here we go. + +42 +00:01:27,000 --> 00:01:28,000 +So I'm opening this project, which is, + +43 +00:01:28,000 --> 00:01:30,000 +you can see we have a job app here. + +44 +00:01:30,000 --> 00:01:33,000 +And now if you look at your palm.xml, + +45 +00:01:33,000 --> 00:01:35,000 +we got two dependencies here. + +46 +00:01:35,000 --> 00:01:38,000 +One is Spring Startup Web and Lombok. + +47 +00:01:38,000 --> 00:01:40,000 +Also, we have a test library if you want to use it. + +48 +00:01:40,000 --> 00:01:42,000 +But we got two, which is which you're going to use now. + +49 +00:01:42,000 --> 00:01:45,000 +Okay, now, apart from this, since we are going to use JSP, + +50 +00:01:45,000 --> 00:01:47,000 +and then in JSP, we are going to use JSTL. + +51 +00:01:47,000 --> 00:01:50,000 +I will show you what JSP I'm talking about. + +52 +00:01:50,000 --> 00:01:53,000 +And to make it work, we have to add two more dependencies. + +53 +00:01:53,000 --> 00:01:54,000 +In fact, three dependencies. + +54 +00:01:54,000 --> 00:01:57,000 +Remember when we use JSP, we have to also use Jasper, + +55 +00:01:57,000 --> 00:01:58,000 +remember? + +56 +00:01:58,000 --> 00:02:00,000 +So instead of going to Maven repository, + +57 +00:02:00,000 --> 00:02:02,000 +I do have those dependencies with me. + +58 +00:02:02,000 --> 00:02:03,000 +I'll just paste it here. + +59 +00:02:03,000 --> 00:02:05,000 +Now these are the dependency you need. + +60 +00:02:05,000 --> 00:02:08,000 +So basically we need Jasper to convert your JSP pages. + +61 +00:02:08,000 --> 00:02:10,000 +We need JST API because + +62 +00:02:10,000 --> 00:02:14,000 +after Tomcat 10, we went from Java X to Jakarta. + +63 +00:02:14,000 --> 00:02:17,000 +So we'll be using that and the JSP library. + +64 +00:02:17,000 --> 00:02:18,000 +So basically we need this two + +65 +00:02:18,000 --> 00:02:22,000 +and we need Jasper to convert JSV pages + +66 +00:02:22,000 --> 00:02:24,000 +and we need to reduce number lines. + +67 +00:02:24,000 --> 00:02:26,000 +And of course, Spring Start. + +68 +00:02:26,000 --> 00:02:29,000 +Now, once you have all this dependency, + +69 +00:02:29,000 --> 00:02:30,000 +that's our first step. + +70 +00:02:30,000 --> 00:02:33,000 +The next step is to get the views here. + +71 +00:02:33,000 --> 00:02:35,000 +Now, where you will put the views, + +72 +00:02:35,000 --> 00:02:37,000 +you will open your SRC inside main folder, + +73 +00:02:37,000 --> 00:02:40,000 +you will create a folder inside main. + +74 +00:02:40,000 --> 00:02:43,000 +And for web, we have to create a folder + +75 +00:02:43,000 --> 00:02:45,000 +called web app, that's done. + +76 +00:02:45,000 --> 00:02:48,000 +And in this web app, I want to put my views. + +77 +00:02:48,000 --> 00:02:51,000 +So I'll be using CSS files here. + +78 +00:02:51,000 --> 00:02:54,000 +So in the web app, I want views and CSS. + +79 +00:02:54,000 --> 00:02:56,000 +So you'll get all the files in the project resources, + +80 +00:02:56,000 --> 00:02:57,000 +you will get there. + +81 +00:02:57,000 --> 00:03:00,000 +So you have an option here. I mean you have views here. + +82 +00:03:00,000 --> 00:03:02,000 +And you can see we have multiple views. + +83 +00:03:02,000 --> 00:03:06,000 +In fact, I don't need JSP, Index.jsp, I can delete that. + +84 +00:03:07,000 --> 00:03:11,000 +I only need this folder, Add Job Home success. + +85 +00:03:11,000 --> 00:03:13,000 +Are we even using success? + +86 +00:03:15,000 --> 00:03:18,000 +Yeah, we got success and we got View All Jobs. + +87 +00:03:18,000 --> 00:03:20,000 +Now, which page does what? + +88 +00:03:20,000 --> 00:03:21,000 +Now if you want the homepage, + +89 +00:03:21,000 --> 00:03:24,000 +remember when we talked about the homepage, + +90 +00:03:24,000 --> 00:03:25,000 +I'm talking about this page here. + +91 +00:03:25,000 --> 00:03:27,000 +So when we talk about this homepage, + +92 +00:03:27,000 --> 00:03:30,000 +this is your homepage here, which is this. + +93 +00:03:30,000 --> 00:03:32,000 +Next, if you want to view all the jobs, + +94 +00:03:32,000 --> 00:03:34,000 +this is this view all jobs. + +95 +00:03:34,000 --> 00:03:39,000 +And if you want this add job for this, we have a page, + +96 +00:03:39,000 --> 00:03:40,000 +which is add job. + +97 +00:03:40,000 --> 00:03:42,000 +And once you add a particular job. + +98 +00:03:42,000 --> 00:03:43,000 +So last time it was not working, + +99 +00:03:43,000 --> 00:03:45,000 +so let me just try once again, + +100 +00:03:45,000 --> 00:03:47,000 +there was small bug which I resolved. + +101 +00:03:47,000 --> 00:03:49,000 +And again, we'll talk about that bug in some time. + +102 +00:03:49,000 --> 00:03:50,000 +And then pros profile. + +103 +00:03:50,000 --> 00:03:53,000 +Let's say I want to hire a React developer, + +104 +00:03:53,000 --> 00:03:56,000 +and then some description doesn't matter nowadays + +105 +00:03:56,000 --> 00:03:58,000 +because people are in their own way. + +106 +00:03:58,000 --> 00:04:01,000 +Let's say I'm looking for years experience one, + +107 +00:04:01,000 --> 00:04:03,000 +I want someone who knows TypeScript + +108 +00:04:03,000 --> 00:04:05,000 +and JavaScript and also React. + +109 +00:04:05,000 --> 00:04:06,000 +But I think it'll take some time for me + +110 +00:04:06,000 --> 00:04:10,000 +to search React here, not React native to you, anyway. + +111 +00:04:10,000 --> 00:04:13,000 +Let's say we have TypeScript in JavaScript, click on submit + +112 +00:04:13,000 --> 00:04:15,000 +and you can see this is the page we want. + +113 +00:04:15,000 --> 00:04:19,000 +So React developer, some description, experience one year. + +114 +00:04:19,000 --> 00:04:23,000 +And Tech Stack needs is JavaScript and TypeScript both. + +115 +00:04:23,000 --> 00:04:25,000 +And if you click on, so this is the success page, okay, + +116 +00:04:25,000 --> 00:04:28,000 +so this is what we want here. + +117 +00:04:28,000 --> 00:04:30,000 +And then if I click on All Jobs, it should be there. + +118 +00:04:30,000 --> 00:04:32,000 +So you can see we got React developer, + +119 +00:04:32,000 --> 00:04:35,000 +this is what we want to build, right? + +120 +00:04:35,000 --> 00:04:38,000 +And for that, we got all these views here, + +121 +00:04:38,000 --> 00:04:40,000 +but then none of this view will actually work + +122 +00:04:40,000 --> 00:04:43,000 +because I mean, of course we do have a view there, + +123 +00:04:43,000 --> 00:04:45,000 +but we have to build a backend. + +124 +00:04:45,000 --> 00:04:47,000 +But before we build a backend, I want to show you the code + +125 +00:04:47,000 --> 00:04:50,000 +inside this to show you what we really trying to build + +126 +00:04:50,000 --> 00:04:53,000 +and what should be the backend for it. + +127 +00:04:53,000 --> 00:04:55,000 +So we'll see that in the next video. + diff --git a/14 - Building a Project/002 Source-Code.url b/14 - Building a Project/002 Source-Code.url new file mode 100644 index 0000000000000000000000000000000000000000..7e04a22f1e5caf33ffb7f668c9099f00c6aa7c14 --- /dev/null +++ b/14 - Building a Project/002 Source-Code.url @@ -0,0 +1,2 @@ +[InternetShortcut] +URL=https://github.com/navinreddy20/spring6-course/tree/main/7%20JobApp-Project \ No newline at end of file diff --git a/14 - Building a Project/003 Understanding Views_en.srt b/14 - Building a Project/003 Understanding Views_en.srt new file mode 100644 index 0000000000000000000000000000000000000000..1dfc51d557f837c5e644ed9bd0eab3aeef2fba3e --- /dev/null +++ b/14 - Building a Project/003 Understanding Views_en.srt @@ -0,0 +1,576 @@ +1 +00:00:00,000 --> 00:00:03,000 +(soft music) + +2 +00:00:03,000 --> 00:00:05,000 +-: Now let's understand these pages here. + +3 +00:00:05,000 --> 00:00:07,000 +So initially I will go for the homepage. + +4 +00:00:07,000 --> 00:00:09,000 +Now what we want in homepage is very simple. + +5 +00:00:09,000 --> 00:00:10,000 +Let me just show you the homepage. + +6 +00:00:10,000 --> 00:00:13,000 +So basically we want this, all this text on the top. + +7 +00:00:13,000 --> 00:00:14,000 +Again, not a big fan of views, + +8 +00:00:14,000 --> 00:00:16,000 +but let's say we have this top screen here + +9 +00:00:16,000 --> 00:00:19,000 +and let me just close that spring initialize. + +10 +00:00:19,000 --> 00:00:22,000 +Okay, and then in this, I want two tabs here. + +11 +00:00:22,000 --> 00:00:26,000 +One for view all jobs and second on add jobs. + +12 +00:00:26,000 --> 00:00:29,000 +So basically I need two links to call those URLs. + +13 +00:00:29,000 --> 00:00:31,000 +And the way I have done that is this. + +14 +00:00:31,000 --> 00:00:33,000 +So in this view, basically you can see + +15 +00:00:33,000 --> 00:00:36,000 +there are lot of things, but we are using some bootstraps + +16 +00:00:36,000 --> 00:00:38,000 +so that it'll look beautiful + +17 +00:00:38,000 --> 00:00:40,000 +and some external settings in our CSS. + +18 +00:00:40,000 --> 00:00:42,000 +But important thing is not views, + +19 +00:00:42,000 --> 00:00:44,000 +but the way we are calling them. + +20 +00:00:44,000 --> 00:00:46,000 +So you can see we have two links here. + +21 +00:00:46,000 --> 00:00:49,000 +One for the homepage, in fact that's for the navigation bar. + +22 +00:00:49,000 --> 00:00:51,000 +We got home, we got view all jobs, + +23 +00:00:51,000 --> 00:00:54,000 +and we are also visiting the homepage of Telusko + +24 +00:00:54,000 --> 00:00:57,000 +using contact and okay, + +25 +00:00:57,000 --> 00:00:59,000 +but this is the thing which I want. + +26 +00:00:59,000 --> 00:01:01,000 +So those two buttons are because of this view all jobs, + +27 +00:01:01,000 --> 00:01:03,000 +this is a URL we are hitting. + +28 +00:01:03,000 --> 00:01:05,000 +So when I click on view all jobs, + +29 +00:01:05,000 --> 00:01:07,000 +this is a URL. + +30 +00:01:07,000 --> 00:01:10,000 +For add job this is a URL. + +31 +00:01:10,000 --> 00:01:11,000 +So we have to map it for two things, + +32 +00:01:11,000 --> 00:01:15,000 +/view all jobs and /add job. + +33 +00:01:15,000 --> 00:01:19,000 +And also if you observe when you go to the homepage, + +34 +00:01:19,000 --> 00:01:23,000 +so let's say if I run the homepage, it shows the same page. + +35 +00:01:23,000 --> 00:01:25,000 +When I click on home, again, it shows the same page + +36 +00:01:25,000 --> 00:01:30,000 +because we got two URLs hitting the same page, right? + +37 +00:01:30,000 --> 00:01:32,000 +So have to do the mapping for that as well. + +38 +00:01:32,000 --> 00:01:35,000 +So basically you have to map four URLs now. + +39 +00:01:35,000 --> 00:01:39,000 +Add job, view all jobs, homepage, and /home. + +40 +00:01:39,000 --> 00:01:40,000 +So four. + +41 +00:01:40,000 --> 00:01:41,000 +In fact, we also need success, right? + +42 +00:01:41,000 --> 00:01:44,000 +If you remember, we also have one more page called success + +43 +00:01:44,000 --> 00:01:46,000 +and we'll see how do we call success there. + +44 +00:01:46,000 --> 00:01:47,000 +But at this point we are editing. + +45 +00:01:47,000 --> 00:01:51,000 +So in total we have to hit 5, 4, one is the redaction. + +46 +00:01:51,000 --> 00:01:53,000 +But yeah, four URLs + +47 +00:01:53,000 --> 00:01:56,000 +and anything else if I want to view all jobs, + +48 +00:01:56,000 --> 00:01:58,000 +because this will be stored somewhere, right? + +49 +00:01:58,000 --> 00:02:00,000 +Of course we are not using database here, + +50 +00:02:00,000 --> 00:02:02,000 +but slowly we'll move to a database as well. + +51 +00:02:02,000 --> 00:02:03,000 +Now this project becomes important + +52 +00:02:03,000 --> 00:02:05,000 +because once we move forward, + +53 +00:02:05,000 --> 00:02:08,000 +we'll talk about how do we use Spring web + +54 +00:02:08,000 --> 00:02:10,000 +with the React front end. + +55 +00:02:10,000 --> 00:02:13,000 +So we'll convert the entire project into React front end, + +56 +00:02:13,000 --> 00:02:15,000 +which will use separate application, + +57 +00:02:15,000 --> 00:02:16,000 +which will hit your server. + +58 +00:02:16,000 --> 00:02:19,000 +And then a server will not be responding with the pages. + +59 +00:02:19,000 --> 00:02:22,000 +A server will respond with JSON data and that will be fancy. + +60 +00:02:22,000 --> 00:02:26,000 +And then if you see here, what we have done is, again, + +61 +00:02:26,000 --> 00:02:28,000 +these are all the nav bar. + +62 +00:02:28,000 --> 00:02:31,000 +This is where we are actually printing data. + +63 +00:02:31,000 --> 00:02:33,000 +So whatever data you're getting printed here, + +64 +00:02:33,000 --> 00:02:34,000 +so if I click on view jobs, + +65 +00:02:34,000 --> 00:02:36,000 +all this data which is getting printed here + +66 +00:02:36,000 --> 00:02:39,000 +is because of this particular tags here. + +67 +00:02:39,000 --> 00:02:43,000 +So example, the first thing, which is the Java developer, + +68 +00:02:43,000 --> 00:02:44,000 +how this is coming, + +69 +00:02:44,000 --> 00:02:47,000 +it is coming because of this post profile. + +70 +00:02:47,000 --> 00:02:50,000 +This is one of the variable in the class. + +71 +00:02:50,000 --> 00:02:53,000 +And if you see we are running a for loop. + +72 +00:02:53,000 --> 00:02:56,000 +Now basically I'm not focusing more on JSPs + +73 +00:02:56,000 --> 00:02:58,000 +because the front technology, + +74 +00:02:58,000 --> 00:03:00,000 +the view technology will keep changing. + +75 +00:03:00,000 --> 00:03:01,000 +Even if you're learning Spring, + +76 +00:03:01,000 --> 00:03:04,000 +you might want to use some different view technologies. + +77 +00:03:04,000 --> 00:03:05,000 +So this specific to JSP, + +78 +00:03:05,000 --> 00:03:07,000 +and that's what we're not focusing on that, + +79 +00:03:07,000 --> 00:03:11,000 +but you can basically use forEach, which is a loop, + +80 +00:03:11,000 --> 00:03:14,000 +which it trades for an array here + +81 +00:03:14,000 --> 00:03:16,000 +and it'll pick up one by one. + +82 +00:03:16,000 --> 00:03:18,000 +So whatever data you have in the array + +83 +00:03:18,000 --> 00:03:21,000 +it'll pick up the first element. + +84 +00:03:21,000 --> 00:03:23,000 +It'll get all the value from the element. + +85 +00:03:23,000 --> 00:03:25,000 +You can see I'm fetching post profile, + +86 +00:03:25,000 --> 00:03:27,000 +I'm fetching post description, + +87 +00:03:27,000 --> 00:03:29,000 +I'm fetching required experience, + +88 +00:03:29,000 --> 00:03:32,000 +I'm fetching the tech stack, which is itself + +89 +00:03:32,000 --> 00:03:34,000 +is a array, right? + +90 +00:03:34,000 --> 00:03:37,000 +So you can see again we are using a forEach here + +91 +00:03:37,000 --> 00:03:39,000 +to fetch each tech stack. + +92 +00:03:39,000 --> 00:03:40,000 +That's what we are doing here. + +93 +00:03:40,000 --> 00:03:43,000 +You can see we have multiple tech stack, not just one. + +94 +00:03:43,000 --> 00:03:44,000 +So that's what we are doing here + +95 +00:03:44,000 --> 00:03:46,000 +and that's what we are able to fetch. + +96 +00:03:46,000 --> 00:03:48,000 +But then not once, depending upon how many elements + +97 +00:03:48,000 --> 00:03:49,000 +you have in the array + +98 +00:03:49,000 --> 00:03:52,000 +that many time it will basically run the loop. + +99 +00:03:52,000 --> 00:03:53,000 +In the add job, + +100 +00:03:53,000 --> 00:03:54,000 +we have a simple form here. + +101 +00:03:54,000 --> 00:03:57,000 +You can see we got a form. + +102 +00:03:57,000 --> 00:03:59,000 +This is a form. + +103 +00:03:59,000 --> 00:04:00,000 +There is a form, yeah, this is a form. + +104 +00:04:00,000 --> 00:04:03,000 +And the URL is handle form. + +105 +00:04:03,000 --> 00:04:06,000 +So basically we got five URLs to handle now, + +106 +00:04:06,000 --> 00:04:08,000 +and then we are sending a POST request. + +107 +00:04:08,000 --> 00:04:10,000 +Now when you say in HTTP + +108 +00:04:10,000 --> 00:04:11,000 +we have different types of methods. + +109 +00:04:11,000 --> 00:04:13,000 +At this point let's discuss only two. + +110 +00:04:13,000 --> 00:04:15,000 +So when you want to get data from the server, + +111 +00:04:15,000 --> 00:04:16,000 +we use a GET request + +112 +00:04:16,000 --> 00:04:19,000 +and by default all the requests are GET. + +113 +00:04:19,000 --> 00:04:20,000 +But if you want to submit data, + +114 +00:04:20,000 --> 00:04:22,000 +we have to use a POST request. + +115 +00:04:22,000 --> 00:04:24,000 +It's not like you cannot use GET here, + +116 +00:04:24,000 --> 00:04:27,000 +it's just that when you use a GET request in the URL, + +117 +00:04:27,000 --> 00:04:28,000 +you will get all the values. + +118 +00:04:28,000 --> 00:04:29,000 +We don't want that. + +119 +00:04:29,000 --> 00:04:30,000 +We want to send a POST request + +120 +00:04:30,000 --> 00:04:33,000 +where the URL should not show the data. + +121 +00:04:33,000 --> 00:04:36,000 +Imagine you're sending a password, okay, let's not do that. + +122 +00:04:36,000 --> 00:04:38,000 +Okay, so we have all this data here you can see + +123 +00:04:38,000 --> 00:04:40,000 +we are asking for the POST ID. + +124 +00:04:40,000 --> 00:04:44,000 +We are asking for POST profile, POST description, + +125 +00:04:44,000 --> 00:04:46,000 +required experience and tech stack. + +126 +00:04:46,000 --> 00:04:48,000 +And you can see we have a list of tech stack there. + +127 +00:04:48,000 --> 00:04:50,000 +And that's why we have all these options here. + +128 +00:04:50,000 --> 00:04:52,000 +It's huge. + +129 +00:04:52,000 --> 00:04:55,000 +My team has done that, searched all this tech stack. + +130 +00:04:55,000 --> 00:04:57,000 +I'm not sure how long it is, but it doesn't matter. + +131 +00:04:57,000 --> 00:04:59,000 +We have quite a huge tech stack here. + +132 +00:04:59,000 --> 00:05:02,000 +And yeah, some script for bootstrap. + +133 +00:05:02,000 --> 00:05:04,000 +Okay, so this is what the add job is. + +134 +00:05:04,000 --> 00:05:06,000 +The home is, we have talked about home. + +135 +00:05:06,000 --> 00:05:10,000 +Success since we only adding one POST at a time + +136 +00:05:10,000 --> 00:05:14,000 +in the success page, you just want to see one POST. + +137 +00:05:14,000 --> 00:05:16,000 +And that's why you can see we are only fetching + +138 +00:05:16,000 --> 00:05:20,000 +one POST here, not a loop, a simple get profile + +139 +00:05:20,000 --> 00:05:23,000 +and get tech stack and all the stuff. + +140 +00:05:23,000 --> 00:05:24,000 +Nothing fancy. + +141 +00:05:24,000 --> 00:05:25,000 +We're just fetching here. + +142 +00:05:25,000 --> 00:05:27,000 +But none of this will work + +143 +00:05:27,000 --> 00:05:29,000 +because we have not created the controller. + +144 +00:05:29,000 --> 00:05:30,000 +Okay, let's do that in the next video. + diff --git a/14 - Building a Project/004 Home and AddJob Controller_en.srt b/14 - Building a Project/004 Home and AddJob Controller_en.srt new file mode 100644 index 0000000000000000000000000000000000000000..868d6caa50675daf62ee4b83b05b96ee8f33c11b --- /dev/null +++ b/14 - Building a Project/004 Home and AddJob Controller_en.srt @@ -0,0 +1,588 @@ +1 +00:00:00,000 --> 00:00:03,000 +(bright music) + +2 +00:00:03,000 --> 00:00:05,000 +-: So it's time to build the backend of it. + +3 +00:00:05,000 --> 00:00:07,000 +Basically, I'm talking about the controllers, + +4 +00:00:07,000 --> 00:00:09,000 +the service class, and the model class. + +5 +00:00:09,000 --> 00:00:11,000 +And also we need repo. + +6 +00:00:11,000 --> 00:00:12,000 +We are not going to connect with the database, + +7 +00:00:12,000 --> 00:00:14,000 +but at least let's have the repo layer. + +8 +00:00:14,000 --> 00:00:16,000 +Maybe in future, if you want to connect into a database, + +9 +00:00:16,000 --> 00:00:17,000 +how will you do it? + +10 +00:00:17,000 --> 00:00:18,000 +So let's have that repo layer ready + +11 +00:00:18,000 --> 00:00:20,000 +and then we can start working. + +12 +00:00:20,000 --> 00:00:22,000 +Okay, there's one more thing I want to do here + +13 +00:00:22,000 --> 00:00:24,000 +is I wanna make sure that the properties are set + +14 +00:00:24,000 --> 00:00:26,000 +in the application properties. + +15 +00:00:26,000 --> 00:00:29,000 +Now what I'm talking about is if you go to the sources, + +16 +00:00:29,000 --> 00:00:31,000 +we do have application dot properties, + +17 +00:00:31,000 --> 00:00:33,000 +and this is where we have to send two things, + +18 +00:00:33,000 --> 00:00:35,000 +the prefix and suffix. + +19 +00:00:35,000 --> 00:00:38,000 +So I can just use that from the previous project. + +20 +00:00:38,000 --> 00:00:39,000 +We have done this before, right? + +21 +00:00:39,000 --> 00:00:40,000 +So I'm just studying the properties, + +22 +00:00:40,000 --> 00:00:42,000 +which is views and dot jsp, + +23 +00:00:42,000 --> 00:00:44,000 +because my views are in the views folder. + +24 +00:00:44,000 --> 00:00:45,000 +That's done. + +25 +00:00:45,000 --> 00:00:47,000 +Now let's, we'll not be touching this file again, + +26 +00:00:47,000 --> 00:00:48,000 +so let me close it. + +27 +00:00:48,000 --> 00:00:49,000 +I think I've made some changes in the admin, + +28 +00:00:49,000 --> 00:00:52,000 +so let me just reload the changes. + +29 +00:00:52,000 --> 00:00:54,000 +Maybe have done that in the last video. + +30 +00:00:54,000 --> 00:00:55,000 +Let me just check that once. + +31 +00:00:55,000 --> 00:00:56,000 +Okay, looks good. + +32 +00:00:56,000 --> 00:00:59,000 +So now let's start with the Java part here. + +33 +00:00:59,000 --> 00:01:02,000 +So if you see we do have only one file, which is your main, + +34 +00:01:02,000 --> 00:01:03,000 +and we will not touching this. + +35 +00:01:03,000 --> 00:01:05,000 +We have to create controllers, the first step, right? + +36 +00:01:05,000 --> 00:01:09,000 +So let's create a controller here and we'll say Java class. + +37 +00:01:09,000 --> 00:01:11,000 +Now we'll say this is job controller, okay. + +38 +00:01:11,000 --> 00:01:13,000 +Now, if you want this to be a controller, + +39 +00:01:13,000 --> 00:01:17,000 +you have to use annotation, which is controller. + +40 +00:01:17,000 --> 00:01:17,000 +That's the first thing. + +41 +00:01:17,000 --> 00:01:19,000 +And now we have to do the mapping, right? + +42 +00:01:19,000 --> 00:01:22,000 +Remember we have talked about the five different mappings + +43 +00:01:22,000 --> 00:01:23,000 +which you have to do. + +44 +00:01:23,000 --> 00:01:25,000 +And we have start step by step. + +45 +00:01:25,000 --> 00:01:27,000 +Let's work with the home, okay? + +46 +00:01:27,000 --> 00:01:29,000 +So if you wanna make sure that when you call home + +47 +00:01:29,000 --> 00:01:33,000 +or slash home, or you said simply the homepage, + +48 +00:01:33,000 --> 00:01:34,000 +it should call the same page, okay? + +49 +00:01:34,000 --> 00:01:36,000 +So that's the first thing we want to do. + +50 +00:01:36,000 --> 00:01:38,000 +So for that, what you're going to do + +51 +00:01:38,000 --> 00:01:40,000 +is you are going to create a method which is public wide, + +52 +00:01:40,000 --> 00:01:42,000 +in fact, not wide, public string, + +53 +00:01:42,000 --> 00:01:43,000 +because we wanna return the name of the page, + +54 +00:01:43,000 --> 00:01:46,000 +and let's call this as home, okay? + +55 +00:01:46,000 --> 00:01:49,000 +And in this, we are going to return the page name, + +56 +00:01:49,000 --> 00:01:50,000 +and what's the page name here? + +57 +00:01:50,000 --> 00:01:52,000 +So the page is home dot jsp. + +58 +00:01:52,000 --> 00:01:55,000 +I will just return home, our job is done, + +59 +00:01:55,000 --> 00:01:56,000 +but then we have to do the mapping as well, right? + +60 +00:01:56,000 --> 00:01:58,000 +Now what mapping have to do? + +61 +00:01:58,000 --> 00:02:01,000 +Of course, I will say request mapping here, and in bracket. + +62 +00:02:01,000 --> 00:02:03,000 +Now it's not just one URL, right? + +63 +00:02:03,000 --> 00:02:06,000 +So example, if you just want to make it for homepage, + +64 +00:02:06,000 --> 00:02:07,000 +you can simply say slash, + +65 +00:02:07,000 --> 00:02:09,000 +but I want this to work for two URLs, + +66 +00:02:09,000 --> 00:02:12,000 +slash and home as well. + +67 +00:02:12,000 --> 00:02:14,000 +So in that case, what I will do is I will just put that + +68 +00:02:14,000 --> 00:02:18,000 +in as an alley, and the next one is home. + +69 +00:02:18,000 --> 00:02:20,000 +So this method will be called for both request. + +70 +00:02:20,000 --> 00:02:24,000 +So slash and when you click on home button on the page, + +71 +00:02:24,000 --> 00:02:26,000 +it will be hitting this URL. + +72 +00:02:26,000 --> 00:02:29,000 +So for both, we are calling the homepage, okay? + +73 +00:02:29,000 --> 00:02:30,000 +That's what we are doing. + +74 +00:02:30,000 --> 00:02:32,000 +So let's see if that works. + +75 +00:02:32,000 --> 00:02:36,000 +I will just go back to my application and run this. + +76 +00:02:36,000 --> 00:02:37,000 +I hope this will work. + +77 +00:02:37,000 --> 00:02:38,000 +Okay, Tomcat started. + +78 +00:02:38,000 --> 00:02:40,000 +It's time to open the browser. + +79 +00:02:40,000 --> 00:02:42,000 +Okay, this was the earlier thing. + +80 +00:02:42,000 --> 00:02:44,000 +Let's hit that URL once again. + +81 +00:02:44,000 --> 00:02:45,000 +Loading, okay, so we got the homepage, right? + +82 +00:02:45,000 --> 00:02:46,000 +That's awesome. + +83 +00:02:46,000 --> 00:02:49,000 +But if I try to say view all pages not working + +84 +00:02:49,000 --> 00:02:50,000 +because we have not done the mapping yet, + +85 +00:02:50,000 --> 00:02:53,000 +add job not working, but the homepage is working. + +86 +00:02:53,000 --> 00:02:56,000 +If I click on home again, it's working, + +87 +00:02:56,000 --> 00:02:58,000 +but if you see the URL, it is slash home. + +88 +00:02:58,000 --> 00:03:00,000 +So both for both the URL, + +89 +00:03:00,000 --> 00:03:04,000 +if you say slash home or just the website homepage, + +90 +00:03:04,000 --> 00:03:06,000 +you get the things working out. + +91 +00:03:06,000 --> 00:03:08,000 +So we got the same, we got the first page. + +92 +00:03:08,000 --> 00:03:10,000 +I want the contact to work. + +93 +00:03:10,000 --> 00:03:12,000 +It will work because we are referring + +94 +00:03:12,000 --> 00:03:15,000 +to the external website, which there is called homepage. + +95 +00:03:15,000 --> 00:03:16,000 +This is working fine, + +96 +00:03:16,000 --> 00:03:19,000 +but if I click on all jobs, not working. + +97 +00:03:19,000 --> 00:03:21,000 +So this is what we need to work now. + +98 +00:03:21,000 --> 00:03:23,000 +Okay, let's go back to the Java project, + +99 +00:03:23,000 --> 00:03:25,000 +and let's go back to the homepage or the controller. + +100 +00:03:25,000 --> 00:03:30,000 +Okay, so now let's do the mapping for add job, okay? + +101 +00:03:30,000 --> 00:03:34,000 +So I will say public string add. + +102 +00:03:34,000 --> 00:03:37,000 +So someone, if someone calls for the add job request, + +103 +00:03:37,000 --> 00:03:39,000 +so when you click on the add job, it should, + +104 +00:03:39,000 --> 00:03:41,000 +it should call the add job page, right? + +105 +00:03:41,000 --> 00:03:44,000 +So I will say simply return, add job, + +106 +00:03:44,000 --> 00:03:46,000 +and let's do the mapping for this. + +107 +00:03:46,000 --> 00:03:49,000 +This should be mapping for request mapping. + +108 +00:03:49,000 --> 00:03:51,000 +Now what's the URL is heading? + +109 +00:03:51,000 --> 00:03:54,000 +So if you go back here, click on add job, look at the URL. + +110 +00:03:54,000 --> 00:03:59,000 +It says local 8080 slash add job, okay? + +111 +00:03:59,000 --> 00:04:01,000 +So that's what we need to refer here, + +112 +00:04:01,000 --> 00:04:02,000 +add job, that's it. + +113 +00:04:02,000 --> 00:04:04,000 +This should look, this looks good. + +114 +00:04:04,000 --> 00:04:06,000 +Let's see if that works. + +115 +00:04:06,000 --> 00:04:08,000 +Let's restart the application and go back here. + +116 +00:04:08,000 --> 00:04:09,000 +Let's refresh. + +117 +00:04:09,000 --> 00:04:11,000 +Still not working. + +118 +00:04:11,000 --> 00:04:13,000 +Okay, so let's see what went wrong. + +119 +00:04:13,000 --> 00:04:17,000 +So when I click on add job, is it doing something? + +120 +00:04:17,000 --> 00:04:18,000 +Let me just check. + +121 +00:04:18,000 --> 00:04:21,000 +So maybe it is calling the add job. + +122 +00:04:21,000 --> 00:04:22,000 +Oh, the page is wrong. + +123 +00:04:22,000 --> 00:04:23,000 +It is add job. + +124 +00:04:23,000 --> 00:04:25,000 +It's not capital, my bad. + +125 +00:04:25,000 --> 00:04:26,000 +And let's refresh. + +126 +00:04:26,000 --> 00:04:28,000 +Okay, it worked. + +127 +00:04:28,000 --> 00:04:29,000 +So let me go back to homepage again. + +128 +00:04:29,000 --> 00:04:31,000 +And when I click on add job, so we got this page, right? + +129 +00:04:31,000 --> 00:04:36,000 +And now if I click on some data, so when I say post 101, + +130 +00:04:36,000 --> 00:04:40,000 +I'm adding a profile here, which is let's say, Java dev, + +131 +00:04:40,000 --> 00:04:43,000 +and then some post, some experience, + +132 +00:04:43,000 --> 00:04:45,000 +and let's say only Java, click on Submit. + +133 +00:04:45,000 --> 00:04:46,000 +Oh, it's not working. + +134 +00:04:46,000 --> 00:04:47,000 +You know why it's not working? + +135 +00:04:47,000 --> 00:04:50,000 +Because when you click on that page, + +136 +00:04:50,000 --> 00:04:52,000 +because this page is getting called, right? + +137 +00:04:52,000 --> 00:04:55,000 +In this page, when you click on Submit, + +138 +00:04:55,000 --> 00:04:57,000 +so let's look at the form tag. + +139 +00:04:57,000 --> 00:05:00,000 +You are basically calling the handle form. + +140 +00:05:00,000 --> 00:05:03,000 +So when you click on Submit, you're calling a handle form + +141 +00:05:03,000 --> 00:05:06,000 +and we are not doing anything to handle this form, okay? + +142 +00:05:06,000 --> 00:05:08,000 +So let's do that in the next video. + +143 +00:05:08,000 --> 00:05:09,000 +How do we handle the form? + +144 +00:05:09,000 --> 00:05:12,000 +Because this is where we have to work with the post request. + +145 +00:05:12,000 --> 00:05:13,000 +Now this is new. + +146 +00:05:13,000 --> 00:05:15,000 +We have worked with the get request, but not post. + +147 +00:05:15,000 --> 00:05:16,000 +Let's say that in the next video. + diff --git a/14 - Building a Project/005 Handling Form_en.srt b/14 - Building a Project/005 Handling Form_en.srt new file mode 100644 index 0000000000000000000000000000000000000000..46f0d891cc5104b30bb8ef72e67ba20583712cd0 --- /dev/null +++ b/14 - Building a Project/005 Handling Form_en.srt @@ -0,0 +1,760 @@ +1 +00:00:00,000 --> 00:00:03,000 +(upbeat music) + +2 +00:00:03,000 --> 00:00:05,000 +-: Okay, so let's work with the form handling now. + +3 +00:00:05,000 --> 00:00:08,000 +So basically we are sending a form here, right? + +4 +00:00:08,000 --> 00:00:10,000 +So this is not normal HTML form in which you have certain + +5 +00:00:10,000 --> 00:00:12,000 +fields and when you click on submit, + +6 +00:00:12,000 --> 00:00:15,000 +and we are sending a post request now. + +7 +00:00:15,000 --> 00:00:17,000 +So to handle the post request, let's go back + +8 +00:00:17,000 --> 00:00:21,000 +to the job controller and let's create a method. + +9 +00:00:21,000 --> 00:00:23,000 +I will say public string + +10 +00:00:23,000 --> 00:00:26,000 +and let's maintain this as handle form. + +11 +00:00:26,000 --> 00:00:27,000 +Okay, now what is a URL? + +12 +00:00:27,000 --> 00:00:29,000 +So we have to say request mapping, + +13 +00:00:29,000 --> 00:00:34,000 +and then in the bracket we have to mention the request, + +14 +00:00:34,000 --> 00:00:36,000 +which is handle form. + +15 +00:00:36,000 --> 00:00:39,000 +I think it is small, let's verify, no, it's capital. + +16 +00:00:39,000 --> 00:00:41,000 +Let's go with capital. + +17 +00:00:42,000 --> 00:00:44,000 +Okay, so we are handling the form now + +18 +00:00:44,000 --> 00:00:47,000 +and here we have to basically return the page, + +19 +00:00:47,000 --> 00:00:48,000 +which is success.jsp. + +20 +00:00:48,000 --> 00:00:51,000 +So let's return success, okay, but will it really work? + +21 +00:00:51,000 --> 00:00:54,000 +Let's try, so what I will do is I will just relaunch this + +22 +00:00:54,000 --> 00:00:58,000 +and go back here, refresh, send. + +23 +00:00:58,000 --> 00:01:01,000 +Okay, let's go back to the homepage again. + +24 +00:01:01,000 --> 00:01:02,000 +So let's click on submit now + +25 +00:01:02,000 --> 00:01:04,000 +and you can see it's not working, + +26 +00:01:04,000 --> 00:01:08,000 +but this time you're not getting 404, we are getting 500. + +27 +00:01:08,000 --> 00:01:11,000 +So something worked and something doesn't. + +28 +00:01:11,000 --> 00:01:12,000 +So let's see what worked. + +29 +00:01:12,000 --> 00:01:15,000 +If you see it is trying to call the success page. + +30 +00:01:15,000 --> 00:01:19,000 +If you go back here or is it really calling success page? + +31 +00:01:19,000 --> 00:01:22,000 +Let's see what's there though, okay, it says it's trying + +32 +00:01:22,000 --> 00:01:24,000 +to call the success page. + +33 +00:01:24,000 --> 00:01:25,000 +So nothing went wrong there. + +34 +00:01:25,000 --> 00:01:27,000 +It's calling the success page, + +35 +00:01:27,000 --> 00:01:31,000 +but it is not able to find, it cannot resolve the job post. + +36 +00:01:31,000 --> 00:01:32,000 +What is this job post? + +37 +00:01:32,000 --> 00:01:34,000 +Let's go back to success page + +38 +00:01:34,000 --> 00:01:36,000 +and let's see what is job post here. + +39 +00:01:36,000 --> 00:01:37,000 +Now job post, + +40 +00:01:37,000 --> 00:01:39,000 +if you see have written a Java coin inside this. + +41 +00:01:39,000 --> 00:01:41,000 +So job post is basically a class + +42 +00:01:41,000 --> 00:01:43,000 +and we don't have that class. + +43 +00:01:43,000 --> 00:01:44,000 +So basically it's a model. + +44 +00:01:44,000 --> 00:01:46,000 +So what are the things we need in job post? + +45 +00:01:46,000 --> 00:01:49,000 +Now basically whatever you are entering in your + +46 +00:01:49,000 --> 00:01:52,000 +page here, everything. + +47 +00:01:52,000 --> 00:01:55,000 +So I need ID, I need profile, I need description, + +48 +00:01:55,000 --> 00:01:57,000 +I need required experience, I need tech stack. + +49 +00:01:57,000 --> 00:01:59,000 +And tech stack is not one, we have multiple. + +50 +00:01:59,000 --> 00:02:03,000 +So we basically we have to use array or at least. + +51 +00:02:03,000 --> 00:02:06,000 +So let's see, so I have to create a page. + +52 +00:02:06,000 --> 00:02:07,000 +So we'll just create a package here. + +53 +00:02:07,000 --> 00:02:12,000 +And this is for the, okay, so we'll say job post, + +54 +00:02:12,000 --> 00:02:16,000 +but this should be a part of a package called model. + +55 +00:02:16,000 --> 00:02:18,000 +Of course you can keep everything in one file, + +56 +00:02:18,000 --> 00:02:21,000 +but it makes sense to our different package. + +57 +00:02:21,000 --> 00:02:22,000 +So job post, + +58 +00:02:25,000 --> 00:02:26,000 +move to package. + +59 +00:02:26,000 --> 00:02:28,000 +Yeah, so you can say we got a model package now in which we + +60 +00:02:28,000 --> 00:02:31,000 +have job post, what are the things we need in job post? + +61 +00:02:31,000 --> 00:02:35,000 +So basically I need the post ID, the post profile, + +62 +00:02:35,000 --> 00:02:37,000 +the post description required experience + +63 +00:02:37,000 --> 00:02:40,000 +and the list of tech stack. + +64 +00:02:40,000 --> 00:02:43,000 +Okay, so basically I need these five variables + +65 +00:02:43,000 --> 00:02:44,000 +to make it work because this is + +66 +00:02:44,000 --> 00:02:46,000 +what you are sending from a form + +67 +00:02:46,000 --> 00:02:49,000 +and you want to display that in the success. + +68 +00:02:49,000 --> 00:02:51,000 +Now the thing is for these five variables, I need to work + +69 +00:02:51,000 --> 00:02:53,000 +with getters and setters. + +70 +00:02:53,000 --> 00:02:55,000 +But don't you think the getter setters + +71 +00:02:55,000 --> 00:02:57,000 +should be something which Java should give you? + +72 +00:02:57,000 --> 00:03:00,000 +See the thing is, when you create a variable + +73 +00:03:00,000 --> 00:03:01,000 +private, you have to need datasets. + +74 +00:03:01,000 --> 00:03:03,000 +You also need toString method + +75 +00:03:03,000 --> 00:03:06,000 +and that's where we have added one of the dependency. + +76 +00:03:06,000 --> 00:03:08,000 +If you go to your pom.xml, + +77 +00:03:08,000 --> 00:03:10,000 +we have added something called Lombok. + +78 +00:03:10,000 --> 00:03:12,000 +Now Lombok will basically help you + +79 +00:03:12,000 --> 00:03:15,000 +to reduce the number of lines of code. + +80 +00:03:15,000 --> 00:03:17,000 +So what you can basically do is you can mention + +81 +00:03:17,000 --> 00:03:20,000 +that this is a data class, so you don't have + +82 +00:03:20,000 --> 00:03:22,000 +to create getter setters for this. + +83 +00:03:22,000 --> 00:03:24,000 +Also, if you need constructor, I need a default constructor, + +84 +00:03:24,000 --> 00:03:27,000 +I need a constructor for all the arguments, + +85 +00:03:27,000 --> 00:03:29,000 +you can simply use this annotations there. + +86 +00:03:29,000 --> 00:03:31,000 +So basically by using these annotations, + +87 +00:03:31,000 --> 00:03:33,000 +what you're doing is you are making sure that you don't need + +88 +00:03:33,000 --> 00:03:36,000 +to create all the getter setters + +89 +00:03:36,000 --> 00:03:38,000 +and toString method, the hash code method, + +90 +00:03:38,000 --> 00:03:40,000 +everything will be taken gear by this data class here + +91 +00:03:40,000 --> 00:03:44,000 +if you want constructor, these two annotations are required + +92 +00:03:44,000 --> 00:03:46,000 +for a default constructor + +93 +00:03:46,000 --> 00:03:48,000 +and a constructor, which will take all the parameters, + +94 +00:03:48,000 --> 00:03:50,000 +but also since we're using spring, so we have + +95 +00:03:50,000 --> 00:03:51,000 +to also make this component + +96 +00:03:51,000 --> 00:03:55,000 +because I want to use it in the other classes. + +97 +00:03:55,000 --> 00:03:57,000 +So that's one, that's it, this is the class we need. + +98 +00:03:57,000 --> 00:03:59,000 +Now success page should work, right? + +99 +00:03:59,000 --> 00:04:02,000 +Because we do have that class now. + +100 +00:04:02,000 --> 00:04:03,000 +Let's see if that works. + +101 +00:04:03,000 --> 00:04:05,000 +Let's relaunch, so when you use Lombok, basically it'll + +102 +00:04:05,000 --> 00:04:08,000 +ask you to enable the annotation processing + +103 +00:04:08,000 --> 00:04:09,000 +and we have enabled that now. + +104 +00:04:09,000 --> 00:04:13,000 +Let's go back here, click on submit, + +105 +00:04:13,000 --> 00:04:14,000 +something is happening again, we got the error, + +106 +00:04:14,000 --> 00:04:16,000 +but this time the error should be different. + +107 +00:04:16,000 --> 00:04:18,000 +Let's see what the error is. + +108 +00:04:18,000 --> 00:04:21,000 +Okay, so it says job post cannot be resolved to a type. + +109 +00:04:21,000 --> 00:04:24,000 +Is it the same problem before? + +110 +00:04:24,000 --> 00:04:26,000 +So the error is not very specific, + +111 +00:04:26,000 --> 00:04:27,000 +but let's solve the problem one by one. + +112 +00:04:27,000 --> 00:04:31,000 +So what we got here is, you know, in the JSP, + +113 +00:04:31,000 --> 00:04:32,000 +basically we are expecting + +114 +00:04:32,000 --> 00:04:35,000 +that from the controller you will be sending this data + +115 +00:04:35,000 --> 00:04:38,000 +because in the controller you are basically + +116 +00:04:38,000 --> 00:04:40,000 +accepting the value. + +117 +00:04:40,000 --> 00:04:43,000 +So if you are, see here we have handle form, + +118 +00:04:43,000 --> 00:04:45,000 +you have to basically accept those values. + +119 +00:04:45,000 --> 00:04:48,000 +We are not doing it, and one of one more problem is + +120 +00:04:48,000 --> 00:04:49,000 +that the request mapping + +121 +00:04:49,000 --> 00:04:51,000 +by default goes for the get request. + +122 +00:04:51,000 --> 00:04:53,000 +Remember we talked about the get request and post request. + +123 +00:04:53,000 --> 00:04:56,000 +So we use get to fetch data, we use post to submit data. + +124 +00:04:56,000 --> 00:05:00,000 +So if you want to use post here, so you have to mention + +125 +00:05:00,000 --> 00:05:02,000 +that the method which we are using here is post. + +126 +00:05:02,000 --> 00:05:04,000 +Otherwise, what you can also do is instead + +127 +00:05:04,000 --> 00:05:07,000 +of using request mapping, you can use post mapping. + +128 +00:05:07,000 --> 00:05:09,000 +What it does is it says we are doing + +129 +00:05:09,000 --> 00:05:11,000 +the mapping for the post method. + +130 +00:05:11,000 --> 00:05:12,000 +So instead of using request + +131 +00:05:12,000 --> 00:05:13,000 +mapping, then specify the method. + +132 +00:05:13,000 --> 00:05:15,000 +You can also use post mapping. + +133 +00:05:15,000 --> 00:05:18,000 +That means here, instead of using request mapping, + +134 +00:05:18,000 --> 00:05:21,000 +we can say get mapping, let's import the package. + +135 +00:05:21,000 --> 00:05:23,000 +So from now basically we'll be focusing on get mapping + +136 +00:05:23,000 --> 00:05:26,000 +and post mapping, not request mapping. + +137 +00:05:26,000 --> 00:05:29,000 +Okay, so when you have a get method, get mapping, post map, + +138 +00:05:29,000 --> 00:05:31,000 +post method, post mapping. + +139 +00:05:31,000 --> 00:05:33,000 +Now since you are sending data, + +140 +00:05:33,000 --> 00:05:34,000 +we have to also accept it, right? + +141 +00:05:34,000 --> 00:05:35,000 +And we have seen that before, right? + +142 +00:05:35,000 --> 00:05:39,000 +If you just want to accept, just create the job post object, + +143 +00:05:39,000 --> 00:05:42,000 +which is let's say job post and your job is done. + +144 +00:05:42,000 --> 00:05:44,000 +That's it, so let's verify the success page. + +145 +00:05:44,000 --> 00:05:47,000 +Once again, we want the job post + +146 +00:05:48,000 --> 00:05:50,000 +and then we got the request dot get attribute. + +147 +00:05:50,000 --> 00:05:53,000 +We can also use JSP here, which we were using before, + +148 +00:05:53,000 --> 00:05:55,000 +but if you want to use java code we can also do that. + +149 +00:05:55,000 --> 00:05:57,000 +So request dot, get attribute job post. + +150 +00:05:57,000 --> 00:05:59,000 +And that's what we are signing here. + +151 +00:05:59,000 --> 00:06:00,000 +This time I think it should work + +152 +00:06:00,000 --> 00:06:02,000 +or maybe we'll get some of different error. + +153 +00:06:02,000 --> 00:06:04,000 +Okay, let's see the output page. + +154 +00:06:04,000 --> 00:06:06,000 +Let's go back here and click on submit. + +155 +00:06:06,000 --> 00:06:08,000 +Okay, again, we got 500. + +156 +00:06:08,000 --> 00:06:10,000 +I'm just expecting different editor this time. + +157 +00:06:10,000 --> 00:06:12,000 +You know what, let me just clear this. + +158 +00:06:12,000 --> 00:06:15,000 +I'm not sure if it is coming from the earlier letter. + +159 +00:06:15,000 --> 00:06:18,000 +Let's refresh, resend the data and go back here. + +160 +00:06:18,000 --> 00:06:20,000 +Okay, it's not able to find job post. + +161 +00:06:20,000 --> 00:06:22,000 +Are we importing the right package? + +162 +00:06:22,000 --> 00:06:25,000 +No, we are importing the wrong package. + +163 +00:06:25,000 --> 00:06:26,000 +So the project name is not this, + +164 +00:06:26,000 --> 00:06:28,000 +this is my idea project name. + +165 +00:06:28,000 --> 00:06:33,000 +The package is com.telusko.jobapp, also verify this. + +166 +00:06:35,000 --> 00:06:37,000 +When you get this project, make sure that you match it. + +167 +00:06:37,000 --> 00:06:40,000 +You are matching with everything which is mentioned here + +168 +00:06:41,000 --> 00:06:46,000 +and let's see if that works now, okay, so it worked. + +169 +00:06:46,000 --> 00:06:48,000 +So you can see we got the post. + +170 +00:06:48,000 --> 00:06:49,000 +The error was because + +171 +00:06:49,000 --> 00:06:51,000 +of this package import, which we were doing. + +172 +00:06:51,000 --> 00:06:55,000 +So we are able to get the data from the user request + +173 +00:06:55,000 --> 00:06:59,000 +to the controller and the data which you are sending is + +174 +00:06:59,000 --> 00:07:01,000 +getting stored in this job post object. + +175 +00:07:01,000 --> 00:07:05,000 +And then the same object we are using in the JSP. + +176 +00:07:05,000 --> 00:07:10,000 +So if you can see, we are basically fetching this object + +177 +00:07:10,000 --> 00:07:13,000 +and that data we are printing in this HTML tags + +178 +00:07:13,000 --> 00:07:16,000 +and that's why you got this data here. + +179 +00:07:16,000 --> 00:07:17,000 +Okay, this is what we have done, right? + +180 +00:07:17,000 --> 00:07:21,000 +Java dev description one year and Java here. + +181 +00:07:21,000 --> 00:07:24,000 +So that's how basically we can use the post mapping. + +182 +00:07:24,000 --> 00:07:26,000 +Now we have few more example. + +183 +00:07:26,000 --> 00:07:29,000 +We have to make sure that this all jobs work. + +184 +00:07:29,000 --> 00:07:31,000 +And also is it really saving + +185 +00:07:31,000 --> 00:07:33,000 +because when you say add job, + +186 +00:07:33,000 --> 00:07:35,000 +is it really saving the data somewhere? + +187 +00:07:35,000 --> 00:07:37,000 +Because once you go back you will not + +188 +00:07:37,000 --> 00:07:38,000 +get the same page again, right? + +189 +00:07:38,000 --> 00:07:40,000 +View jobs will not be having it. + +190 +00:07:40,000 --> 00:07:42,000 +So let's try to solve that in the next video. + diff --git a/14 - Building a Project/006 Working with Layers_en.srt b/14 - Building a Project/006 Working with Layers_en.srt new file mode 100644 index 0000000000000000000000000000000000000000..9cfbc9c7cf56bcaf769ce0c688eef9134a52ff93 --- /dev/null +++ b/14 - Building a Project/006 Working with Layers_en.srt @@ -0,0 +1,848 @@ +1 +00:00:00,000 --> 00:00:03,000 +(bright calm piano music) + +2 +00:00:03,000 --> 00:00:04,000 +-: Now, basically, to this point, + +3 +00:00:04,000 --> 00:00:09,000 +we were able to add the data in the add post or add job + +4 +00:00:09,000 --> 00:00:12,000 +and then we were able to get that on the success page. + +5 +00:00:12,000 --> 00:00:14,000 +Just to confirm that if I refer to the homepage + +6 +00:00:14,000 --> 00:00:16,000 +and if I click on add job + +7 +00:00:16,000 --> 00:00:19,000 +and whatever data you insert here, so I'm writing this too, + +8 +00:00:19,000 --> 00:00:22,000 +I will click on submit, you are getting data here, + +9 +00:00:22,000 --> 00:00:25,000 +but then this is not actually getting added somewhere. + +10 +00:00:25,000 --> 00:00:26,000 +As I mentioned before, + +11 +00:00:26,000 --> 00:00:28,000 +we are not going to use database here, + +12 +00:00:28,000 --> 00:00:30,000 +but still I want to store this data somewhere maybe + +13 +00:00:30,000 --> 00:00:32,000 +in the array or added list. + +14 +00:00:32,000 --> 00:00:35,000 +So let's store this data in the added list. + +15 +00:00:35,000 --> 00:00:37,000 +But how we are going to do that? + +16 +00:00:37,000 --> 00:00:39,000 +See, the thing is if you ask your controller + +17 +00:00:39,000 --> 00:00:41,000 +to save the data, controller will say, + +18 +00:00:41,000 --> 00:00:42,000 +that's not my job, right? + +19 +00:00:42,000 --> 00:00:45,000 +Normally, when you want to do some processing + +20 +00:00:45,000 --> 00:00:47,000 +or if you want to store data somewhere, + +21 +00:00:47,000 --> 00:00:48,000 +it is not the job of a controller. + +22 +00:00:48,000 --> 00:00:50,000 +For this, we have different layers. + +23 +00:00:50,000 --> 00:00:52,000 +Now, one of the layer where controller talks + +24 +00:00:52,000 --> 00:00:53,000 +to is your service layer. + +25 +00:00:53,000 --> 00:00:56,000 +So what I will do is I will just right click here + +26 +00:00:56,000 --> 00:01:00,000 +and create a new class which is your job service, + +27 +00:01:00,000 --> 00:01:02,000 +and this will be in a different package. + +28 +00:01:02,000 --> 00:01:05,000 +Let's say, we are putting that in a service package, okay? + +29 +00:01:05,000 --> 00:01:07,000 +And, of course, we don't have this package here, + +30 +00:01:07,000 --> 00:01:09,000 +so let me create one. + +31 +00:01:09,000 --> 00:01:10,000 +So you can see we got a service package here + +32 +00:01:10,000 --> 00:01:13,000 +in which you got a class called job service. + +33 +00:01:13,000 --> 00:01:17,000 +Now, in this, basically I need two methods. + +34 +00:01:17,000 --> 00:01:21,000 +One to view data and one to add data, okay? + +35 +00:01:21,000 --> 00:01:22,000 +And so, let's say we have the method + +36 +00:01:22,000 --> 00:01:25,000 +which is public void addJob. + +37 +00:01:26,000 --> 00:01:27,000 +That's one of the methods we have. + +38 +00:01:27,000 --> 00:01:31,000 +And then, we'll need one more, which is public, + +39 +00:01:31,000 --> 00:01:34,000 +which will return the least of job posts, + +40 +00:01:34,000 --> 00:01:37,000 +not just one with the least of job posts. + +41 +00:01:37,000 --> 00:01:38,000 +We have to input the package. + +42 +00:01:39,000 --> 00:01:43,000 +And let's say this is get all jobs. + +43 +00:01:43,000 --> 00:01:44,000 +Again, this method doesn't matter, + +44 +00:01:44,000 --> 00:01:46,000 +but let's say we have get all jobs. + +45 +00:01:46,000 --> 00:01:49,000 +And here I want to return a list, right? + +46 +00:01:49,000 --> 00:01:51,000 +Now, basically this job of service is + +47 +00:01:51,000 --> 00:01:52,000 +to do any processing, + +48 +00:01:52,000 --> 00:01:55,000 +but what if you want to fetch data from somewhere, + +49 +00:01:55,000 --> 00:01:57,000 +maybe database or some other server? + +50 +00:01:57,000 --> 00:02:00,000 +In that case, it's not the job of service layer. + +51 +00:02:00,000 --> 00:02:02,000 +So here, we have to use one more class + +52 +00:02:02,000 --> 00:02:04,000 +or one more layer which is your repository. + +53 +00:02:04,000 --> 00:02:06,000 +So we'll just right click here + +54 +00:02:06,000 --> 00:02:09,000 +and say class, this is my JobRepo. + +55 +00:02:10,000 --> 00:02:12,000 +And then this should be in different package. + +56 +00:02:12,000 --> 00:02:16,000 +This should be in say, let's say .repo package. + +57 +00:02:16,000 --> 00:02:19,000 +And, of course, I have to move this to a repo package. + +58 +00:02:19,000 --> 00:02:21,000 +I will just say, move and click. + +59 +00:02:21,000 --> 00:02:23,000 +So you can see we have different classes + +60 +00:02:23,000 --> 00:02:23,000 +in different packages now. + +61 +00:02:23,000 --> 00:02:26,000 +We got one in model which is job post. + +62 +00:02:26,000 --> 00:02:28,000 +We got repo which is job repo. + +63 +00:02:28,000 --> 00:02:30,000 +And then we got job service. + +64 +00:02:30,000 --> 00:02:32,000 +Now, it is a job of the job repo, + +65 +00:02:32,000 --> 00:02:34,000 +basically to have the elements. + +66 +00:02:34,000 --> 00:02:36,000 +Of course, I'm not using the database here, + +67 +00:02:36,000 --> 00:02:39,000 +so we'll have all my data in this part class. okay? + +68 +00:02:39,000 --> 00:02:42,000 +So maybe we can say this is mocking, + +69 +00:02:42,000 --> 00:02:44,000 +like actual database, but yeah, + +70 +00:02:44,000 --> 00:02:45,000 +so that's what you wanna do here. + +71 +00:02:45,000 --> 00:02:46,000 +So what do we need here? + +72 +00:02:46,000 --> 00:02:47,000 +So basically, I need a method + +73 +00:02:47,000 --> 00:02:50,000 +which will return the list of jobs. + +74 +00:02:50,000 --> 00:02:54,000 +I will say public list of job post. + +75 +00:02:54,000 --> 00:02:57,000 +And we have to import the package for list as well, + +76 +00:02:57,000 --> 00:02:58,000 +so I will do that. + +77 +00:02:58,000 --> 00:03:01,000 +And then here, I will say this is getAllJobs. + +78 +00:03:03,000 --> 00:03:05,000 +Now, basically, we have to return the data. + +79 +00:03:05,000 --> 00:03:07,000 +Now, the way I can return that data is + +80 +00:03:07,000 --> 00:03:09,000 +with the help of array list, okay? + +81 +00:03:09,000 --> 00:03:12,000 +So as I mentioned, I will be having some demo data here. + +82 +00:03:12,000 --> 00:03:17,000 +And so, for that, I have to create a list of job post. + +83 +00:03:17,000 --> 00:03:20,000 +Let's say, I will say this is jobs equal to, + +84 +00:03:20,000 --> 00:03:22,000 +and I want to create a data. + +85 +00:03:22,000 --> 00:03:24,000 +I mean, of course, we want dummy data here. + +86 +00:03:24,000 --> 00:03:27,000 +And the way I can get that is let me just paste the code. + +87 +00:03:27,000 --> 00:03:30,000 +I don't want to type the entire demo data. + +88 +00:03:30,000 --> 00:03:33,000 +So basically, I have to create a new array list + +89 +00:03:33,000 --> 00:03:36,000 +and then I'm adding all this data into an array + +90 +00:03:36,000 --> 00:03:38,000 +and give it to the array list. + +91 +00:03:38,000 --> 00:03:41,000 +If you remember when I started with the video, + +92 +00:03:41,000 --> 00:03:42,000 +something was not working, right? + +93 +00:03:42,000 --> 00:03:45,000 +So I made one mistake when I was trying + +94 +00:03:45,000 --> 00:03:48,000 +to add the data in the array, I missed this part. + +95 +00:03:48,000 --> 00:03:51,000 +So what I was doing is I was directly using this syntax. + +96 +00:03:51,000 --> 00:03:54,000 +This works, but then this will make your list immutable. + +97 +00:03:54,000 --> 00:03:55,000 +I want a mutable string, + +98 +00:03:55,000 --> 00:03:58,000 +so for that, we have to use a new array list. + +99 +00:03:58,000 --> 00:04:00,000 +Okay, so we got the data here. + +100 +00:04:00,000 --> 00:04:03,000 +Here we just have to do one thing, just return the jobs, + +101 +00:04:03,000 --> 00:04:06,000 +our job is done, right? + +102 +00:04:06,000 --> 00:04:09,000 +And then we need one more to add the job. + +103 +00:04:09,000 --> 00:04:11,000 +So I will say public void addJob, + +104 +00:04:13,000 --> 00:04:15,000 +and this will accept a job object. + +105 +00:04:15,000 --> 00:04:17,000 +So I will say JobPost job, + +106 +00:04:17,000 --> 00:04:20,000 +and this will add the job in the list. + +107 +00:04:20,000 --> 00:04:21,000 +So whatever jobs you have, inside that, + +108 +00:04:21,000 --> 00:04:23,000 +you'll be adding one more. + +109 +00:04:23,000 --> 00:04:27,000 +So we'll say jobs.add the job. + +110 +00:04:28,000 --> 00:04:30,000 +That's it. These are the two methods we need. + +111 +00:04:30,000 --> 00:04:34,000 +So let's say, in future, if you want to use a database, + +112 +00:04:34,000 --> 00:04:37,000 +you will only change this class. + +113 +00:04:37,000 --> 00:04:39,000 +Other classes will have no idea what you're doing, okay? + +114 +00:04:39,000 --> 00:04:41,000 +So this class is responsible to fetch data from database + +115 +00:04:41,000 --> 00:04:45,000 +or some other server or maybe from a file for that matter. + +116 +00:04:45,000 --> 00:04:47,000 +We got this class. Let's go back to service. + +117 +00:04:47,000 --> 00:04:49,000 +Now, what service will do is service needs + +118 +00:04:49,000 --> 00:04:51,000 +an object of job posts. + +119 +00:04:51,000 --> 00:04:53,000 +I will say not this one + +120 +00:04:53,000 --> 00:04:56,000 +or JobService, not job post with a service. + +121 +00:04:57,000 --> 00:05:01,000 +And then using this object, I can basically say service dot. + +122 +00:05:01,000 --> 00:05:03,000 +But of course, when you want to add, + +123 +00:05:03,000 --> 00:05:07,000 +you have to also accept the JobPost here, right? + +124 +00:05:08,000 --> 00:05:11,000 +So that means someone who is calling this method + +125 +00:05:11,000 --> 00:05:14,000 +should also send, so add the job controller. + +126 +00:05:14,000 --> 00:05:15,000 +When you're calling this service, + +127 +00:05:15,000 --> 00:05:17,000 +we have to pass this object of job post. + +128 +00:05:17,000 --> 00:05:22,000 +So this object is getting passed from controller to service. + +129 +00:05:22,000 --> 00:05:25,000 +From service, it will go to the repo. + +130 +00:05:25,000 --> 00:05:27,000 +So we say addJob, jobPost. + +131 +00:05:27,000 --> 00:05:29,000 +So now, from the service, it's going to repo. + +132 +00:05:29,000 --> 00:05:31,000 +Repo is accepting it. + +133 +00:05:31,000 --> 00:05:34,000 +Now, this kind of objects are called DTO + +134 +00:05:34,000 --> 00:05:36,000 +which is data transfer objects, okay? + +135 +00:05:36,000 --> 00:05:39,000 +Because they're getting transfer between different layers. + +136 +00:05:39,000 --> 00:05:41,000 +Okay, so just from this point, + +137 +00:05:41,000 --> 00:05:43,000 +because we are going to use this later, + +138 +00:05:43,000 --> 00:05:46,000 +DTO, data transfer object. + +139 +00:05:46,000 --> 00:05:50,000 +So let's go back here. We got a job controller in this. + +140 +00:05:50,000 --> 00:05:52,000 +We have to pass this data, right? + +141 +00:05:53,000 --> 00:05:55,000 +But then we are not getting object of service here, right? + +142 +00:05:55,000 --> 00:05:57,000 +We are just declaring it. + +143 +00:05:57,000 --> 00:05:59,000 +So what we can do is, since we are using spring, + +144 +00:05:59,000 --> 00:06:01,000 +so we can simply say Autowired, + +145 +00:06:01,000 --> 00:06:03,000 +but for that, we have to also make sure, + +146 +00:06:03,000 --> 00:06:05,000 +okay, there's some problem. + +147 +00:06:05,000 --> 00:06:09,000 +Yeah, in the job repo, we are saying this is okay, + +148 +00:06:09,000 --> 00:06:11,000 +what annotation we have to use? + +149 +00:06:11,000 --> 00:06:13,000 +For database, we are going to use, + +150 +00:06:13,000 --> 00:06:15,000 +for the layer which works with database, + +151 +00:06:15,000 --> 00:06:18,000 +we use repository annotation. + +152 +00:06:18,000 --> 00:06:19,000 +Service also works here. + +153 +00:06:19,000 --> 00:06:23,000 +Component also works, but then repository makes sense. + +154 +00:06:23,000 --> 00:06:24,000 +In service, we have an issue. + +155 +00:06:24,000 --> 00:06:29,000 +We have to return, so it's a return service.getAllJobs. + +156 +00:06:32,000 --> 00:06:35,000 +Okay, so this is done, service layer is done + +157 +00:06:35,000 --> 00:06:36,000 +because we are, what we are doing in service layer + +158 +00:06:36,000 --> 00:06:40,000 +is just send data to the repo layer + +159 +00:06:40,000 --> 00:06:43,000 +and then just get data from the repo layer. + +160 +00:06:43,000 --> 00:06:46,000 +The job controller will get the data and add data. + +161 +00:06:46,000 --> 00:06:48,000 +So when you say you are adding a job, + +162 +00:06:48,000 --> 00:06:50,000 +or we are sending a new request, + +163 +00:06:50,000 --> 00:06:52,000 +we have to make sure that you add that there. + +164 +00:06:52,000 --> 00:06:54,000 +For this, you need object of service here. + +165 +00:06:54,000 --> 00:06:55,000 +So in the controller, normally, + +166 +00:06:55,000 --> 00:06:57,000 +you'll be having the object of service. + +167 +00:06:57,000 --> 00:07:02,000 +So it's a job service and we'll make this private. + +168 +00:07:02,000 --> 00:07:04,000 +And for this, I need Autowired. + +169 +00:07:04,000 --> 00:07:07,000 +Okay, so now, we are doing the wiring between the elements, + +170 +00:07:07,000 --> 00:07:08,000 +between the values. + +171 +00:07:08,000 --> 00:07:11,000 +So basically, controller has a object of service. + +172 +00:07:11,000 --> 00:07:14,000 +Service has the object of, oh, + +173 +00:07:14,000 --> 00:07:16,000 +I made a mistake here, I'm calling the same method. + +174 +00:07:16,000 --> 00:07:19,000 +My bad, it should be repo, not service. + +175 +00:07:19,000 --> 00:07:21,000 +Okay, so controller talking to service, + +176 +00:07:21,000 --> 00:07:22,000 +service talking to repo. + +177 +00:07:22,000 --> 00:07:24,000 +Okay, that's what we are doing here, right? + +178 +00:07:24,000 --> 00:07:27,000 +And now, will this work? + +179 +00:07:27,000 --> 00:07:28,000 +Am I missing something here? + +180 +00:07:28,000 --> 00:07:32,000 +On service, we got @Service. + +181 +00:07:32,000 --> 00:07:34,000 +On repo, we got @Repo. + +182 +00:07:35,000 --> 00:07:36,000 +Everything looks cool. + +183 +00:07:36,000 --> 00:07:37,000 +Let's go to controller. + +184 +00:07:37,000 --> 00:07:41,000 +Looks cool. But then we are not sending data, right? + +185 +00:07:41,000 --> 00:07:46,000 +So we say service.addJob. Let's send the job post. + +186 +00:07:46,000 --> 00:07:46,000 +It should work now. + +187 +00:07:46,000 --> 00:07:48,000 +So we have completed all the layers, + +188 +00:07:48,000 --> 00:07:51,000 +and it should add the data in the list, okay? + +189 +00:07:51,000 --> 00:07:52,000 +But how we are going to verify? + +190 +00:07:52,000 --> 00:07:55,000 +So temporary what I'm gonna do is before, + +191 +00:07:55,000 --> 00:07:59,000 +I mean after adding this, let me also print the entire list. + +192 +00:07:59,000 --> 00:08:04,000 +So I'll print the jobs, so that I will know + +193 +00:08:04,000 --> 00:08:08,000 +it got added in the existing list here, okay? + +194 +00:08:08,000 --> 00:08:09,000 +The last number, the last post right here is five. + +195 +00:08:09,000 --> 00:08:13,000 +Anyway, we are going to use 101. Let's see if that works. + +196 +00:08:13,000 --> 00:08:15,000 +Let's restart this. Okay, server started. + +197 +00:08:15,000 --> 00:08:18,000 +Let's go back to our page. + +198 +00:08:18,000 --> 00:08:20,000 +And I will just go back here a bit. + +199 +00:08:20,000 --> 00:08:22,000 +I don't want to enter this data once again. + +200 +00:08:22,000 --> 00:08:24,000 +So click on submit. Something happened. + +201 +00:08:24,000 --> 00:08:26,000 +You can see we got the page here. + +202 +00:08:26,000 --> 00:08:29,000 +But let's say the output, if you see the output, + +203 +00:08:29,000 --> 00:08:31,000 +we are basically printing everything, right? + +204 +00:08:31,000 --> 00:08:33,000 +So let me just wrap the content. + +205 +00:08:33,000 --> 00:08:37,000 +And if you see the last entry is for 101. + +206 +00:08:37,000 --> 00:08:40,000 +So yes, it came, the data came to the repo layer + +207 +00:08:40,000 --> 00:08:42,000 +and then we are adding that. + +208 +00:08:42,000 --> 00:08:45,000 +So yes, it's there in the list, okay? + +209 +00:08:45,000 --> 00:08:47,000 +But I don't want to view data here. + +210 +00:08:47,000 --> 00:08:49,000 +I want to view the data in the view page. + +211 +00:08:49,000 --> 00:08:51,000 +And we have not done that yet. + +212 +00:08:51,000 --> 00:08:53,000 +So let's see that in the next video. + diff --git a/14 - Building a Project/007 View Data_en.srt b/14 - Building a Project/007 View Data_en.srt new file mode 100644 index 0000000000000000000000000000000000000000..42e9bc5f6fec7aa9564dfba1a5415257c7f01974 --- /dev/null +++ b/14 - Building a Project/007 View Data_en.srt @@ -0,0 +1,468 @@ +1 +00:00:00,000 --> 00:00:03,000 +(bright music) + +2 +00:00:03,000 --> 00:00:05,000 +-: Now it's time to work with the view, okay? + +3 +00:00:05,000 --> 00:00:08,000 +When I say view, I'm saying view all jobs + +4 +00:00:08,000 --> 00:00:10,000 +because that is not working, right? + +5 +00:00:10,000 --> 00:00:12,000 +So example, if I go back here + +6 +00:00:12,000 --> 00:00:14,000 +and if I click on all jobs, nothing is there + +7 +00:00:14,000 --> 00:00:17,000 +because we are not doing that. + +8 +00:00:17,000 --> 00:00:19,000 +It says 404. + +9 +00:00:19,000 --> 00:00:21,000 +To achieve that, we have to go to the controller + +10 +00:00:21,000 --> 00:00:23,000 +and we have to handle the view all + +11 +00:00:23,000 --> 00:00:24,000 +because that's the UL, right? + +12 +00:00:24,000 --> 00:00:26,000 +So if I go back to the UL, + +13 +00:00:26,000 --> 00:00:29,000 +we have to map it to view all jobs. + +14 +00:00:29,000 --> 00:00:32,000 +So let's do that. So let me create a controller here. + +15 +00:00:32,000 --> 00:00:36,000 +So as a public, it should return a string, a page of course. + +16 +00:00:36,000 --> 00:00:39,000 +And then the meta name will be, let's say, view jobs. + +17 +00:00:39,000 --> 00:00:41,000 +And of course we are not accepting anything in the back. + +18 +00:00:41,000 --> 00:00:42,000 +So let's keep it empty. + +19 +00:00:42,000 --> 00:00:44,000 +But we have to do the mapping, right? + +20 +00:00:44,000 --> 00:00:45,000 +So it should guest mapping, as I mentioned, + +21 +00:00:45,000 --> 00:00:47,000 +we will be using Get mapping or post mapping here. + +22 +00:00:47,000 --> 00:00:52,000 +And the URL is view all jobs. + +23 +00:00:52,000 --> 00:00:53,000 +This is a UL, right? Now. + +24 +00:00:53,000 --> 00:00:55,000 +If you go back here, now basically we have + +25 +00:00:55,000 --> 00:00:57,000 +to return all the data, right? + +26 +00:00:57,000 --> 00:00:58,000 +So first of all, it may turn the name of the view. + +27 +00:00:58,000 --> 00:01:00,000 +So the name of the view is view, okay? + +28 +00:01:00,000 --> 00:01:02,000 +What was the name of the view? + +29 +00:01:02,000 --> 00:01:06,000 +So it's view all jobs, right? + +30 +00:01:06,000 --> 00:01:09,000 +But here we don't just want to return the view, right? + +31 +00:01:09,000 --> 00:01:12,000 +Because if you do that, let me just restart the application. + +32 +00:01:12,000 --> 00:01:13,000 +So server started, + +33 +00:01:13,000 --> 00:01:17,000 +and if I click on all jobs, + +34 +00:01:17,000 --> 00:01:20,000 +so you can see we got the view, but not the data. + +35 +00:01:20,000 --> 00:01:23,000 +So the page is coming, but where's the data? + +36 +00:01:23,000 --> 00:01:24,000 +You know why data is not coming? + +37 +00:01:24,000 --> 00:01:26,000 +Because we are not sending data. So how do we do that? + +38 +00:01:26,000 --> 00:01:28,000 +First of all, we have to get the data in a list. + +39 +00:01:28,000 --> 00:01:31,000 +So I will say list of job post, + +40 +00:01:31,000 --> 00:01:33,000 +we have to input the package for list. + +41 +00:01:33,000 --> 00:01:36,000 +And here we'll say jobs equal to, + +42 +00:01:36,000 --> 00:01:38,000 +we have to get this from service, right? + +43 +00:01:38,000 --> 00:01:39,000 +So service will return all the jobs + +44 +00:01:39,000 --> 00:01:41,000 +because we are doing that from the different layers. + +45 +00:01:41,000 --> 00:01:42,000 +In the service also, + +46 +00:01:42,000 --> 00:01:45,000 +we are returning all the jobs. + +47 +00:01:45,000 --> 00:01:47,000 +In the repo also, we are returning all the jobs, right? + +48 +00:01:47,000 --> 00:01:50,000 +If you can see here, but we were not sending the data + +49 +00:01:50,000 --> 00:01:52,000 +to the view and now we have the data, + +50 +00:01:52,000 --> 00:01:54,000 +we just have to send that to the view. + +51 +00:01:54,000 --> 00:01:55,000 +How will you send that? + +52 +00:01:55,000 --> 00:01:56,000 +We have seen this before, right? + +53 +00:01:56,000 --> 00:01:58,000 +We can use a model object here. + +54 +00:01:58,000 --> 00:02:00,000 +So to import the package for Model M, + +55 +00:02:00,000 --> 00:02:04,000 +and then whatever data you have, just add that to the model. + +56 +00:02:04,000 --> 00:02:06,000 +So I would say this is, okay. + +57 +00:02:06,000 --> 00:02:07,000 +Now what should your name, in fact, in the view, + +58 +00:02:07,000 --> 00:02:09,000 +we are already using a name. + +59 +00:02:09,000 --> 00:02:10,000 +So let's use that. + +60 +00:02:10,000 --> 00:02:12,000 +So if you go to view all jobs, + +61 +00:02:12,000 --> 00:02:17,000 +and if you see this is what we are sending there, job posts. + +62 +00:02:17,000 --> 00:02:18,000 +So of course you have to make sure + +63 +00:02:18,000 --> 00:02:20,000 +that you send the same thing. + +64 +00:02:20,000 --> 00:02:23,000 +So it is job posts. + +65 +00:02:23,000 --> 00:02:26,000 +And then we can send jobs. + +66 +00:02:26,000 --> 00:02:28,000 +Of course, this name can be different from this. + +67 +00:02:28,000 --> 00:02:32,000 +And that's why we are using a different name here and done. + +68 +00:02:32,000 --> 00:02:34,000 +I mean this should work. Let's try. + +69 +00:02:34,000 --> 00:02:37,000 +So we shut the application, go back here, + +70 +00:02:37,000 --> 00:02:38,000 +I will go to the homepage first. + +71 +00:02:38,000 --> 00:02:41,000 +So I'm on the homepage. Let's click on all jobs. + +72 +00:02:41,000 --> 00:02:43,000 +And yes, we got the data. + +73 +00:02:43,000 --> 00:02:45,000 +So basically it's all about sending data to the view, right? + +74 +00:02:45,000 --> 00:02:48,000 +View is already designed, you just have to send it. + +75 +00:02:48,000 --> 00:02:52,000 +The beauty is, why I'm not focusing on view here is + +76 +00:02:52,000 --> 00:02:54,000 +because this view will change, right? + +77 +00:02:54,000 --> 00:02:56,000 +In the upcoming sections, we are gonna talk about + +78 +00:02:56,000 --> 00:02:59,000 +how do you connect this with your React. + +79 +00:02:59,000 --> 00:03:01,000 +Now in the React, we'll be having a separate view, right? + +80 +00:03:01,000 --> 00:03:03,000 +A separate front end. + +81 +00:03:03,000 --> 00:03:05,000 +From here we just have to send data + +82 +00:03:05,000 --> 00:03:09,000 +and you'll be amazed to see how many lines of code + +83 +00:03:09,000 --> 00:03:10,000 +you have to change. + +84 +00:03:10,000 --> 00:03:12,000 +I mean, I'm saying in a positive way. + +85 +00:03:12,000 --> 00:03:14,000 +You have to basically work with less lines of code. + +86 +00:03:14,000 --> 00:03:16,000 +I mean you have to change less lines of code + +87 +00:03:16,000 --> 00:03:17,000 +to make it work. + +88 +00:03:17,000 --> 00:03:20,000 +And we'll be using the same project just to achieve that. + +89 +00:03:20,000 --> 00:03:22,000 +Okay, so this view is working, + +90 +00:03:22,000 --> 00:03:24,000 +but then we have to also verify if I add a new job. + +91 +00:03:24,000 --> 00:03:27,000 +Example here we only have five, + +92 +00:03:27,000 --> 00:03:28,000 +but let's say if I add a new job now. + +93 +00:03:29,000 --> 00:03:32,000 +Let's say post is 101, + +94 +00:03:32,000 --> 00:03:36,000 +profile is Java Spring Dev. + +95 +00:03:36,000 --> 00:03:38,000 +Some description, + +96 +00:03:38,000 --> 00:03:40,000 +experience, let's say one year, + +97 +00:03:40,000 --> 00:03:42,000 +person should know Java, JavaScript + +98 +00:03:42,000 --> 00:03:44,000 +and TypeScript also Spring, but I'm not able + +99 +00:03:44,000 --> 00:03:45,000 +to find Spring here. + +100 +00:03:45,000 --> 00:03:47,000 +But let's click on submit. + +101 +00:03:47,000 --> 00:03:49,000 +You can say this is the data we want, right? + +102 +00:03:49,000 --> 00:03:52,000 +But if I click on all jobs now the data should be there + +103 +00:03:52,000 --> 00:03:53,000 +and it it is there. + +104 +00:03:53,000 --> 00:03:55,000 +So a person who is using this application + +105 +00:03:55,000 --> 00:03:58,000 +has no idea if you're even using database, but yes, + +106 +00:03:58,000 --> 00:04:00,000 +the moment you reach out the application, + +107 +00:04:00,000 --> 00:04:01,000 +you will lose everything. + +108 +00:04:01,000 --> 00:04:03,000 +And we don't want that, right? + +109 +00:04:03,000 --> 00:04:05,000 +We want a database layer there. How do we do that? + +110 +00:04:05,000 --> 00:04:07,000 +So we'll see that in the upcoming sessions. + +111 +00:04:07,000 --> 00:04:09,000 +We'll also see how can you have a separate front end + +112 +00:04:09,000 --> 00:04:11,000 +and then this particular server + +113 +00:04:11,000 --> 00:04:13,000 +will only work with the data. + +114 +00:04:13,000 --> 00:04:16,000 +So the client can be anything, a React application, + +115 +00:04:16,000 --> 00:04:18,000 +a mobile application, or any other server. + +116 +00:04:18,000 --> 00:04:21,000 +So we are slowly heading towards that point. + +117 +00:04:21,000 --> 00:04:24,000 +And how do we do it? Let's see in the upcoming videos. + diff --git a/14 - Building a Project/008 Source-Code.url b/14 - Building a Project/008 Source-Code.url new file mode 100644 index 0000000000000000000000000000000000000000..7e04a22f1e5caf33ffb7f668c9099f00c6aa7c14 --- /dev/null +++ b/14 - Building a Project/008 Source-Code.url @@ -0,0 +1,2 @@ +[InternetShortcut] +URL=https://github.com/navinreddy20/spring6-course/tree/main/7%20JobApp-Project \ No newline at end of file diff --git a/14 - Building a Project/008 Summary for Job Webapp_en.srt b/14 - Building a Project/008 Summary for Job Webapp_en.srt new file mode 100644 index 0000000000000000000000000000000000000000..704fc46eec2e398bb65c73382db7d3c5b5be1b56 --- /dev/null +++ b/14 - Building a Project/008 Summary for Job Webapp_en.srt @@ -0,0 +1,348 @@ +1 +00:00:00,000 --> 00:00:03,000 +(soft music) + +2 +00:00:03,000 --> 00:00:05,000 +-: So let's do a quick summary + +3 +00:00:05,000 --> 00:00:06,000 +of whatever we have done. + +4 +00:00:06,000 --> 00:00:07,000 +So basically we have + +5 +00:00:07,000 --> 00:00:08,000 +a project which we are + +6 +00:00:08,000 --> 00:00:10,000 +building for the job portal. + +7 +00:00:10,000 --> 00:00:11,000 +Now this is where you can + +8 +00:00:11,000 --> 00:00:12,000 +add a new job. + +9 +00:00:12,000 --> 00:00:13,000 +If you're an employer, + +10 +00:00:13,000 --> 00:00:14,000 +you can add a new job. + +11 +00:00:14,000 --> 00:00:17,000 +But if you are a employer + +12 +00:00:17,000 --> 00:00:18,000 +and if you're searching for a job, + +13 +00:00:18,000 --> 00:00:19,000 +basically you can click on + +14 +00:00:19,000 --> 00:00:20,000 +view all jobs, and you can search + +15 +00:00:20,000 --> 00:00:21,000 +for the jobs here. + +16 +00:00:21,000 --> 00:00:23,000 +The way we have implemented this is, + +17 +00:00:23,000 --> 00:00:23,000 +we have already have + +18 +00:00:23,000 --> 00:00:25,000 +a lot of views here. + +19 +00:00:25,000 --> 00:00:27,000 +One for add job homepage, + +20 +00:00:27,000 --> 00:00:29,000 +success page if you want to post + +21 +00:00:29,000 --> 00:00:30,000 +a new job. + +22 +00:00:30,000 --> 00:00:31,000 +And then once you post a new job, + +23 +00:00:31,000 --> 00:00:32,000 +you want to see a screen + +24 +00:00:32,000 --> 00:00:33,000 +that is success page. + +25 +00:00:33,000 --> 00:00:35,000 +And then we have View All Jobs. + +26 +00:00:35,000 --> 00:00:36,000 +And to achieve this, + +27 +00:00:36,000 --> 00:00:38,000 +we have a controller here. + +28 +00:00:38,000 --> 00:00:40,000 +So controller is handling different requests. + +29 +00:00:40,000 --> 00:00:42,000 +The first one is for the home. + +30 +00:00:42,000 --> 00:00:43,000 +And this homepage will be called, + +31 +00:00:43,000 --> 00:00:45,000 +if you send a request + +32 +00:00:45,000 --> 00:00:46,000 +for the actual homepage + +33 +00:00:46,000 --> 00:00:48,000 +or slash home, you will... + +34 +00:00:48,000 --> 00:00:50,000 +It'll call the homepage. + +35 +00:00:50,000 --> 00:00:52,000 +For Add Job, we are adding a URL here. + +36 +00:00:52,000 --> 00:00:56,000 +For form, we are having this method here. + +37 +00:00:56,000 --> 00:00:57,000 +But then this is a post mapping, + +38 +00:00:57,000 --> 00:00:58,000 +not the get mapping. + +39 +00:00:58,000 --> 00:00:59,000 +So whatever data send, + +40 +00:00:59,000 --> 00:01:01,000 +you're sending from the form will be + +41 +00:01:01,000 --> 00:01:02,000 +stored in this job post. + +42 +00:01:02,000 --> 00:01:03,000 +We can also use model attribute here, + +43 +00:01:03,000 --> 00:01:05,000 +but not required. + +44 +00:01:05,000 --> 00:01:07,000 +And whatever data you're getting, + +45 +00:01:09,000 --> 00:01:10,000 +you are basically sending to a collection. + +46 +00:01:10,000 --> 00:01:11,000 +Now this collection is getting created in + +47 +00:01:11,000 --> 00:01:13,000 +the reppo. + +48 +00:01:13,000 --> 00:01:16,000 +So if you see we have a reppo layer here, + +49 +00:01:16,000 --> 00:01:18,000 +we are not using database, we are just using a + +50 +00:01:18,000 --> 00:01:19,000 +hard coded list. + +51 +00:01:19,000 --> 00:01:20,000 +And this is basically, + +52 +00:01:20,000 --> 00:01:22,000 +you gonna add the jobs as well. + +53 +00:01:22,000 --> 00:01:24,000 +And that's what we have done. + +54 +00:01:24,000 --> 00:01:25,000 +But we can also convert this + +55 +00:01:25,000 --> 00:01:27,000 +into a database application. + +56 +00:01:27,000 --> 00:01:28,000 +Just connect with database. + +57 +00:01:28,000 --> 00:01:29,000 +In between we have a service layer. + +58 +00:01:29,000 --> 00:01:30,000 +So basically a + +59 +00:01:30,000 --> 00:01:32,000 +client talks to a controller, controller, + +60 +00:01:32,000 --> 00:01:32,000 +talks to our service, + +61 +00:01:32,000 --> 00:01:35,000 +service, talks to reppo, talks + +62 +00:01:35,000 --> 00:01:37,000 +to a database or a file or some other server, + +63 +00:01:37,000 --> 00:01:38,000 +right? + +64 +00:01:38,000 --> 00:01:40,000 +And in the controller we are able to add + +65 +00:01:40,000 --> 00:01:42,000 +that we are able to fetch data. + +66 +00:01:42,000 --> 00:01:45,000 +So when you say view all jobs, you should be able + +67 +00:01:45,000 --> 00:01:46,000 +to view all the jobs. + +68 +00:01:46,000 --> 00:01:47,000 +So that's what you're doing here. + +69 +00:01:47,000 --> 00:01:49,000 +And additionally, + +70 +00:01:49,000 --> 00:01:53,000 +we have used some dependency here for the JSP. + +71 +00:01:53,000 --> 00:01:54,000 +And the moment you remove + +72 +00:01:54,000 --> 00:01:55,000 +JSP from your project, lot + +73 +00:01:55,000 --> 00:01:56,000 +of dependency will go away. + +74 +00:01:56,000 --> 00:01:57,000 +Like, we don't need Jasper, + +75 +00:01:57,000 --> 00:02:00,000 +we don't need this Jakarta, + +76 +00:02:00,000 --> 00:02:01,000 +J-S-P-J-S Steel. + +77 +00:02:01,000 --> 00:02:03,000 +We don't need this from the glass fish. + +78 +00:02:03,000 --> 00:02:05,000 +All this will be removed when you don't have a + +79 +00:02:05,000 --> 00:02:06,000 +JSP in your project. + +80 +00:02:06,000 --> 00:02:07,000 +Okay? Maybe that's the way people are + +81 +00:02:07,000 --> 00:02:09,000 +running away from JSP, + +82 +00:02:09,000 --> 00:02:11,000 +but that, yeah, that's, that's + +83 +00:02:11,000 --> 00:02:13,000 +how things are working out here. + +84 +00:02:13,000 --> 00:02:14,000 +So look at the project, + +85 +00:02:14,000 --> 00:02:16,000 +make sure you do this project by yourself also. + +86 +00:02:16,000 --> 00:02:19,000 +That's important. And that's it. + +87 +00:02:19,000 --> 00:02:20,000 +See you in the next section. + diff --git a/14 - Building a Project/external-links.txt b/14 - Building a Project/external-links.txt new file mode 100644 index 0000000000000000000000000000000000000000..b1506226b4bf5acc1d22066faff59f0d5edc6807 --- /dev/null +++ b/14 - Building a Project/external-links.txt @@ -0,0 +1,6 @@ + +002 Source-Code +https://github.com/navinreddy20/spring6-course/tree/main/7%20JobApp-Project + +008 Source-Code +https://github.com/navinreddy20/spring6-course/tree/main/7%20JobApp-Project diff --git a/15 - REST using Spring Boot/001 Rest using Spring Boot Introduction_en.srt b/15 - REST using Spring Boot/001 Rest using Spring Boot Introduction_en.srt new file mode 100644 index 0000000000000000000000000000000000000000..537f4f137a80725b04514b4de170d59185ca927a --- /dev/null +++ b/15 - REST using Spring Boot/001 Rest using Spring Boot Introduction_en.srt @@ -0,0 +1,508 @@ +1 +00:00:00,000 --> 00:00:03,000 +(gentle music) + +2 +00:00:03,000 --> 00:00:06,000 +-: Welcome to the new section where we're gonna talk about + +3 +00:00:06,000 --> 00:00:09,000 +how do you work with REST API using Spring Boot. + +4 +00:00:09,000 --> 00:00:12,000 +The thing is, whatever we have done till now is + +5 +00:00:12,000 --> 00:00:15,000 +we have built a application, which is for the job + +6 +00:00:15,000 --> 00:00:18,000 +where a user can basically view all the jobs + +7 +00:00:18,000 --> 00:00:21,000 +as an job seeker. + +8 +00:00:21,000 --> 00:00:23,000 +And if you're an employer you can add a job. + +9 +00:00:23,000 --> 00:00:24,000 +And in this section we are going + +10 +00:00:24,000 --> 00:00:28,000 +to focus on the same project but with a different concept. + +11 +00:00:28,000 --> 00:00:30,000 +The thing is, when you build this application, + +12 +00:00:30,000 --> 00:00:32,000 +in the same application, you have everything, + +13 +00:00:32,000 --> 00:00:34,000 +you have a front end and you have a backend. + +14 +00:00:34,000 --> 00:00:37,000 +So we can say this is a full stack application + +15 +00:00:37,000 --> 00:00:40,000 +where you have a front end, backend in one project, right? + +16 +00:00:40,000 --> 00:00:41,000 +And that's what we have done here. + +17 +00:00:41,000 --> 00:00:45,000 +So basically we have controllers for accepting the request. + +18 +00:00:45,000 --> 00:00:48,000 +We have different layers to do some processing, + +19 +00:00:48,000 --> 00:00:49,000 +getting data from database. + +20 +00:00:49,000 --> 00:00:51,000 +Of course we don't have a database, + +21 +00:00:51,000 --> 00:00:53,000 +but we are mocking that we are using a database here. + +22 +00:00:53,000 --> 00:00:56,000 +So this job rapport, we are retaining data, + +23 +00:00:56,000 --> 00:00:59,000 +but we can assume that this is coming from database now. + +24 +00:00:59,000 --> 00:01:02,000 +Okay, but the important thing is we have also created + +25 +00:01:02,000 --> 00:01:04,000 +all these view pages, right? + +26 +00:01:04,000 --> 00:01:06,000 +So we have got JSP pages here. + +27 +00:01:06,000 --> 00:01:09,000 +So every time a client requests for something, + +28 +00:01:09,000 --> 00:01:11,000 +you return a page, right? + +29 +00:01:11,000 --> 00:01:13,000 +See, ultimately you want to return data, + +30 +00:01:13,000 --> 00:01:15,000 +but then you can't simply return any data. + +31 +00:01:15,000 --> 00:01:18,000 +So you have to format that data in a particular format. + +32 +00:01:18,000 --> 00:01:21,000 +So basically you have to do proper formatting for that data. + +33 +00:01:21,000 --> 00:01:23,000 +So you have your page should look beautiful, right? + +34 +00:01:23,000 --> 00:01:25,000 +And that's what we have done here. + +35 +00:01:25,000 --> 00:01:27,000 +Of course, this page is not that beautiful, + +36 +00:01:27,000 --> 00:01:29,000 +but at least as a user, I can use this website, right? + +37 +00:01:29,000 --> 00:01:31,000 +So I can click on this, I can click on this ad, + +38 +00:01:31,000 --> 00:01:35,000 +I can just click on the links here and I will get my data. + +39 +00:01:35,000 --> 00:01:36,000 +But think about this. + +40 +00:01:36,000 --> 00:01:37,000 +See, in the earlier days what we used + +41 +00:01:37,000 --> 00:01:40,000 +to have is we used to have a proper web application + +42 +00:01:40,000 --> 00:01:42,000 +with a front end, with a backend. + +43 +00:01:42,000 --> 00:01:44,000 +And anyone want to use your website + +44 +00:01:44,000 --> 00:01:47,000 +or your web application, they can simply open the browser, + +45 +00:01:47,000 --> 00:01:49,000 +they can go to the page and they can access everything. + +46 +00:01:49,000 --> 00:01:52,000 +But also we have something called mobiles, right? + +47 +00:01:52,000 --> 00:01:55,000 +So nowadays we also use mobiles to achieve the same thing. + +48 +00:01:55,000 --> 00:01:59,000 +Doesn't matter which app you talk about, Facebook, LinkedIn, + +49 +00:01:59,000 --> 00:02:02,000 +maybe you want to check a score for your cricket game, + +50 +00:02:02,000 --> 00:02:04,000 +you have applications. + +51 +00:02:04,000 --> 00:02:06,000 +So that means whatever we do using browsers, + +52 +00:02:06,000 --> 00:02:08,000 +we also have apps for that. + +53 +00:02:08,000 --> 00:02:11,000 +Now, if you're trying to understand this architecture, + +54 +00:02:11,000 --> 00:02:15,000 +let's say for a client, which is your browser-based client, + +55 +00:02:15,000 --> 00:02:16,000 +you are building a server. + +56 +00:02:16,000 --> 00:02:19,000 +Now this server is responsible to return HTML pages + +57 +00:02:19,000 --> 00:02:21,000 +because that's what your browser expect. + +58 +00:02:21,000 --> 00:02:24,000 +On the other hand, you have a mobile phone now. + +59 +00:02:24,000 --> 00:02:26,000 +In the mobile phone, the layout is there. + +60 +00:02:26,000 --> 00:02:30,000 +What you want from this server is just data, right? + +61 +00:02:30,000 --> 00:02:30,000 +Adjacent data. + +62 +00:02:30,000 --> 00:02:32,000 +So that means we have to basically create + +63 +00:02:32,000 --> 00:02:33,000 +two different servers. + +64 +00:02:33,000 --> 00:02:35,000 +One to work with the browsers + +65 +00:02:35,000 --> 00:02:37,000 +because they expect you to give JSP + +66 +00:02:37,000 --> 00:02:39,000 +and second server for the mobile applications + +67 +00:02:39,000 --> 00:02:40,000 +where you can give data. + +68 +00:02:40,000 --> 00:02:41,000 +And not just mobile, + +69 +00:02:41,000 --> 00:02:44,000 +this can be a server as well as, as we discussed before. + +70 +00:02:44,000 --> 00:02:45,000 +Don't you think? + +71 +00:02:45,000 --> 00:02:47,000 +You know, we can create a common server + +72 +00:02:47,000 --> 00:02:51,000 +and this server is not going to return any page. + +73 +00:02:51,000 --> 00:02:53,000 +It'll return just data. + +74 +00:02:53,000 --> 00:02:56,000 +Then you will say, you know, the people who use browsers + +75 +00:02:56,000 --> 00:02:59,000 +or if you want to access the same application using browser, + +76 +00:02:59,000 --> 00:03:02,000 +what you will get is JSON data in the page. + +77 +00:03:02,000 --> 00:03:05,000 +You do not get this UI. How do you work with the UI? + +78 +00:03:05,000 --> 00:03:08,000 +And that's where you build a front end separately, + +79 +00:03:08,000 --> 00:03:10,000 +maybe with the help of React, Angular, + +80 +00:03:10,000 --> 00:03:12,000 +whatever technology you want to use. + +81 +00:03:12,000 --> 00:03:16,000 +So you'll be having a separate UI, which is your front end, + +82 +00:03:16,000 --> 00:03:18,000 +and you'll building a separate backend. + +83 +00:03:18,000 --> 00:03:21,000 +Now the advantage of this is this backend server + +84 +00:03:21,000 --> 00:03:22,000 +will only work with JSON format, + +85 +00:03:22,000 --> 00:03:24,000 +or it can be also XML format. + +86 +00:03:24,000 --> 00:03:26,000 +Because these two are famous formats, + +87 +00:03:26,000 --> 00:03:28,000 +which we use JSON, XML. + +88 +00:03:28,000 --> 00:03:31,000 +Basically if you want to send data from client to server, + +89 +00:03:31,000 --> 00:03:33,000 +you will use JSON format. + +90 +00:03:33,000 --> 00:03:35,000 +If you want to send data from server to client, + +91 +00:03:35,000 --> 00:03:37,000 +you will use adjacent format. + +92 +00:03:37,000 --> 00:03:40,000 +So the communication, the payload is happening with the help + +93 +00:03:40,000 --> 00:03:41,000 +of adjacent data there. + +94 +00:03:41,000 --> 00:03:44,000 +It can be browser, it can be your Android application + +95 +00:03:44,000 --> 00:03:46,000 +or iOS application for that matter. + +96 +00:03:46,000 --> 00:03:47,000 +So how do we achieve this? + +97 +00:03:47,000 --> 00:03:49,000 +How do you return just data from the server? + +98 +00:03:49,000 --> 00:03:53,000 +And that's where we can use something called a REST API. + +99 +00:03:53,000 --> 00:03:57,000 +So we want to build this entire application + +100 +00:03:57,000 --> 00:03:59,000 +where a server will not return a page. + +101 +00:03:59,000 --> 00:04:00,000 +So whatever we are doing here, + +102 +00:04:00,000 --> 00:04:02,000 +all these pages will not be keeping this. + +103 +00:04:02,000 --> 00:04:05,000 +We'll remove all the GSV pages will remove, + +104 +00:04:05,000 --> 00:04:08,000 +I mean the controllers will not return the pages now. + +105 +00:04:08,000 --> 00:04:09,000 +They will return data. + +106 +00:04:09,000 --> 00:04:11,000 +But how do we do that? + +107 +00:04:11,000 --> 00:04:12,000 +And what is REST? + +108 +00:04:12,000 --> 00:04:14,000 +So let's discuss that in the next video, + +109 +00:04:14,000 --> 00:04:16,000 +we'll also focus on the front end part. + +110 +00:04:16,000 --> 00:04:18,000 +So I do have a React front end ready, + +111 +00:04:18,000 --> 00:04:20,000 +which will act as a front end here. + +112 +00:04:20,000 --> 00:04:21,000 +And again, this is not a React course. + +113 +00:04:21,000 --> 00:04:24,000 +I will not teach you each thing in React, + +114 +00:04:24,000 --> 00:04:26,000 +but I will explain the project structure. + +115 +00:04:26,000 --> 00:04:27,000 +You can just get the project, make it run, + +116 +00:04:27,000 --> 00:04:29,000 +and you can connect with it. + +117 +00:04:29,000 --> 00:04:31,000 +And now you will say, Hey, you know, I don't want + +118 +00:04:31,000 --> 00:04:33,000 +to learn front end here. + +119 +00:04:33,000 --> 00:04:36,000 +In that case, how will you test your backend? + +120 +00:04:36,000 --> 00:04:37,000 +How will you know that? + +121 +00:04:37,000 --> 00:04:39,000 +What data you will you are receiving? + +122 +00:04:39,000 --> 00:04:41,000 +How do you send data? + +123 +00:04:41,000 --> 00:04:43,000 +So that's why we have to also use something called + +124 +00:04:43,000 --> 00:04:46,000 +a client, a REST client. + +125 +00:04:46,000 --> 00:04:47,000 +And that REST client is Postman. + +126 +00:04:47,000 --> 00:04:50,000 +We have multiple options, but Postman is famous. + +127 +00:04:50,000 --> 00:04:52,000 +So we'll also see how do we work with postman. + diff --git a/15 - REST using Spring Boot/002 What is REST_en.srt b/15 - REST using Spring Boot/002 What is REST_en.srt new file mode 100644 index 0000000000000000000000000000000000000000..a141427f9fa9b306c195d65e9eb78ee5b0cf988e --- /dev/null +++ b/15 - REST using Spring Boot/002 What is REST_en.srt @@ -0,0 +1,688 @@ +1 +00:00:00,000 --> 00:00:03,000 +(mellow bright music) + +2 +00:00:03,000 --> 00:00:05,000 +-: In this video, we'll talk about REST, + +3 +00:00:05,000 --> 00:00:09,000 +which stands for Representational State Transfer. + +4 +00:00:09,000 --> 00:00:11,000 +See, the thing is, if we talk about a web application, + +5 +00:00:11,000 --> 00:00:14,000 +most of the time, we work with data, right? + +6 +00:00:14,000 --> 00:00:16,000 +Creating data, reading data, + +7 +00:00:16,000 --> 00:00:18,000 +updating data, and deleting data. + +8 +00:00:18,000 --> 00:00:21,000 +We can also call this as a CRUD operation: + +9 +00:00:21,000 --> 00:00:23,000 +create, read, update, and delete. + +10 +00:00:23,000 --> 00:00:26,000 +So what we basically do is you want to create some data + +11 +00:00:26,000 --> 00:00:27,000 +on the server. + +12 +00:00:27,000 --> 00:00:28,000 +You want to get some data. + +13 +00:00:28,000 --> 00:00:30,000 +You want to update some data. + +14 +00:00:30,000 --> 00:00:31,000 +You want to delete some data. + +15 +00:00:31,000 --> 00:00:33,000 +To achieve this, first of all, + +16 +00:00:33,000 --> 00:00:34,000 +we have to consider this data, + +17 +00:00:34,000 --> 00:00:37,000 +which is on the server, as a resource. + +18 +00:00:37,000 --> 00:00:37,000 +I mean, think about this. + +19 +00:00:37,000 --> 00:00:39,000 +Whenever you try to build an application, + +20 +00:00:39,000 --> 00:00:42,000 +you create entities out of it, right? + +21 +00:00:42,000 --> 00:00:43,000 +So let's say if you talk about the job application, + +22 +00:00:43,000 --> 00:00:44,000 +which you are building, + +23 +00:00:44,000 --> 00:00:45,000 +in this job application, + +24 +00:00:45,000 --> 00:00:49,000 +we can think about job itself as one entity, right? + +25 +00:00:49,000 --> 00:00:51,000 +Maybe you can also think about + +26 +00:00:51,000 --> 00:00:53,000 +if you want to maintain the employee details, + +27 +00:00:53,000 --> 00:00:54,000 +which we are not doing, + +28 +00:00:54,000 --> 00:00:55,000 +but let's say if you have employee details, + +29 +00:00:55,000 --> 00:00:57,000 +so employee becomes one entity. + +30 +00:00:57,000 --> 00:00:59,000 +Your job is one entity. + +31 +00:00:59,000 --> 00:01:00,000 +Let's say you have an admin, + +32 +00:01:00,000 --> 00:01:02,000 +so admin becomes one entity. + +33 +00:01:02,000 --> 00:01:04,000 +Let's say you want to also represent some companies there. + +34 +00:01:04,000 --> 00:01:06,000 +So if you're an employer, + +35 +00:01:06,000 --> 00:01:08,000 +first, you have to talk about your own company, + +36 +00:01:08,000 --> 00:01:11,000 +why someone should join your company, right? + +37 +00:01:11,000 --> 00:01:13,000 +So this is your employer profile. + +38 +00:01:13,000 --> 00:01:15,000 +So that's your one entity. + +39 +00:01:15,000 --> 00:01:17,000 +So basically what we have is in your application, + +40 +00:01:17,000 --> 00:01:19,000 +we have different entities. + +41 +00:01:19,000 --> 00:01:21,000 +Each entity you can represent, + +42 +00:01:21,000 --> 00:01:23,000 +you can think about them as a resource, right? + +43 +00:01:23,000 --> 00:01:25,000 +You have a job resource, you have a employee resource, + +44 +00:01:25,000 --> 00:01:28,000 +you have a employer resource. + +45 +00:01:28,000 --> 00:01:30,000 +So what we are doing is we are just working + +46 +00:01:30,000 --> 00:01:32,000 +with a resource here, right? + +47 +00:01:32,000 --> 00:01:35,000 +Now when I say, "I want to add a new job," + +48 +00:01:35,000 --> 00:01:37,000 +now that is one resource, right? + +49 +00:01:37,000 --> 00:01:39,000 +Now, whatever data you have in a server, + +50 +00:01:39,000 --> 00:01:41,000 +of course they will be changing, right? + +51 +00:01:41,000 --> 00:01:43,000 +So let's say if you talk about employee data. + +52 +00:01:43,000 --> 00:01:45,000 +So an employee, + +53 +00:01:45,000 --> 00:01:48,000 +maybe you have a section there which says current employer, + +54 +00:01:48,000 --> 00:01:50,000 +which is null at this point. + +55 +00:01:50,000 --> 00:01:52,000 +And after some time you got a job, + +56 +00:01:52,000 --> 00:01:55,000 +so the current employer will change to something else. + +57 +00:01:55,000 --> 00:01:57,000 +Maybe it'll become Google, Microsoft, + +58 +00:01:57,000 --> 00:01:58,000 +Telusko, doesn't matter. + +59 +00:01:58,000 --> 00:02:01,000 +So what happens is you update those resources, right? + +60 +00:02:01,000 --> 00:02:04,000 +But if you think about a moment, + +61 +00:02:04,000 --> 00:02:06,000 +at this moment, what's the value? + +62 +00:02:06,000 --> 00:02:09,000 +So let's say at this moment, the value is Microsoft. + +63 +00:02:09,000 --> 00:02:11,000 +Maybe after a few months, it becomes Telusko. + +64 +00:02:11,000 --> 00:02:13,000 +After a few months, it's become some other company. + +65 +00:02:13,000 --> 00:02:15,000 +So what we are doing is we are changing, right? + +66 +00:02:15,000 --> 00:02:17,000 +But at a given point, + +67 +00:02:17,000 --> 00:02:20,000 +you got some value that is called a state. + +68 +00:02:20,000 --> 00:02:22,000 +So example, at this point, if I say, + +69 +00:02:22,000 --> 00:02:24,000 +"Hey, give me the data about the employee," + +70 +00:02:24,000 --> 00:02:27,000 +of course, employee will have a name, ID, + +71 +00:02:27,000 --> 00:02:29,000 +or some other details, which will be fixed, right? + +72 +00:02:29,000 --> 00:02:31,000 +You don't change your name often. + +73 +00:02:31,000 --> 00:02:35,000 +You might, but most of the time it is fixed. + +74 +00:02:35,000 --> 00:02:36,000 +You might be having an ID, + +75 +00:02:36,000 --> 00:02:38,000 +which is common for the application, + +76 +00:02:38,000 --> 00:02:38,000 +so it will be fixed. + +77 +00:02:38,000 --> 00:02:40,000 +Maybe you have address as well, + +78 +00:02:40,000 --> 00:02:43,000 +which will not change frequently, but it might. + +79 +00:02:43,000 --> 00:02:44,000 +But what about the employer? + +80 +00:02:44,000 --> 00:02:47,000 +You know, people do switch job every few months nowadays, + +81 +00:02:47,000 --> 00:02:49,000 +so that thing is keep changing, right? + +82 +00:02:49,000 --> 00:02:53,000 +But at a given point, we can call it as a state. + +83 +00:02:53,000 --> 00:02:55,000 +So if you fetch now, you will get a different state. + +84 +00:02:55,000 --> 00:02:58,000 +If you fetch later, you will get a different state. + +85 +00:02:58,000 --> 00:03:01,000 +So what you have to do is you just have to send the state + +86 +00:03:01,000 --> 00:03:02,000 +to the client + +87 +00:03:02,000 --> 00:03:04,000 +because client is asking for data, right? + +88 +00:03:04,000 --> 00:03:06,000 +So client says, "Hey, I want the details + +89 +00:03:06,000 --> 00:03:07,000 +about this employee." + +90 +00:03:07,000 --> 00:03:10,000 +So servers will say, "Okay, let me send the current state," + +91 +00:03:10,000 --> 00:03:12,000 +so the server will send it. + +92 +00:03:12,000 --> 00:03:13,000 +So we are sending a state, + +93 +00:03:13,000 --> 00:03:16,000 +but also we have to send that in a proper format. + +94 +00:03:16,000 --> 00:03:17,000 +So we will say, + +95 +00:03:17,000 --> 00:03:20,000 +"Let's make it a proper presentable thing, + +96 +00:03:20,000 --> 00:03:22,000 +presentational state." + +97 +00:03:22,000 --> 00:03:24,000 +So that is your representational state. + +98 +00:03:24,000 --> 00:03:27,000 +And then we have to also make sure that we are transferring. + +99 +00:03:27,000 --> 00:03:30,000 +So it is transfer, that is REST, right? + +100 +00:03:30,000 --> 00:03:33,000 +So important thing is you are transferring state here. + +101 +00:03:33,000 --> 00:03:35,000 +Also, remember when you talk about REST as architecture, + +102 +00:03:35,000 --> 00:03:38,000 +you have to use it as a stateless, + +103 +00:03:38,000 --> 00:03:40,000 +which means when a client talk to the server + +104 +00:03:40,000 --> 00:03:42,000 +for the first time, + +105 +00:03:42,000 --> 00:03:44,000 +client has to mention all the details, right? + +106 +00:03:44,000 --> 00:03:45,000 +"Hey, I want this data. + +107 +00:03:45,000 --> 00:03:47,000 +Why I want this data because I have this login." + +108 +00:03:47,000 --> 00:03:50,000 +Maybe you have to also implement security there. + +109 +00:03:50,000 --> 00:03:52,000 +But when a client comes for the second time, + +110 +00:03:52,000 --> 00:03:55,000 +you cannot expect from the server that server knows you + +111 +00:03:55,000 --> 00:03:58,000 +because every request is stateless, okay? + +112 +00:03:58,000 --> 00:04:00,000 +So every time you talk to a server, + +113 +00:04:00,000 --> 00:04:01,000 +you have to talk about who you are, + +114 +00:04:01,000 --> 00:04:02,000 +why you're asking for it. + +115 +00:04:02,000 --> 00:04:04,000 +So that's one thing. + +116 +00:04:04,000 --> 00:04:09,000 +Next, in the REST API, we use something called a noun. + +117 +00:04:09,000 --> 00:04:11,000 +So example, if you talk about our code here, + +118 +00:04:11,000 --> 00:04:15,000 +we were using view all jobs, add a job. + +119 +00:04:15,000 --> 00:04:17,000 +So basically we were using actions, right? + +120 +00:04:17,000 --> 00:04:21,000 +So in the URL, we were basically using actions, words. + +121 +00:04:21,000 --> 00:04:24,000 +But now in REST API, you will not be using actions. + +122 +00:04:24,000 --> 00:04:27,000 +We'll be using something called a noun. + +123 +00:04:27,000 --> 00:04:29,000 +Example, let's say if you want details about the jobs, + +124 +00:04:29,000 --> 00:04:30,000 +you can simply say: + +125 +00:04:30,000 --> 00:04:32,000 +localhost:8080/jobs. + +126 +00:04:32,000 --> 00:04:35,000 +If you want to add a job, you will say: + +127 +00:04:35,000 --> 00:04:37,000 +localhost:8080/job. + +128 +00:04:37,000 --> 00:04:40,000 +If you want to get one job, you will say: + +129 +00:04:40,000 --> 00:04:42,000 +localhost:8080/job. + +130 +00:04:42,000 --> 00:04:44,000 +But is it matching with the add job? + +131 +00:04:44,000 --> 00:04:45,000 +How do you differentiate between this two? + +132 +00:04:45,000 --> 00:04:48,000 +Add job also has the same URL, + +133 +00:04:48,000 --> 00:04:50,000 +get job also has the same URL, + +134 +00:04:50,000 --> 00:04:51,000 +how it will work? + +135 +00:04:51,000 --> 00:04:54,000 +So the URL is same, but the methods will change. + +136 +00:04:54,000 --> 00:04:56,000 +Now, which method I'm talking about? + +137 +00:04:56,000 --> 00:04:58,000 +See, REST uses something called HTTP. + +138 +00:04:58,000 --> 00:05:01,000 +And we all know the HTTP is Hyper Text Transfer Protocol, + +139 +00:05:01,000 --> 00:05:04,000 +which are protocol which we use to access the web. + +140 +00:05:04,000 --> 00:05:07,000 +Now in HTTP, we have different methods. + +141 +00:05:07,000 --> 00:05:10,000 +We have a lot of methods, but then few are important, + +142 +00:05:10,000 --> 00:05:13,000 +and let's discuss about those things in the next video. + +143 +00:05:13,000 --> 00:05:15,000 +But if we talk about REST API, + +144 +00:05:15,000 --> 00:05:17,000 +what we deal is we deal with resources. + +145 +00:05:17,000 --> 00:05:20,000 +And what you send data is your states. + +146 +00:05:20,000 --> 00:05:23,000 +You transfer the states from server to client, + +147 +00:05:23,000 --> 00:05:25,000 +or maybe you get a new state from the client to the server. + +148 +00:05:25,000 --> 00:05:28,000 +So the important thing is from our server, + +149 +00:05:28,000 --> 00:05:29,000 +we are not going to return JSP, + +150 +00:05:29,000 --> 00:05:31,000 +we are going to return data, the current state. + +151 +00:05:31,000 --> 00:05:32,000 +Now to represent this, + +152 +00:05:32,000 --> 00:05:34,000 +we have two different formats, which are very famous, + +153 +00:05:34,000 --> 00:05:36,000 +JSON and XML. + +154 +00:05:36,000 --> 00:05:37,000 +XML is a old format. + +155 +00:05:37,000 --> 00:05:40,000 +JSON is a new format because it is easy to read. + +156 +00:05:40,000 --> 00:05:43,000 +It takes less memory to represent the data. + +157 +00:05:43,000 --> 00:05:46,000 +And this is how basically a simple JSON looks like, right? + +158 +00:05:46,000 --> 00:05:48,000 +So this is a JSON data. + +159 +00:05:48,000 --> 00:05:50,000 +And if you want the similar part for the XML, + +160 +00:05:50,000 --> 00:05:51,000 +this is what XML looks like. + +161 +00:05:51,000 --> 00:05:54,000 +Now you decide which one looks better, right? + +162 +00:05:54,000 --> 00:05:56,000 +So JSON looks better than the XML, right? + +163 +00:05:56,000 --> 00:05:58,000 +Now JSON is basically stands + +164 +00:05:58,000 --> 00:06:00,000 +for JavaScript Object Notation. + +165 +00:06:00,000 --> 00:06:02,000 +I know you'll be thinking this is only used + +166 +00:06:02,000 --> 00:06:03,000 +for the JavaScript. + +167 +00:06:03,000 --> 00:06:05,000 +No, this is just a notation, + +168 +00:06:05,000 --> 00:06:07,000 +which came from the JavaScript object. + +169 +00:06:07,000 --> 00:06:10,000 +So we got the name, but we can use this type of data + +170 +00:06:10,000 --> 00:06:12,000 +for any other programming language. + +171 +00:06:12,000 --> 00:06:14,000 +But still we have a question on the HTTP methods. + +172 +00:06:14,000 --> 00:06:16,000 +Let's discuss that in the next video. + diff --git a/15 - REST using Spring Boot/003 Http Methods_en.srt b/15 - REST using Spring Boot/003 Http Methods_en.srt new file mode 100644 index 0000000000000000000000000000000000000000..449a05d3fabce1f4cd065a481cd770c904a2f086 --- /dev/null +++ b/15 - REST using Spring Boot/003 Http Methods_en.srt @@ -0,0 +1,280 @@ +1 +00:00:00,000 --> 00:00:03,000 +(gentle music) + +2 +00:00:03,000 --> 00:00:05,000 +-: So let's talk about H-T-T-P, + +3 +00:00:05,000 --> 00:00:08,000 +which stands for Hypertext Transfer Protocol. + +4 +00:00:08,000 --> 00:00:09,000 +Of course, we are not here to discuss about, + +5 +00:00:09,000 --> 00:00:10,000 +what is a protocol? + +6 +00:00:10,000 --> 00:00:11,000 +We are here to discuss, + +7 +00:00:11,000 --> 00:00:15,000 +what are the methods which we can use to work with HTTP. + +8 +00:00:15,000 --> 00:00:16,000 +See if you remember, + +9 +00:00:16,000 --> 00:00:19,000 +when we were building this application for Job, + +10 +00:00:19,000 --> 00:00:22,000 +we have used two methods: the GET and the POST. + +11 +00:00:22,000 --> 00:00:24,000 +Now, when we want to fetch data from the server, + +12 +00:00:24,000 --> 00:00:26,000 +we use something called a GET request. + +13 +00:00:26,000 --> 00:00:29,000 +So in the CRUD operations, if you want to read something, + +14 +00:00:29,000 --> 00:00:31,000 +we use the GET method. + +15 +00:00:31,000 --> 00:00:33,000 +But what if you want to create a resource? + +16 +00:00:33,000 --> 00:00:36,000 +So you want to send some data from client to server, + +17 +00:00:36,000 --> 00:00:37,000 +which maybe you want to save + +18 +00:00:37,000 --> 00:00:38,000 +that in a database or something. + +19 +00:00:38,000 --> 00:00:40,000 +But if you want to send data, + +20 +00:00:40,000 --> 00:00:43,000 +if you want to create something on the server, we use POST. + +21 +00:00:43,000 --> 00:00:45,000 +So POST is for sending data. + +22 +00:00:45,000 --> 00:00:48,000 +Now, we can also use it for updating data, + +23 +00:00:48,000 --> 00:00:50,000 +but mostly we use POST to create data. + +24 +00:00:50,000 --> 00:00:51,000 +But what if you want to update something? + +25 +00:00:51,000 --> 00:00:54,000 +In that case, you can use PUT. + +26 +00:00:54,000 --> 00:00:56,000 +So you can use PUT request for the updating. + +27 +00:00:56,000 --> 00:00:58,000 +And then we have a DELETE as well, right? + +28 +00:00:58,000 --> 00:01:00,000 +So in the HTTP, we also have a DELETE method. + +29 +00:01:00,000 --> 00:01:02,000 +So just like CRUD, we have DELETE-DELETE, + +30 +00:01:02,000 --> 00:01:05,000 +so we have it the same for the HTTP. + +31 +00:01:05,000 --> 00:01:06,000 +So in HTTP, we have different methods. + +32 +00:01:06,000 --> 00:01:11,000 +The famous four is POST, GET, PUT, and DELETE. + +33 +00:01:11,000 --> 00:01:15,000 +So if you want to use that in the Spring Boot, + +34 +00:01:15,000 --> 00:01:17,000 +we have talked about GetMapping and PostMapping. + +35 +00:01:17,000 --> 00:01:18,000 +What about PUT? + +36 +00:01:18,000 --> 00:01:19,000 +So we have PutMapping. + +37 +00:01:19,000 --> 00:01:21,000 +What if you have DELETE? + +38 +00:01:21,000 --> 00:01:22,000 +You have DeleteMapping. + +39 +00:01:22,000 --> 00:01:24,000 +So now, let's say if we talk about the URL, + +40 +00:01:24,000 --> 00:01:27,000 +which we talked about in the rest, + +41 +00:01:27,000 --> 00:01:29,000 +if you want to add a new job, + +42 +00:01:29,000 --> 00:01:32,000 +you will use your URL /job, right? + +43 +00:01:34,000 --> 00:01:34,000 +That's for create. + +44 +00:01:34,000 --> 00:01:39,000 +If you want to get a particular job, same URL /job. + +45 +00:01:39,000 --> 00:01:40,000 +Both are same. + +46 +00:01:40,000 --> 00:01:42,000 +The difference is the methods. + +47 +00:01:42,000 --> 00:01:44,000 +For the creation of the job, you will use POST. + +48 +00:01:44,000 --> 00:01:47,000 +For the getting the job, you will use GET method. + +49 +00:01:47,000 --> 00:01:48,000 +Two different methods. + +50 +00:01:48,000 --> 00:01:49,000 +So from the client side as well, + +51 +00:01:49,000 --> 00:01:51,000 +you have to mention POST. + +52 +00:01:51,000 --> 00:01:53,000 +On the server side also you have to mention POST. + +53 +00:01:53,000 --> 00:01:54,000 +In the server, we will be using PostMapping. + +54 +00:01:54,000 --> 00:01:55,000 +But the question arises, + +55 +00:01:55,000 --> 00:01:57,000 +how we are going to use these methods? + +56 +00:01:57,000 --> 00:01:58,000 +If we talk about your browser, + +57 +00:01:58,000 --> 00:02:00,000 +in the browser, we do have GET. + +58 +00:02:00,000 --> 00:02:02,000 +So by default, the URL when you use, + +59 +00:02:02,000 --> 00:02:04,000 +it will throw a GET request. + +60 +00:02:04,000 --> 00:02:05,000 +But what about the POST? + +61 +00:02:05,000 --> 00:02:08,000 +To send the POST request, we have to create a Form. + +62 +00:02:08,000 --> 00:02:10,000 +But then what if you don't want to get a form? + +63 +00:02:10,000 --> 00:02:11,000 +What if you want to test it? + +64 +00:02:11,000 --> 00:02:14,000 +So, browser will not be having that option, right? + +65 +00:02:14,000 --> 00:02:16,000 +And that's why we have to look for a client. + +66 +00:02:16,000 --> 00:02:18,000 +And that's where this client can be a React application + +67 +00:02:18,000 --> 00:02:20,000 +or this client can be your testing client, + +68 +00:02:20,000 --> 00:02:22,000 +let's say Postman. + +69 +00:02:22,000 --> 00:02:23,000 +So we'll see, how do we use Postman, + +70 +00:02:23,000 --> 00:02:26,000 +and what we are trying to build here in the next video. + diff --git a/15 - REST using Spring Boot/004 Source-Code.url b/15 - REST using Spring Boot/004 Source-Code.url new file mode 100644 index 0000000000000000000000000000000000000000..7db762151df8db77e9b2cf4ed5497ee142b1350a --- /dev/null +++ b/15 - REST using Spring Boot/004 Source-Code.url @@ -0,0 +1,2 @@ +[InternetShortcut] +URL=https://github.com/navinreddy20/spring6-course/tree/main/React%20UI \ No newline at end of file diff --git a/15 - REST using Spring Boot/004 Understanding the React UI_en.srt b/15 - REST using Spring Boot/004 Understanding the React UI_en.srt new file mode 100644 index 0000000000000000000000000000000000000000..b52e5caf4c506cf904c3fd7cc3239c21534fb762 --- /dev/null +++ b/15 - REST using Spring Boot/004 Understanding the React UI_en.srt @@ -0,0 +1,1092 @@ +1 +00:00:00,000 --> 00:00:03,000 +(upbeat music) + +2 +00:00:03,000 --> 00:00:05,000 +-: So now we have talked about what is rest? + +3 +00:00:05,000 --> 00:00:07,000 +We have talked about different HDP methods. + +4 +00:00:07,000 --> 00:00:10,000 +Now let's start building the application. + +5 +00:00:10,000 --> 00:00:12,000 +But the thing is, before we write the backend, we need + +6 +00:00:12,000 --> 00:00:14,000 +to understand how do we test it in the front end. + +7 +00:00:14,000 --> 00:00:17,000 +Now basically when you talk about real application, + +8 +00:00:17,000 --> 00:00:20,000 +the way we are building this project, we have two things, + +9 +00:00:20,000 --> 00:00:22,000 +the front end and a back end. + +10 +00:00:22,000 --> 00:00:24,000 +I do have a front end ready with me. + +11 +00:00:24,000 --> 00:00:25,000 +Of course not the entire front end. + +12 +00:00:25,000 --> 00:00:28,000 +We are going to build this step by step. + +13 +00:00:28,000 --> 00:00:31,000 +Initially we'll focus on fetching all the job post. + +14 +00:00:31,000 --> 00:00:33,000 +Remember when we talked about the job portal + +15 +00:00:33,000 --> 00:00:36,000 +and then we had two buttons, view all jobs + +16 +00:00:36,000 --> 00:00:39,000 +and then we had the button for add job. + +17 +00:00:39,000 --> 00:00:42,000 +Now when you click on view all job, + +18 +00:00:42,000 --> 00:00:44,000 +basically it'll show you all the requirements + +19 +00:00:44,000 --> 00:00:45,000 +we have, right? + +20 +00:00:45,000 --> 00:00:46,000 +Now here, basically we have + +21 +00:00:46,000 --> 00:00:49,000 +a React application as a front end, + +22 +00:00:49,000 --> 00:00:50,000 +which will show all the jobs. + +23 +00:00:50,000 --> 00:00:53,000 +And I just want to show you the code here. + +24 +00:00:53,000 --> 00:00:54,000 +Of course, we are not here to learn React, + +25 +00:00:54,000 --> 00:00:57,000 +but I will show you the code, what we have done + +26 +00:00:57,000 --> 00:00:58,000 +and how do you run this project. + +27 +00:00:58,000 --> 00:01:01,000 +You will find this project in your resources. + +28 +00:01:01,000 --> 00:01:02,000 +So please download this project. + +29 +00:01:02,000 --> 00:01:05,000 +Now, when you get this project, you can use GitClone + +30 +00:01:05,000 --> 00:01:07,000 +or you can download the zip file, your choice. + +31 +00:01:07,000 --> 00:01:10,000 +Now, when you get this project on your machine, + +32 +00:01:10,000 --> 00:01:11,000 +just open that in VS code and open the terminal + +33 +00:01:11,000 --> 00:01:14,000 +because this is where we will write a code. + +34 +00:01:14,000 --> 00:01:15,000 +But before we run the code or + +35 +00:01:15,000 --> 00:01:18,000 +before we, oh, let's run the code first. + +36 +00:01:18,000 --> 00:01:22,000 +So what I will do is I will, I want to run a server here. + +37 +00:01:22,000 --> 00:01:26,000 +Now since we don't have a backend server to work with this, + +38 +00:01:26,000 --> 00:01:29,000 +so we created something in this page itself, which liked + +39 +00:01:29,000 --> 00:01:30,000 +as a backend, the fake backend. + +40 +00:01:30,000 --> 00:01:33,000 +So what I will do is I will open a new terminal here + +41 +00:01:33,000 --> 00:01:34,000 +and I will pass a command. + +42 +00:01:34,000 --> 00:01:37,000 +So we are going to use a json-server. + +43 +00:01:37,000 --> 00:01:40,000 +Now by default, this will not be available in your machine. + +44 +00:01:40,000 --> 00:01:42,000 +So you have to make sure that you download this. + +45 +00:01:42,000 --> 00:01:46,000 +So you can say NPM install, you can set it globally + +46 +00:01:46,000 --> 00:01:50,000 +and you can download json-server. + +47 +00:01:50,000 --> 00:01:52,000 +So basically when you, when you install this, + +48 +00:01:52,000 --> 00:01:54,000 +you will be having json-server in your machine. + +49 +00:01:54,000 --> 00:01:56,000 +I do have it, I will not run this command. + +50 +00:01:56,000 --> 00:01:58,000 +Now the command which I want to run, to run the json-server, + +51 +00:01:58,000 --> 00:02:01,000 +which is a fake server for us, I would say json-server, + +52 +00:02:01,000 --> 00:02:03,000 +-: -watch. + +53 +00:02:03,000 --> 00:02:05,000 +And then when you say you have a json-server, + +54 +00:02:05,000 --> 00:02:07,000 +you need to have some data, right? + +55 +00:02:07,000 --> 00:02:11,000 +JSON Data, so if you can see we have data db.json here + +56 +00:02:11,000 --> 00:02:13,000 +and that we have some data in the JSON file. + +57 +00:02:13,000 --> 00:02:17,000 +Okay, not lot, we have only three or four. + +58 +00:02:17,000 --> 00:02:18,000 +I can say two IDs similar, + +59 +00:02:18,000 --> 00:02:20,000 +maybe I can just change it to two. + +60 +00:02:21,000 --> 00:02:24,000 +This should be three and four. + +61 +00:02:24,000 --> 00:02:26,000 +So we've got different IDs here, + +62 +00:02:26,000 --> 00:02:28,000 +I will save it some dummy data just to test + +63 +00:02:28,000 --> 00:02:30,000 +if my front end is working properly + +64 +00:02:30,000 --> 00:02:33,000 +and I will say watch, then I will mention the name + +65 +00:02:33,000 --> 00:02:35,000 +of the file, which is db.json, + +66 +00:02:35,000 --> 00:02:38,000 +by default it'll run on port number 3000. + +67 +00:02:38,000 --> 00:02:40,000 +I don't wanna do that because my React application, + +68 +00:02:40,000 --> 00:02:43,000 +the front end will run on port number 3000. + +69 +00:02:43,000 --> 00:02:45,000 +So I want to run this on a different port. + +70 +00:02:45,000 --> 00:02:48,000 +So I will say Port 8,000, any port number will do, + +71 +00:02:48,000 --> 00:02:51,000 +which is which is available, and click on enter. + +72 +00:02:51,000 --> 00:02:53,000 +So it'll make sure that your backend is ready. + +73 +00:02:53,000 --> 00:02:56,000 +So if you want to access any post, you can say we have + +74 +00:02:56,000 --> 00:02:58,000 +a what we call resources here. + +75 +00:02:58,000 --> 00:03:02,000 +Remember in the rest video we have talked about resources. + +76 +00:03:02,000 --> 00:03:05,000 +So if you want to get all the posts here, you have + +77 +00:03:05,000 --> 00:03:08,000 +to hit the URL, which is HTTP colon, localized colon, + +78 +00:03:08,000 --> 00:03:10,000 +8,000 slash posts. + +79 +00:03:10,000 --> 00:03:14,000 +We have to use noun, not get AllPosts or show AllPostss. + +80 +00:03:14,000 --> 00:03:16,000 +You have to say posts, so my backend is running, + +81 +00:03:16,000 --> 00:03:17,000 +the fake backend is running. + +82 +00:03:17,000 --> 00:03:19,000 +Now we have to run the front end. + +83 +00:03:19,000 --> 00:03:21,000 +So I will go back to my original terminal + +84 +00:03:21,000 --> 00:03:25,000 +and here I will run the front end. + +85 +00:03:25,000 --> 00:03:27,000 +First of all, I have to say NPM install + +86 +00:03:27,000 --> 00:03:30,000 +to install all the packages, which will take some time. + +87 +00:03:30,000 --> 00:03:31,000 +So you can see node modules is getting created now. + +88 +00:03:31,000 --> 00:03:34,000 +I'm doing this because when you get the project you will + +89 +00:03:34,000 --> 00:03:35,000 +not get node modules. + +90 +00:03:35,000 --> 00:03:37,000 +So you have to run this command first NPM install. + +91 +00:03:37,000 --> 00:03:40,000 +So if you are new to the world of JavaScript, + +92 +00:03:40,000 --> 00:03:42,000 +basically this is a React application which + +93 +00:03:42,000 --> 00:03:46,000 +behind the scene the language is JavaScript. + +94 +00:03:46,000 --> 00:03:49,000 +And if you want to use any of the feature, basically we have + +95 +00:03:49,000 --> 00:03:50,000 +to install those packages. + +96 +00:03:50,000 --> 00:03:53,000 +Now React itself is a library, so you have to install it. + +97 +00:03:53,000 --> 00:03:55,000 +And where do you find all the required + +98 +00:03:55,000 --> 00:03:58,000 +packages is in package.json. + +99 +00:03:58,000 --> 00:04:01,000 +Now if you try to compare this with Java World, + +100 +00:04:01,000 --> 00:04:03,000 +we got something called Mavin. + +101 +00:04:03,000 --> 00:04:05,000 +In Mavin we mentioned what dependency you need. + +102 +00:04:05,000 --> 00:04:08,000 +In the same way in the world of JavaScript, + +103 +00:04:08,000 --> 00:04:09,000 +we use package.json. + +104 +00:04:09,000 --> 00:04:13,000 +And you can see we need React, here is React. + +105 +00:04:13,000 --> 00:04:13,000 +So basically we need React. + +106 +00:04:13,000 --> 00:04:17,000 +We need react-dom to change the elements of HTML. + +107 +00:04:17,000 --> 00:04:22,000 +We need a router-dom to specify the navigations, + +108 +00:04:22,000 --> 00:04:24,000 +which links to click and what will + +109 +00:04:24,000 --> 00:04:25,000 +happen when you click on that link. + +110 +00:04:25,000 --> 00:04:27,000 +And we also have a jsonserver here, + +111 +00:04:27,000 --> 00:04:30,000 +which is a fake backend, which we are using now. + +112 +00:04:30,000 --> 00:04:32,000 +And yeah, so we have a lot of dependencies + +113 +00:04:32,000 --> 00:04:35,000 +and the version of React I'm using is React 18. + +114 +00:04:35,000 --> 00:04:38,000 +So you have to make sure that you have node installed in + +115 +00:04:38,000 --> 00:04:39,000 +your machine, latest version of Node. + +116 +00:04:39,000 --> 00:04:41,000 +Okay, so I have installed the packages, now it's time + +117 +00:04:41,000 --> 00:04:44,000 +to start the React application. + +118 +00:04:44,000 --> 00:04:45,000 +So I will say NPM start. + +119 +00:04:45,000 --> 00:04:47,000 +Now it'll load the application + +120 +00:04:47,000 --> 00:04:51,000 +and boom, you can see we got this page here. + +121 +00:04:51,000 --> 00:04:53,000 +If you are not able to see this page, + +122 +00:04:53,000 --> 00:04:55,000 +I mean when you run this on your machine, + +123 +00:04:55,000 --> 00:04:58,000 +maybe there's something wrong with the json-server + +124 +00:04:58,000 --> 00:05:00,000 +because if you don't run json-server, + +125 +00:05:00,000 --> 00:05:02,000 +you will get the other here. + +126 +00:05:02,000 --> 00:05:03,000 +That server is not available or something. + +127 +00:05:03,000 --> 00:05:04,000 +So basically you have to make sure that you have + +128 +00:05:04,000 --> 00:05:08,000 +your json-server running and you will get this data here. + +129 +00:05:08,000 --> 00:05:11,000 +But mind you, the data which you are getting here is coming + +130 +00:05:11,000 --> 00:05:14,000 +from the fake server, not from the server, which we're going + +131 +00:05:14,000 --> 00:05:17,000 +to build in Spring Boot, okay? + +132 +00:05:17,000 --> 00:05:19,000 +Which we'll do, in fact we do have this server, + +133 +00:05:19,000 --> 00:05:22,000 +but that is sending the JC pages. + +134 +00:05:22,000 --> 00:05:23,000 +We don't want that, right? + +135 +00:05:23,000 --> 00:05:25,000 +We want our server to send the JSON. + +136 +00:05:25,000 --> 00:05:28,000 +So instead of using this fake database here, we are going + +137 +00:05:28,000 --> 00:05:30,000 +to use our server. + +138 +00:05:30,000 --> 00:05:32,000 +Okay, but this is working, + +139 +00:05:32,000 --> 00:05:34,000 +but let's understand what is happening here. + +140 +00:05:34,000 --> 00:05:37,000 +So the way you work with React is React is simply a library. + +141 +00:05:37,000 --> 00:05:40,000 +So which provides you a feature of component based designing + +142 +00:05:40,000 --> 00:05:43,000 +where you have your HTML page, okay? + +143 +00:05:43,000 --> 00:05:44,000 +So it's not like we are running away from HTML. + +144 +00:05:44,000 --> 00:05:47,000 +The page which you see here is an HTML page. + +145 +00:05:47,000 --> 00:05:49,000 +It's just that all these things which are there + +146 +00:05:49,000 --> 00:05:50,000 +are the components, + +147 +00:05:50,000 --> 00:05:52,000 +this is one of the components, these are the components + +148 +00:05:52,000 --> 00:05:54,000 +and these are reusable components. + +149 +00:05:54,000 --> 00:05:58,000 +So you create a component once and multiple times, okay? + +150 +00:05:58,000 --> 00:05:59,000 +So you can say one glass + +151 +00:05:59,000 --> 00:06:01,000 +and multiple objects in Java world, + +152 +00:06:01,000 --> 00:06:02,000 +that's what we are doing here. + +153 +00:06:02,000 --> 00:06:04,000 +And to achieve that, the main file, + +154 +00:06:04,000 --> 00:06:06,000 +you can see we have a public folder here. + +155 +00:06:06,000 --> 00:06:08,000 +This is the file which is getting displayed. + +156 +00:06:08,000 --> 00:06:10,000 +And if you see there's no content here, + +157 +00:06:10,000 --> 00:06:12,000 +all this thing here is a comment. + +158 +00:06:12,000 --> 00:06:15,000 +So if I remove this, this is your HTML page, okay? + +159 +00:06:15,000 --> 00:06:17,000 +That's the fun part of React. + +160 +00:06:17,000 --> 00:06:20,000 +This is your HTML page, which you can see here, okay? + +161 +00:06:20,000 --> 00:06:22,000 +This is a page which is displayed with the help + +162 +00:06:22,000 --> 00:06:24,000 +of index or HTML. + +163 +00:06:24,000 --> 00:06:25,000 +But how all this content are coming, + +164 +00:06:25,000 --> 00:06:28,000 +we have not specified anything in the deal directory. + +165 +00:06:28,000 --> 00:06:31,000 +You can see div is empty or root tag, so this empty. + +166 +00:06:31,000 --> 00:06:35,000 +So it is happening because of one thing. + +167 +00:06:35,000 --> 00:06:38,000 +So if you see for this index.html, + +168 +00:06:38,000 --> 00:06:40,000 +since we are using React, there is a file. + +169 +00:06:40,000 --> 00:06:44,000 +So if you open SRC, we got something called index.js. + +170 +00:06:44,000 --> 00:06:48,000 +Now this is responsible to change the content of HTML page. + +171 +00:06:48,000 --> 00:06:50,000 +And the way it is doing that is + +172 +00:06:50,000 --> 00:06:51,000 +with the help of this root tag. + +173 +00:06:51,000 --> 00:06:53,000 +So if you can see we have diff, which has ID root. + +174 +00:06:53,000 --> 00:06:56,000 +So whatever you want to change with the help + +175 +00:06:56,000 --> 00:06:57,000 +of dom manipulation, basically you can + +176 +00:06:57,000 --> 00:06:59,000 +or document manipulation, + +177 +00:06:59,000 --> 00:07:01,000 +you can basically change the content of this deal. + +178 +00:07:01,000 --> 00:07:04,000 +It is happening because of this index.js here. + +179 +00:07:04,000 --> 00:07:06,000 +In which if you can see we are getting hold on + +180 +00:07:06,000 --> 00:07:10,000 +our root ID, root tag basically the deal. + +181 +00:07:10,000 --> 00:07:14,000 +And then we are saying root.render. + +182 +00:07:14,000 --> 00:07:17,000 +So basically we are changing the content of the root div + +183 +00:07:17,000 --> 00:07:19,000 +and what we are putting there, we are putting app. + +184 +00:07:19,000 --> 00:07:22,000 +Now this is weird, right, so basically this looks + +185 +00:07:22,000 --> 00:07:24,000 +like HTML tag, but with a capital letter. + +186 +00:07:24,000 --> 00:07:26,000 +So this is not actually HTML, + +187 +00:07:26,000 --> 00:07:31,000 +but we are able to use HTML tags with JavaScript. + +188 +00:07:31,000 --> 00:07:35,000 +Okay, so how it is coming, so why, what is happening here? + +189 +00:07:35,000 --> 00:07:38,000 +And again, I'm not here to teach you React, + +190 +00:07:38,000 --> 00:07:40,000 +I'm just giving you a glimpse of + +191 +00:07:40,000 --> 00:07:42,000 +how React looks like in the upcoming videos. + +192 +00:07:42,000 --> 00:07:43,000 +We're not going to focus much on the UI + +193 +00:07:43,000 --> 00:07:45,000 +but I thought, let me spend some time, + +194 +00:07:45,000 --> 00:07:48,000 +maybe it'll motivate you to learn react more. + +195 +00:07:48,000 --> 00:07:50,000 +So we, we can see we are rendering app here. + +196 +00:07:50,000 --> 00:07:53,000 +Now if you go back to app, what is app? + +197 +00:07:53,000 --> 00:07:55,000 +So if you go to app.js, + +198 +00:07:55,000 --> 00:07:58,000 +what we are doing is we are basically replacing + +199 +00:07:58,000 --> 00:08:01,000 +the root with the app. + +200 +00:08:01,000 --> 00:08:03,000 +And what is app, app is basically + +201 +00:08:03,000 --> 00:08:05,000 +a component, a function component. + +202 +00:08:05,000 --> 00:08:08,000 +That's what you create a component in the React. + +203 +00:08:08,000 --> 00:08:11,000 +We are basically saying that the app will be replaced + +204 +00:08:11,000 --> 00:08:12,000 +by this thing. + +205 +00:08:12,000 --> 00:08:15,000 +Now what is this thing, if you can see we have AllPosts. + +206 +00:08:15,000 --> 00:08:18,000 +So whatever AllPosts will give will be there in the app. + +207 +00:08:18,000 --> 00:08:20,000 +So you can see we are creating a layer of out of layer, + +208 +00:08:20,000 --> 00:08:23,000 +but ultimately it'll just add the data on the page. + +209 +00:08:23,000 --> 00:08:27,000 +But what is AllPosts, go back into components. + +210 +00:08:27,000 --> 00:08:29,000 +We have Allposts here in the AllPosts, + +211 +00:08:29,000 --> 00:08:34,000 +if you can see we are basically hitting a URL, okay? + +212 +00:08:35,000 --> 00:08:37,000 +So we are using axios for that to hit the URL, which is kind + +213 +00:08:37,000 --> 00:08:40,000 +of a fetch in JavaScript. + +214 +00:08:40,000 --> 00:08:44,000 +But what we are doing is we are basically hitting this URL, + +215 +00:08:44,000 --> 00:08:46,000 +which is localized colon 8,000 slash post. + +216 +00:08:46,000 --> 00:08:47,000 +This looks familiar, right? + +217 +00:08:47,000 --> 00:08:51,000 +So what we have done is when you ran the json-server, + +218 +00:08:51,000 --> 00:08:52,000 +we were using this URL. + +219 +00:08:52,000 --> 00:08:54,000 +Now of course this URL will change. + +220 +00:08:54,000 --> 00:08:56,000 +We build this spring application. + +221 +00:08:56,000 --> 00:08:58,000 +Once we have our the backend ready, + +222 +00:08:58,000 --> 00:09:00,000 +it'll have a different port number. + +223 +00:09:00,000 --> 00:09:02,000 +So we'll be updating that here. + +224 +00:09:02,000 --> 00:09:04,000 +But at this point to make it work, + +225 +00:09:04,000 --> 00:09:05,000 +we are using this port number. + +226 +00:09:05,000 --> 00:09:07,000 +So what we are doing is we are + +227 +00:09:07,000 --> 00:09:11,000 +sending this request, it'll return you some data. + +228 +00:09:11,000 --> 00:09:12,000 +And with that data, + +229 +00:09:12,000 --> 00:09:15,000 +if you can see we are running a loop here. + +230 +00:09:15,000 --> 00:09:17,000 +So basically we are using a map. + +231 +00:09:17,000 --> 00:09:19,000 +So all the data which you get in the post, + +232 +00:09:19,000 --> 00:09:20,000 +we are running a map. + +233 +00:09:20,000 --> 00:09:23,000 +And for each element we are fetching + +234 +00:09:23,000 --> 00:09:26,000 +its profile. + +235 +00:09:26,000 --> 00:09:28,000 +We are also fetching its id. + +236 +00:09:28,000 --> 00:09:31,000 +So we are fetching the id, we are fetching the profile. + +237 +00:09:31,000 --> 00:09:33,000 +We are fetching the description. + +238 +00:09:33,000 --> 00:09:34,000 +We are fetching the experience, + +239 +00:09:34,000 --> 00:09:37,000 +we are fetching the technologies. + +240 +00:09:37,000 --> 00:09:39,000 +Now the tech stack itself is added, right? + +241 +00:09:39,000 --> 00:09:40,000 +So it'll be again, map. + +242 +00:09:40,000 --> 00:09:45,000 +And because of this we are able to get this one post here. + +243 +00:09:45,000 --> 00:09:49,000 +So this post is coming because of that one code. + +244 +00:09:49,000 --> 00:09:51,000 +But then this is not happening once, + +245 +00:09:51,000 --> 00:09:53,000 +it is happening multiple times now, depend upon + +246 +00:09:53,000 --> 00:09:55,000 +how much JSON data you have, that many times it'll run + +247 +00:09:55,000 --> 00:09:57,000 +and it'll run, render each component. + +248 +00:09:57,000 --> 00:10:00,000 +And that's why you can see all the components here. + +249 +00:10:00,000 --> 00:10:01,000 +If you have more data, + +250 +00:10:01,000 --> 00:10:04,000 +you will automatically see different data here. + +251 +00:10:04,000 --> 00:10:07,000 +Okay, so that's the beauty of React here. + +252 +00:10:07,000 --> 00:10:09,000 +Again, as I mentioned + +253 +00:10:09,000 --> 00:10:11,000 +before, we are not going to focus more on react in future, + +254 +00:10:11,000 --> 00:10:15,000 +but just to show you the glimpse here, what is happening. + +255 +00:10:15,000 --> 00:10:18,000 +Important is when I give you the project, + +256 +00:10:18,000 --> 00:10:20,000 +I will give you the entire project here. + +257 +00:10:20,000 --> 00:10:22,000 +You just have to run this and you just have + +258 +00:10:22,000 --> 00:10:24,000 +to change a port number, whatever you're using. + +259 +00:10:24,000 --> 00:10:26,000 +But we have one problem. + +260 +00:10:26,000 --> 00:10:28,000 +What if you don't want to build direct application? + +261 +00:10:28,000 --> 00:10:31,000 +What if you want to build for mobile? + +262 +00:10:31,000 --> 00:10:33,000 +Then should we also create a mobile project here + +263 +00:10:33,000 --> 00:10:35,000 +where I will show you, okay, this is + +264 +00:10:35,000 --> 00:10:36,000 +how you create a mobile application. + +265 +00:10:36,000 --> 00:10:38,000 +We can, but then it'll make this course very lengthy, right? + +266 +00:10:38,000 --> 00:10:40,000 +I want you to finish this course, not like you have + +267 +00:10:40,000 --> 00:10:44,000 +to spend your entire four years doing a PhD in this course. + +268 +00:10:44,000 --> 00:10:46,000 +So how do we solve this? + +269 +00:10:46,000 --> 00:10:49,000 +So instead of using React, we have one more choice. + +270 +00:10:49,000 --> 00:10:52,000 +What you can do is instead of using the React application, + +271 +00:10:52,000 --> 00:10:55,000 +you can use a testing client application like Postman + +272 +00:10:55,000 --> 00:10:58,000 +and you can hit the same URL, it'll return data. + +273 +00:10:58,000 --> 00:11:02,000 +But how, that we'll see in the next video. + diff --git a/15 - REST using Spring Boot/005 Working with Postman_en.srt b/15 - REST using Spring Boot/005 Working with Postman_en.srt new file mode 100644 index 0000000000000000000000000000000000000000..2db2da3fccfe8d8e7c71a147b7dd88696aea9f7c --- /dev/null +++ b/15 - REST using Spring Boot/005 Working with Postman_en.srt @@ -0,0 +1,292 @@ +1 +00:00:00,000 --> 00:00:03,000 +(light music) + +2 +00:00:03,000 --> 00:00:05,000 +-: Now, let's see, how do we use Postman. + +3 +00:00:05,000 --> 00:00:07,000 +Basically to get the Postman on your machine, + +4 +00:00:07,000 --> 00:00:08,000 +you can just go to the browser + +5 +00:00:08,000 --> 00:00:10,000 +and search for Postman download. + +6 +00:00:10,000 --> 00:00:12,000 +You can see this is the website. + +7 +00:00:12,000 --> 00:00:14,000 +You can click on this + +8 +00:00:14,000 --> 00:00:17,000 +and based on which version of, which OS you're using, + +9 +00:00:17,000 --> 00:00:20,000 +you can download the software here. + +10 +00:00:20,000 --> 00:00:21,000 +It'll automatically detect which OS you're using + +11 +00:00:21,000 --> 00:00:23,000 +and it will download. + +12 +00:00:23,000 --> 00:00:25,000 +So I'm using Mac that do Apple chips. + +13 +00:00:25,000 --> 00:00:28,000 +I will click on this and it will download the Postman + +14 +00:00:28,000 --> 00:00:31,000 +in my machine and you just have to open it. + +15 +00:00:31,000 --> 00:00:33,000 +Okay? So it's not that difficult. + +16 +00:00:33,000 --> 00:00:36,000 +Now, once you have installed Postman, + +17 +00:00:36,000 --> 00:00:38,000 +I can open Postman on my machine. + +18 +00:00:38,000 --> 00:00:41,000 +This is how the postman looks like. + +19 +00:00:41,000 --> 00:00:42,000 +Now how do you send a request? + +20 +00:00:42,000 --> 00:00:45,000 +Now this is a client, the REST client. + +21 +00:00:45,000 --> 00:00:47,000 +And if you want to send a request, + +22 +00:00:47,000 --> 00:00:50,000 +basically you can see there's an option of plus here. + +23 +00:00:50,000 --> 00:00:51,000 +So click on this. + +24 +00:00:51,000 --> 00:00:53,000 +And you can see there are different options here, + +25 +00:00:53,000 --> 00:00:54,000 +different SJP methods. + +26 +00:00:54,000 --> 00:00:58,000 +We got get, post, put, patch, delete, head, options. + +27 +00:00:58,000 --> 00:01:01,000 +We have seen get, post, put, and delete. + +28 +00:01:01,000 --> 00:01:03,000 +So I'll be sending a get request now. + +29 +00:01:03,000 --> 00:01:05,000 +But what is A URL? + +30 +00:01:05,000 --> 00:01:06,000 +Now we have used the URL before, right? + +31 +00:01:06,000 --> 00:01:08,000 +So if you see the code, + +32 +00:01:08,000 --> 00:01:10,000 +this is the URL, which we're going to use. + +33 +00:01:10,000 --> 00:01:11,000 +So I will just copy this + +34 +00:01:11,000 --> 00:01:14,000 +and paste it here and click on send. + +35 +00:01:14,000 --> 00:01:17,000 +So whatever you can do on React, you can also do it here. + +36 +00:01:17,000 --> 00:01:20,000 +But the only thing is in React you can create a UI. + +37 +00:01:20,000 --> 00:01:23,000 +Here we are not doing that, we are just getting decent data. + +38 +00:01:23,000 --> 00:01:25,000 +Now you will say, what's the use of this? + +39 +00:01:25,000 --> 00:01:29,000 +To test if you are actually sending the right data. + +40 +00:01:29,000 --> 00:01:30,000 +So maybe you have a server, + +41 +00:01:30,000 --> 00:01:32,000 +from the server you're sending Jason data, + +42 +00:01:32,000 --> 00:01:34,000 +you can test it on a Postman. + +43 +00:01:34,000 --> 00:01:35,000 +But you will say, + +44 +00:01:35,000 --> 00:01:38,000 +'Hey, you know I can also do that on my browser'. + +45 +00:01:38,000 --> 00:01:40,000 +So I can just go to the browser, + +46 +00:01:40,000 --> 00:01:42,000 +paste the same link, enter, you get the data, right? + +47 +00:01:42,000 --> 00:01:44,000 +Yes, it works for the GET request. + +48 +00:01:44,000 --> 00:01:46,000 +What about post request? + +49 +00:01:46,000 --> 00:01:48,000 +How will you send a post request from here? + +50 +00:01:48,000 --> 00:01:49,000 +Of course for that you have to get a form + +51 +00:01:49,000 --> 00:01:51,000 +and ultimately we have to get into UI. + +52 +00:01:51,000 --> 00:01:53,000 +We don't have to do that because we have a Postman + +53 +00:01:53,000 --> 00:01:55,000 +where you can send the post request. + +54 +00:01:55,000 --> 00:01:57,000 +So you can click on post + +55 +00:01:57,000 --> 00:01:59,000 +and you can hit the URL, whatever URL you have. + +56 +00:01:59,000 --> 00:02:03,000 +And if you want to send data, there's option of body here. + +57 +00:02:03,000 --> 00:02:05,000 +In this body, you have an option of raw. + +58 +00:02:05,000 --> 00:02:09,000 +Select that and say I want to send adjacent data + +59 +00:02:09,000 --> 00:02:10,000 +and you can put your adjacent data here. + +60 +00:02:10,000 --> 00:02:11,000 +When you click on send, + +61 +00:02:11,000 --> 00:02:14,000 +you are sending the request to the server, + +62 +00:02:14,000 --> 00:02:15,000 +including the data. + +63 +00:02:15,000 --> 00:02:17,000 +That's how we are going to use Postman + +64 +00:02:17,000 --> 00:02:17,000 +in the upcoming video. + +65 +00:02:17,000 --> 00:02:20,000 +So maybe we'll switch between Postman + +66 +00:02:20,000 --> 00:02:23,000 +and React to show you what you can do with this project. + +67 +00:02:23,000 --> 00:02:26,000 +So yeah, that's it from Postman. It's easy to use. + +68 +00:02:26,000 --> 00:02:30,000 +So it's not just the only client available. + +69 +00:02:30,000 --> 00:02:33,000 +We can also use Swagger to see the content. + +70 +00:02:33,000 --> 00:02:35,000 +Maybe in between, also see how do we use swagger. + +71 +00:02:35,000 --> 00:02:38,000 +But yeah, that's the entire idea. + +72 +00:02:38,000 --> 00:02:41,000 +But now we have to actually build the backend. + +73 +00:02:41,000 --> 00:02:42,000 +Let's do that in the next video. + diff --git a/15 - REST using Spring Boot/006 Source-Code.url b/15 - REST using Spring Boot/006 Source-Code.url new file mode 100644 index 0000000000000000000000000000000000000000..6bd0d442afa7ce6bde8adb8cc0bda799c6b74a15 --- /dev/null +++ b/15 - REST using Spring Boot/006 Source-Code.url @@ -0,0 +1,2 @@ +[InternetShortcut] +URL=https://github.com/navinreddy20/spring6-course/tree/36d783117044564847940ba5046b35cc59f55346/9%20REST%20using%20Spring%20Boot/8.6%20Creating%20a%20Rest%20Controller/spring-boot-rest \ No newline at end of file diff --git a/15 - REST using Spring Boot/007 Connecting React and Spring_en.srt b/15 - REST using Spring Boot/007 Connecting React and Spring_en.srt new file mode 100644 index 0000000000000000000000000000000000000000..56379524f8f198b105a8caafd13e906eab245191 --- /dev/null +++ b/15 - REST using Spring Boot/007 Connecting React and Spring_en.srt @@ -0,0 +1,204 @@ +1 +00:00:00,000 --> 00:00:03,000 +(gentle music) + +2 +00:00:03,000 --> 00:00:04,000 +-: So let's try to connect + +3 +00:00:04,000 --> 00:00:06,000 +our React application with the backend. + +4 +00:00:06,000 --> 00:00:09,000 +Now this particular React application which is running, + +5 +00:00:09,000 --> 00:00:13,000 +it is using the data from the mock database, which we had. + +6 +00:00:13,000 --> 00:00:14,000 +Right? DB.json? + +7 +00:00:14,000 --> 00:00:16,000 +And that's why you got this data here. + +8 +00:00:16,000 --> 00:00:17,000 +But this is not what we want. + +9 +00:00:17,000 --> 00:00:20,000 +So what we can do is we can go back to our React application + +10 +00:00:20,000 --> 00:00:23,000 +and we just have to change this particular URL here. + +11 +00:00:23,000 --> 00:00:25,000 +So just paste it. + +12 +00:00:25,000 --> 00:00:27,000 +Our job is done, right? It's so simple. + +13 +00:00:27,000 --> 00:00:31,000 +Let's see if this works. I will just save this. + +14 +00:00:31,000 --> 00:00:34,000 +It has restarted the server. Not sure. + +15 +00:00:34,000 --> 00:00:36,000 +Let me send npm start again. + +16 +00:00:36,000 --> 00:00:38,000 +So this time it'll not hit the same URL + +17 +00:00:38,000 --> 00:00:41,000 +it'll hit different URL, but we got an error. + +18 +00:00:41,000 --> 00:00:45,000 +It says network error. This is not working. + +19 +00:00:45,000 --> 00:00:47,000 +So why is it is not running? + +20 +00:00:47,000 --> 00:00:48,000 +So the problem is with the security, right? + +21 +00:00:48,000 --> 00:00:51,000 +So there's a concept of CrossOrigin. + +22 +00:00:51,000 --> 00:00:52,000 +So they have different origins. + +23 +00:00:52,000 --> 00:00:54,000 +And that's why we have an issue. + +24 +00:00:54,000 --> 00:00:56,000 +To solve this problem, and in fact, + +25 +00:00:56,000 --> 00:00:59,000 +you can read about this more on the search for CrossOrigin. + +26 +00:00:59,000 --> 00:01:00,000 +You'll get the idea. + +27 +00:01:00,000 --> 00:01:04,000 +So basically we have to add one more annotation here + +28 +00:01:04,000 --> 00:01:06,000 +on our controller to allow it. + +29 +00:01:06,000 --> 00:01:09,000 +So you have to say CrossOrigin and in bracket + +30 +00:01:09,000 --> 00:01:13,000 +you have to mention origins and mention the front end port + +31 +00:01:13,000 --> 00:01:15,000 +with the URL, in fact, the entire URL, + +32 +00:01:15,000 --> 00:01:19,000 +which is http://localhost. + +33 +00:01:19,000 --> 00:01:20,000 +So basically you're saying, + +34 +00:01:20,000 --> 00:01:22,000 +"Please allow request from this particular URL," + +35 +00:01:22,000 --> 00:01:24,000 +and that's what we have done here. + +36 +00:01:24,000 --> 00:01:28,000 +Let's refresh or relaunch the application. + +37 +00:01:28,000 --> 00:01:32,000 +Let's go back to our front end and say refresh. + +38 +00:01:32,000 --> 00:01:33,000 +And you got it. + +39 +00:01:33,000 --> 00:01:35,000 +So basically the the React application + +40 +00:01:35,000 --> 00:01:37,000 +is able to get the data from the server + +41 +00:01:37,000 --> 00:01:39,000 +and this is what we had in the server, right? + +42 +00:01:39,000 --> 00:01:40,000 +Five different code. + +43 +00:01:40,000 --> 00:01:41,000 +So that's how basically you connect + +44 +00:01:41,000 --> 00:01:45,000 +your front end and your backend. + +45 +00:01:45,000 --> 00:01:47,000 +So the only thing which was giving us error + +46 +00:01:47,000 --> 00:01:51,000 +is the CrossOrigin and we have solved this with this line. + +47 +00:01:51,000 --> 00:01:52,000 +Cool, so that's how basically you work + +48 +00:01:52,000 --> 00:01:54,000 +with React and backend. + +49 +00:01:54,000 --> 00:01:57,000 +Now we are done with the viewing all post. + +50 +00:01:57,000 --> 00:02:01,000 +Maybe you want to also add a post or create a new job post. + +51 +00:02:01,000 --> 00:02:03,000 +How we do that? Let's see in the next video. + diff --git a/15 - REST using Spring Boot/008 PathVariable_en.srt b/15 - REST using Spring Boot/008 PathVariable_en.srt new file mode 100644 index 0000000000000000000000000000000000000000..54b893e318570fd896238b08d51d7d21ae1683e1 --- /dev/null +++ b/15 - REST using Spring Boot/008 PathVariable_en.srt @@ -0,0 +1,672 @@ +1 +00:00:00,000 --> 00:00:03,000 +(upbeat music) + +2 +00:00:03,000 --> 00:00:04,000 +-: So we are able to get all the jobs + +3 +00:00:04,000 --> 00:00:06,000 +is because of this controller. + +4 +00:00:06,000 --> 00:00:10,000 +So when you hit the request for JobsPosts, + +5 +00:00:10,000 --> 00:00:13,000 +you are getting basically all the jobs here, right? + +6 +00:00:13,000 --> 00:00:15,000 +And the way we are getting that, + +7 +00:00:15,000 --> 00:00:18,000 +if you go back to your Postman, let's hit the query + +8 +00:00:18,000 --> 00:00:21,000 +for localhost.8080/jobposts. + +9 +00:00:21,000 --> 00:00:24,000 +If you click consent in the result, you can see we got, + +10 +00:00:24,000 --> 00:00:27,000 +we are getting all the posts here internal, we got five. + +11 +00:00:27,000 --> 00:00:31,000 +But then what if I just want one, + +12 +00:00:31,000 --> 00:00:33,000 +I don't want all something like, let's say I got, + +13 +00:00:33,000 --> 00:00:37,000 +I want this, so I want to search for a regular post + +14 +00:00:37,000 --> 00:00:40,000 +by the post ID, which is three in this case. + +15 +00:00:40,000 --> 00:00:43,000 +So what I can do is I can come back here on the URL + +16 +00:00:43,000 --> 00:00:46,000 +and I'm not going to search for job posts. + +17 +00:00:46,000 --> 00:00:48,000 +Now I just want to search for one, right? + +18 +00:00:48,000 --> 00:00:51,000 +So it's a job post, that's how you define your URLs. + +19 +00:00:51,000 --> 00:00:55,000 +Or in, when you talk about React, we call them as URI + +20 +00:00:55,000 --> 00:00:58,000 +because they are the uniform resource identifier + +21 +00:00:58,000 --> 00:01:01,000 +because we are identifying a particular resource. + +22 +00:01:01,000 --> 00:01:03,000 +So we can say a job post slash + +23 +00:01:03,000 --> 00:01:05,000 +and then we can give a number, which is three. + +24 +00:01:05,000 --> 00:01:08,000 +So this is how we can basically get this data. + +25 +00:01:08,000 --> 00:01:10,000 +But will it work, of course not. + +26 +00:01:10,000 --> 00:01:12,000 +Which, if you're on this code, you can say, "Hey, it says + +27 +00:01:12,000 --> 00:01:16,000 +this particular request is 404, not found, + +28 +00:01:16,000 --> 00:01:18,000 +basically is not able to find the path". + +29 +00:01:18,000 --> 00:01:21,000 +You know why, because we don't have a controller for that. + +30 +00:01:21,000 --> 00:01:23,000 +So what we have to do is we have to get a controller here. + +31 +00:01:23,000 --> 00:01:26,000 +So I would say public, which will return one job + +32 +00:01:26,000 --> 00:01:27,000 +post not all. + +33 +00:01:27,000 --> 00:01:29,000 +So it'll not be at least it'll be a single one + +34 +00:01:29,000 --> 00:01:33,000 +because the post ID is a unique number or unique field. + +35 +00:01:33,000 --> 00:01:36,000 +So it of course you will get only one and I will say get job + +36 +00:01:36,000 --> 00:01:38,000 +because we just want one. + +37 +00:01:38,000 --> 00:01:41,000 +And then here we have to do the mapping as well. + +38 +00:01:41,000 --> 00:01:42,000 +So I will say get mapping + +39 +00:01:42,000 --> 00:01:47,000 +and this will be for job post, not all jobs, just one. + +40 +00:01:47,000 --> 00:01:49,000 +And then we can simply return the value. + +41 +00:01:49,000 --> 00:01:52,000 +But then how you going to get the value? + +42 +00:01:52,000 --> 00:01:55,000 +See, the thing is we have different job posts, right? + +43 +00:01:55,000 --> 00:01:57,000 +I mean we have different jobs and every job has an ID + +44 +00:01:57,000 --> 00:02:00,000 +and that ID, we are even passing in the URL. + +45 +00:02:00,000 --> 00:02:02,000 +So you can see we are passing three here. + +46 +00:02:02,000 --> 00:02:05,000 +How will you accept three here, that's a question, right? + +47 +00:02:05,000 --> 00:02:07,000 +At this point what I will do is I will hardcode the value + +48 +00:02:07,000 --> 00:02:11,000 +three and then I'm going to send a request to service. + +49 +00:02:11,000 --> 00:02:14,000 +I would say service.get.Job. + +50 +00:02:14,000 --> 00:02:17,000 +And in bracket you have to pass the ID. + +51 +00:02:17,000 --> 00:02:20,000 +Again, I, at this point, I will hardcore the value as three. + +52 +00:02:20,000 --> 00:02:22,000 +And then we'll see how do you get the value dynamically. + +53 +00:02:22,000 --> 00:02:24,000 +But unfortunately in our service class, + +54 +00:02:24,000 --> 00:02:25,000 +we don't have this method. + +55 +00:02:25,000 --> 00:02:27,000 +So I can simply click here + +56 +00:02:27,000 --> 00:02:30,000 +and say, "Hey, generate a method for me by accepting INT + +57 +00:02:30,000 --> 00:02:31,000 +and return the value". + +58 +00:02:31,000 --> 00:02:34,000 +But then even service don't have a value, right? + +59 +00:02:34,000 --> 00:02:36,000 +So we have to ask it from the repo, + +60 +00:02:36,000 --> 00:02:37,000 +so I would say repo.getJob, + +61 +00:02:39,000 --> 00:02:42,000 +even repo is not having this method. + +62 +00:02:42,000 --> 00:02:46,000 +So let me create one, I would say create a method. + +63 +00:02:46,000 --> 00:02:48,000 +But then how will you get the post here? + +64 +00:02:48,000 --> 00:02:51,000 +See, the thing is, it is repo's responsibility + +65 +00:02:51,000 --> 00:02:52,000 +to return data, right? + +66 +00:02:52,000 --> 00:02:53,000 +But then the data is there in the list now. + +67 +00:02:53,000 --> 00:02:56,000 +So how will you get this data, which is three? + +68 +00:02:56,000 --> 00:02:58,000 +Because that's what I'm asking for, right? + +69 +00:02:58,000 --> 00:03:01,000 +The way you can do that is you can, first of all, you have + +70 +00:03:01,000 --> 00:03:03,000 +to iterate to the elements. + +71 +00:03:03,000 --> 00:03:06,000 +I will say, first of all, I will return null here + +72 +00:03:06,000 --> 00:03:08,000 +and then I will say four. + +73 +00:03:08,000 --> 00:03:10,000 +Let me iterate between all the post, + +74 +00:03:10,000 --> 00:03:12,000 +because we have a list of elements. + +75 +00:03:12,000 --> 00:03:16,000 +So I'll say job post, I will say post colon. + +76 +00:03:16,000 --> 00:03:20,000 +And I'm going to fetch this from job. + +77 +00:03:20,000 --> 00:03:23,000 +The method name is jobs or maybe I will say job, + +78 +00:03:23,000 --> 00:03:24,000 +not job post. + +79 +00:03:24,000 --> 00:03:26,000 +So job, okay. + +80 +00:03:26,000 --> 00:03:29,000 +And then once I iterate, I have to check each post ID. + +81 +00:03:29,000 --> 00:03:34,000 +So I will say if the job dot get post ID, if it is matching + +82 +00:03:34,000 --> 00:03:37,000 +with whatever data you're sending here. + +83 +00:03:37,000 --> 00:03:40,000 +So of course we have to send the value I here + +84 +00:03:40,000 --> 00:03:43,000 +and we have to accept the number. + +85 +00:03:43,000 --> 00:03:45,000 +So we can say I + +86 +00:03:45,000 --> 00:03:47,000 +or any other variable if you want, you know, + +87 +00:03:47,000 --> 00:03:49,000 +I should be saying post ID. + +88 +00:03:49,000 --> 00:03:52,000 +That makes much more sense instead of I. + +89 +00:03:52,000 --> 00:03:55,000 +So I would say post ID, post ID, use proper names. + +90 +00:03:55,000 --> 00:03:57,000 +That makes, that makes your life easy. + +91 +00:03:57,000 --> 00:04:00,000 +So here, we'll try to match it with the post ID. + +92 +00:04:00,000 --> 00:04:05,000 +If it is matching, I will return the job. + +93 +00:04:05,000 --> 00:04:07,000 +It's that simple, if it is not matching with any + +94 +00:04:07,000 --> 00:04:09,000 +of the post, it'll return null. + +95 +00:04:09,000 --> 00:04:13,000 +Okay, so that's what we want to give here, okay. + +96 +00:04:13,000 --> 00:04:15,000 +And what do you think, will it work? + +97 +00:04:15,000 --> 00:04:17,000 +Let's go back to our controller + +98 +00:04:17,000 --> 00:04:19,000 +because it should work in the repo. + +99 +00:04:19,000 --> 00:04:21,000 +We have to go back to the controller. + +100 +00:04:21,000 --> 00:04:23,000 +And the question is, will it send, let's try it out. + +101 +00:04:23,000 --> 00:04:25,000 +So what I'll do is I'll relaunch the application + +102 +00:04:25,000 --> 00:04:28,000 +because I have made some changes and go back to Postman. + +103 +00:04:28,000 --> 00:04:31,000 +And this time let's hit, and you can see we call the data. + +104 +00:04:31,000 --> 00:04:34,000 +So this, yes, we are getting this post three. + +105 +00:04:34,000 --> 00:04:35,000 +But then what if you send two + +106 +00:04:35,000 --> 00:04:38,000 +and if you click on send, you can say it says not found. + +107 +00:04:38,000 --> 00:04:41,000 +You know why, because we are hard coding. + +108 +00:04:41,000 --> 00:04:44,000 +The value here, it'll only search for three. + +109 +00:04:44,000 --> 00:04:46,000 +I mean the UI should be three. + +110 +00:04:46,000 --> 00:04:47,000 +Of course this should be dynamic, right? + +111 +00:04:47,000 --> 00:04:51,000 +The way you do that is by putting that in a curly bracket. + +112 +00:04:51,000 --> 00:04:52,000 +So you have to use a curly bracket + +113 +00:04:52,000 --> 00:04:55,000 +and say post, + +114 +00:04:55,000 --> 00:04:57,000 +I mean whatever video variable you want to use here. + +115 +00:04:57,000 --> 00:05:01,000 +And then you have to accept that value there. + +116 +00:05:01,000 --> 00:05:06,000 +So it's a post ID, and here we'll accept the post ID. + +117 +00:05:06,000 --> 00:05:08,000 +And the same ID you are going to send here. + +118 +00:05:08,000 --> 00:05:10,000 +So what we are doing is in the URL, + +119 +00:05:10,000 --> 00:05:12,000 +whatever value you're sending, we are accepting + +120 +00:05:12,000 --> 00:05:15,000 +that in this little variable + +121 +00:05:15,000 --> 00:05:17,000 +and then we are sending it further. + +122 +00:05:17,000 --> 00:05:18,000 +Now, since we are passing in the URL, + +123 +00:05:18,000 --> 00:05:20,000 +we have to use the curly package. + +124 +00:05:20,000 --> 00:05:24,000 +It's not like what we have done before in the query string. + +125 +00:05:24,000 --> 00:05:26,000 +In the query string, we have used request peram. + +126 +00:05:26,000 --> 00:05:28,000 +Here, we have to use this curly brackets. + +127 +00:05:28,000 --> 00:05:31,000 +But then will this work, no, you know, we have + +128 +00:05:31,000 --> 00:05:34,000 +to use one annotation here called path variable. + +129 +00:05:34,000 --> 00:05:37,000 +So when we use path variable here, then it'll check + +130 +00:05:37,000 --> 00:05:38,000 +for the path and it'll try + +131 +00:05:38,000 --> 00:05:40,000 +to find this particular curly bracket. + +132 +00:05:40,000 --> 00:05:43,000 +Okay, and you can also mention the variable name + +133 +00:05:43,000 --> 00:05:45,000 +if you want, you can mention which variable + +134 +00:05:45,000 --> 00:05:46,000 +you are going to target. + +135 +00:05:46,000 --> 00:05:49,000 +So I will say post ID example, let's say if you have more, + +136 +00:05:49,000 --> 00:05:51,000 +so you have to post ID slash maybe you want + +137 +00:05:51,000 --> 00:05:53,000 +to specify something else. + +138 +00:05:53,000 --> 00:05:55,000 +Maybe I'll say something, and if you want + +139 +00:05:55,000 --> 00:05:57,000 +to accept this in two different variables, then you have + +140 +00:05:57,000 --> 00:05:59,000 +to provide the names, post ID, + +141 +00:05:59,000 --> 00:06:01,000 +something, something like that. + +142 +00:06:01,000 --> 00:06:04,000 +Oh, that's, anyway, + +143 +00:06:04,000 --> 00:06:06,000 +but then if you just have one variable, + +144 +00:06:06,000 --> 00:06:09,000 +you can skip this part if you have the same name. + +145 +00:06:09,000 --> 00:06:10,000 +But let's see if this works now. + +146 +00:06:10,000 --> 00:06:12,000 +So I will just relaunch this. + +147 +00:06:12,000 --> 00:06:16,000 +Go back to my Postman and let's hit the third one first. + +148 +00:06:16,000 --> 00:06:19,000 +Third post, okay, so I not started yet. + +149 +00:06:19,000 --> 00:06:20,000 +So I started, we got three. + +150 +00:06:20,000 --> 00:06:25,000 +If I say two and we got two, if I say 10, + +151 +00:06:25,000 --> 00:06:28,000 +because that's the last post we have. + +152 +00:06:28,000 --> 00:06:32,000 +Do we have 10 now, let me verify repo. + +153 +00:06:32,000 --> 00:06:34,000 +Oh, sorry, we only have five, so I will say five. + +154 +00:06:34,000 --> 00:06:35,000 +And you can see we got five. + +155 +00:06:35,000 --> 00:06:37,000 +But yes, if you don't have a value, then you will get null + +156 +00:06:37,000 --> 00:06:39,000 +because you have not got anything. + +157 +00:06:39,000 --> 00:06:42,000 +So that's how basically you can request + +158 +00:06:42,000 --> 00:06:44,000 +for one particular thing. + +159 +00:06:44,000 --> 00:06:46,000 +So important thing is, in this video we have talked + +160 +00:06:46,000 --> 00:06:48,000 +about the path variable. + +161 +00:06:48,000 --> 00:06:50,000 +So if you want to accept a particular variable + +162 +00:06:50,000 --> 00:06:52,000 +or one value, you can use path variable. + +163 +00:06:52,000 --> 00:06:54,000 +In the next video, let's try to discuss + +164 +00:06:54,000 --> 00:06:56,000 +how do you send a data, + +165 +00:06:56,000 --> 00:06:58,000 +because till this point we are just + +166 +00:06:58,000 --> 00:06:59,000 +fetching data from the server. + +167 +00:06:59,000 --> 00:07:00,000 +How do you send data to the server? + +168 +00:07:00,000 --> 00:07:03,000 +Let's talk about that in the next video. + diff --git a/15 - REST using Spring Boot/008 Source-Code.url b/15 - REST using Spring Boot/008 Source-Code.url new file mode 100644 index 0000000000000000000000000000000000000000..a161099b2d867a9ed36899d6195f6998f2f70355 --- /dev/null +++ b/15 - REST using Spring Boot/008 Source-Code.url @@ -0,0 +1,2 @@ +[InternetShortcut] +URL=https://github.com/navinreddy20/spring6-course/tree/36d783117044564847940ba5046b35cc59f55346/9%20REST%20using%20Spring%20Boot/8.8%20PathVariable/spring-boot-rest \ No newline at end of file diff --git a/15 - REST using Spring Boot/009 Sending Data and RequestBody_en.srt b/15 - REST using Spring Boot/009 Sending Data and RequestBody_en.srt new file mode 100644 index 0000000000000000000000000000000000000000..63e7b27ee3b33c9e20cceb7bec1dc57fc96a422c --- /dev/null +++ b/15 - REST using Spring Boot/009 Sending Data and RequestBody_en.srt @@ -0,0 +1,572 @@ +1 +00:00:00,000 --> 00:00:03,000 +(upbeat music) + +2 +00:00:03,000 --> 00:00:06,000 +-: So basically, we have created one more controller here + +3 +00:00:06,000 --> 00:00:08,000 +and then we were testing it with Postman, right? + +4 +00:00:08,000 --> 00:00:10,000 +So basically we got a Postman here + +5 +00:00:10,000 --> 00:00:11,000 +and things are working out, + +6 +00:00:11,000 --> 00:00:14,000 +but we can also create a React app for this, right? + +7 +00:00:14,000 --> 00:00:15,000 +So we'll discuss that. + +8 +00:00:15,000 --> 00:00:20,000 +How do you use all this URL in the React application later, + +9 +00:00:20,000 --> 00:00:24,000 +but while learning all these things, let's use Postman + +10 +00:00:24,000 --> 00:00:25,000 +to send the request to the server + +11 +00:00:25,000 --> 00:00:28,000 +and later on we'll see how do you use React there. + +12 +00:00:28,000 --> 00:00:30,000 +Okay, so what we're gonna discuss now is + +13 +00:00:30,000 --> 00:00:32,000 +how do you send data? + +14 +00:00:32,000 --> 00:00:32,000 +Okay? + +15 +00:00:32,000 --> 00:00:35,000 +First of all, what I will do is I will just send a request + +16 +00:00:35,000 --> 00:00:36,000 +for five and let me copy this + +17 +00:00:36,000 --> 00:00:41,000 +because I'm going to reuse this so it's a copy, okay? + +18 +00:00:41,000 --> 00:00:42,000 +Just for my reference. + +19 +00:00:42,000 --> 00:00:46,000 +Now, let's say how do you send data to the server? + +20 +00:00:46,000 --> 00:00:48,000 +Because if you see on the server side, if you go back + +21 +00:00:48,000 --> 00:00:52,000 +to your code in the repo, we do have a method. + +22 +00:00:52,000 --> 00:00:53,000 +Where's the method? + +23 +00:00:53,000 --> 00:00:55,000 +Okay, so we do have a method called add job. + +24 +00:00:55,000 --> 00:00:56,000 +Can you see that? + +25 +00:00:56,000 --> 00:01:00,000 +Which adds the job in the list. + +26 +00:01:00,000 --> 00:01:04,000 +In the service also, we have add job, if you see here, + +27 +00:01:04,000 --> 00:01:05,000 +but in the controller we don't have add job. + +28 +00:01:05,000 --> 00:01:08,000 +So let's create one so that we can send data. + +29 +00:01:08,000 --> 00:01:10,000 +So I'll say public, I don't want to return anything + +30 +00:01:10,000 --> 00:01:12,000 +and I will say add job. + +31 +00:01:12,000 --> 00:01:14,000 +And then we have to do the mapping. + +32 +00:01:14,000 --> 00:01:17,000 +But this time, instead of using get mapping, + +33 +00:01:17,000 --> 00:01:18,000 +we are going to use post mapping + +34 +00:01:18,000 --> 00:01:21,000 +because we are basically submitting some data to the server. + +35 +00:01:21,000 --> 00:01:24,000 +So we'll say post and what will be the URL? + +36 +00:01:24,000 --> 00:01:27,000 +So the URL will be job post but you will say, + +37 +00:01:27,000 --> 00:01:30,000 +"hey, we already have a job post here, right"? + +38 +00:01:30,000 --> 00:01:32,000 +Will it be confused? + +39 +00:01:32,000 --> 00:01:34,000 +See, we do have a same URL, + +40 +00:01:34,000 --> 00:01:35,000 +but then we have a different methods. + +41 +00:01:35,000 --> 00:01:37,000 +We have get mapping and post mapping. + +42 +00:01:37,000 --> 00:01:38,000 +So they are different. + +43 +00:01:38,000 --> 00:01:41,000 +Okay, and then whatever data you will receive, + +44 +00:01:41,000 --> 00:01:43,000 +you will basically say return or not return. + +45 +00:01:43,000 --> 00:01:47,000 +You will basically say service.add job. + +46 +00:01:47,000 --> 00:01:49,000 +Oh, but then when you say add job, + +47 +00:01:49,000 --> 00:01:51,000 +you need that object of job post. + +48 +00:01:51,000 --> 00:01:53,000 +How will you get that object? + +49 +00:01:53,000 --> 00:01:57,000 +So in this bracket I can create the object of job post + +50 +00:01:57,000 --> 00:02:00,000 +and we'll say job post. + +51 +00:02:00,000 --> 00:02:02,000 +And if you remember, we have done something similar + +52 +00:02:02,000 --> 00:02:05,000 +when we talked about Spring MVC, right? + +53 +00:02:05,000 --> 00:02:06,000 +Or Spring Web MVC. + +54 +00:02:06,000 --> 00:02:09,000 +Okay, and then we can pass the job post. + +55 +00:02:09,000 --> 00:02:11,000 +Now question guys, when you send the data, + +56 +00:02:11,000 --> 00:02:15,000 +how exactly this data will be supplied here in this object + +57 +00:02:15,000 --> 00:02:17,000 +because what we are going to send from the client + +58 +00:02:17,000 --> 00:02:21,000 +is the JSON format and that JSON data needs + +59 +00:02:21,000 --> 00:02:23,000 +to get stored in this object. + +60 +00:02:23,000 --> 00:02:28,000 +For this we have to use an annotation called request body. + +61 +00:02:28,000 --> 00:02:30,000 +Now this sounds similar, right? + +62 +00:02:30,000 --> 00:02:32,000 +We have talked about response body before. + +63 +00:02:32,000 --> 00:02:34,000 +When you want to return data, we use response body. + +64 +00:02:34,000 --> 00:02:37,000 +When you want to send data to the server + +65 +00:02:37,000 --> 00:02:39,000 +or as a server, if you want to accept data, + +66 +00:02:39,000 --> 00:02:41,000 +you have to use request body. + +67 +00:02:41,000 --> 00:02:45,000 +So whatever data you are sending in the job post request, + +68 +00:02:45,000 --> 00:02:47,000 +which is post mapping or post request, + +69 +00:02:47,000 --> 00:02:50,000 +that will be stored inside this job post. + +70 +00:02:50,000 --> 00:02:52,000 +But will it work, let's try. + +71 +00:02:52,000 --> 00:02:55,000 +I will relaunch the application and go back to Postman. + +72 +00:02:55,000 --> 00:02:56,000 +First, let's fetch all the records. + +73 +00:02:56,000 --> 00:02:59,000 +I will click on send and you can see it is sending + +74 +00:02:59,000 --> 00:03:01,000 +all the records and last value is five. + +75 +00:03:01,000 --> 00:03:02,000 +I mean the post is five. + +76 +00:03:02,000 --> 00:03:05,000 +What I will do is I will send the request now. + +77 +00:03:05,000 --> 00:03:07,000 +Now what is a UL for? + +78 +00:03:07,000 --> 00:03:09,000 +Send request is your website name, + +79 +00:03:09,000 --> 00:03:13,000 +which is localhost:8080/jobpost. + +80 +00:03:13,000 --> 00:03:16,000 +And then we have to make sure that you send a post request + +81 +00:03:16,000 --> 00:03:17,000 +because we are sending data now, + +82 +00:03:17,000 --> 00:03:20,000 +but also we have to send data. + +83 +00:03:20,000 --> 00:03:22,000 +We are not sending data, how do you send data here? + +84 +00:03:22,000 --> 00:03:25,000 +In that case, you can use a body here. + +85 +00:03:25,000 --> 00:03:27,000 +If you can see we have a body here, select raw + +86 +00:03:27,000 --> 00:03:30,000 +and make sure that you have JSON here + +87 +00:03:30,000 --> 00:03:31,000 +because we're sending JSON data + +88 +00:03:31,000 --> 00:03:33,000 +and then paste your data, whatever you want to send. + +89 +00:03:33,000 --> 00:03:35,000 +And that's why I copy it, why to type all this thing. + +90 +00:03:35,000 --> 00:03:37,000 +But I will change the post study to six. + +91 +00:03:37,000 --> 00:03:41,000 +I'm looking for a iOS developer experience in mobile + +92 +00:03:41,000 --> 00:03:43,000 +development for iOS, not Android. + +93 +00:03:43,000 --> 00:03:48,000 +So I'll delete that and you don't need to know development. + +94 +00:03:48,000 --> 00:03:51,000 +Experience I want is two years and this is my new post. + +95 +00:03:51,000 --> 00:03:54,000 +And the moment I click on send, okay, something happened. + +96 +00:03:54,000 --> 00:03:56,000 +You can see we got 200, okay? + +97 +00:03:56,000 --> 00:04:00,000 +That means we don't have any error, how do you verify this? + +98 +00:04:00,000 --> 00:04:02,000 +It's very simple, just go back + +99 +00:04:02,000 --> 00:04:05,000 +to your job post and say send. + +100 +00:04:05,000 --> 00:04:09,000 +If you can see at the end, if you can see six, it's working. + +101 +00:04:09,000 --> 00:04:12,000 +So basically now we are able to send data to the server. + +102 +00:04:12,000 --> 00:04:14,000 +We are able to get the data from the server. + +103 +00:04:14,000 --> 00:04:17,000 +I know you are waiting for a time where we can connect + +104 +00:04:17,000 --> 00:04:18,000 +with database, but we'll do that later. + +105 +00:04:18,000 --> 00:04:21,000 +But at this point we are able to create a new job + +106 +00:04:21,000 --> 00:04:24,000 +and then this happening because of this annotation called + +107 +00:04:24,000 --> 00:04:27,000 +request body, which is very important. + +108 +00:04:27,000 --> 00:04:28,000 +So yeah, that's it, we now we know + +109 +00:04:28,000 --> 00:04:32,000 +how do you send data from client to server? + +110 +00:04:32,000 --> 00:04:34,000 +One more thing, it's not just you have to, + +111 +00:04:34,000 --> 00:04:38,000 +you can only send, you know the JSON format. + +112 +00:04:38,000 --> 00:04:40,000 +You can also send XML format if you want. + +113 +00:04:40,000 --> 00:04:43,000 +But then for that we have to do some extra stuff. + +114 +00:04:43,000 --> 00:04:45,000 +But at this point we are working with XML. + +115 +00:04:46,000 --> 00:04:49,000 +Also, you can return the object created here if you want. + +116 +00:04:49,000 --> 00:04:52,000 +So because in our code we are saying void, + +117 +00:04:52,000 --> 00:04:56,000 +but it also makes sense to return the job post whatever job + +118 +00:04:56,000 --> 00:04:58,000 +post you have entered there, return the same object, + +119 +00:04:58,000 --> 00:05:00,000 +which will also tell you that yeah, + +120 +00:05:00,000 --> 00:05:02,000 +you have added some new data. + +121 +00:05:02,000 --> 00:05:06,000 +So you can just relaunch it, go back to your Postman, + +122 +00:05:06,000 --> 00:05:09,000 +click on, okay, I wish the server right. + +123 +00:05:09,000 --> 00:05:10,000 +So I have to say send. + +124 +00:05:10,000 --> 00:05:12,000 +And you can see it is coming back again. + +125 +00:05:12,000 --> 00:05:16,000 +Even if you say post request, additionally, + +126 +00:05:16,000 --> 00:05:18,000 +this is not a good way of returning data + +127 +00:05:18,000 --> 00:05:19,000 +because whatever you're accepting, you're returning + +128 +00:05:19,000 --> 00:05:22,000 +that maybe if you can also do, + +129 +00:05:22,000 --> 00:05:24,000 +what you can do is you can send a request, + +130 +00:05:24,000 --> 00:05:29,000 +you can service dot get job and mention the post Id, + +131 +00:05:29,000 --> 00:05:30,000 +which you have entered. + +132 +00:05:30,000 --> 00:05:31,000 +You know, this will make sure that + +133 +00:05:31,000 --> 00:05:34,000 +you have actually stored the data somewhere. + +134 +00:05:34,000 --> 00:05:37,000 +Okay, so because now you are basically adding the object + +135 +00:05:37,000 --> 00:05:39,000 +and then you're fetching the object from the source + +136 +00:05:39,000 --> 00:05:40,000 +where you have saved it. + +137 +00:05:40,000 --> 00:05:44,000 +So now if you relaunch this just for the confirmation, + +138 +00:05:44,000 --> 00:05:47,000 +go back to your postman, hit the send again + +139 +00:05:47,000 --> 00:05:49,000 +and you can see it's coming back. + +140 +00:05:49,000 --> 00:05:51,000 +But this time it's coming from the collection, okay? + +141 +00:05:51,000 --> 00:05:52,000 +Not just whatever you're sending. + +142 +00:05:52,000 --> 00:05:55,000 +So yeah, that's it from this video where we talked about + +143 +00:05:55,000 --> 00:05:57,000 +how do you send it to server. + diff --git a/15 - REST using Spring Boot/009 Source-Code.url b/15 - REST using Spring Boot/009 Source-Code.url new file mode 100644 index 0000000000000000000000000000000000000000..4f15fb7896a8396976b32cc6703829ce9aaf9eec --- /dev/null +++ b/15 - REST using Spring Boot/009 Source-Code.url @@ -0,0 +1,2 @@ +[InternetShortcut] +URL=https://github.com/navinreddy20/spring6-course/tree/36d783117044564847940ba5046b35cc59f55346/9%20REST%20using%20Spring%20Boot/8.9%20Sending%20Data%20and%20RequestBody/spring-boot-rest \ No newline at end of file diff --git a/15 - REST using Spring Boot/010 Put and Delete Mapping_en.srt b/15 - REST using Spring Boot/010 Put and Delete Mapping_en.srt new file mode 100644 index 0000000000000000000000000000000000000000..79382834fb430787061881a08accab973cd880ca --- /dev/null +++ b/15 - REST using Spring Boot/010 Put and Delete Mapping_en.srt @@ -0,0 +1,1248 @@ +1 +00:00:00,000 --> 00:00:03,000 +(bright music) + +2 +00:00:03,000 --> 00:00:04,000 +Instructor: So till this point, + +3 +00:00:04,000 --> 00:00:05,000 +we have talked about the get request + +4 +00:00:05,000 --> 00:00:07,000 +and the post request, right? + +5 +00:00:07,000 --> 00:00:10,000 +So in the Postman, if you see we have done + +6 +00:00:10,000 --> 00:00:12,000 +with the get post, but what about put and delete? + +7 +00:00:12,000 --> 00:00:16,000 +So let's focus on this two in this video. + +8 +00:00:16,000 --> 00:00:17,000 +What I wanna do now is let's say + +9 +00:00:17,000 --> 00:00:20,000 +I want to change a particular object. + +10 +00:00:20,000 --> 00:00:21,000 +Okay? + +11 +00:00:21,000 --> 00:00:22,000 +Now when I say particular object, first of all, + +12 +00:00:22,000 --> 00:00:24,000 +let's do a get request. + +13 +00:00:24,000 --> 00:00:25,000 +Okay? + +14 +00:00:25,000 --> 00:00:27,000 +The server is not running, let's run the server. + +15 +00:00:27,000 --> 00:00:29,000 +So let's restart. + +16 +00:00:29,000 --> 00:00:31,000 +And now let's click on send. + +17 +00:00:31,000 --> 00:00:33,000 +And you can see we got the list of objects here + +18 +00:00:33,000 --> 00:00:35,000 +and what are the ideas we have? + +19 +00:00:35,000 --> 00:00:39,000 +So we got postId one, two, three, four, five. + +20 +00:00:39,000 --> 00:00:41,000 +And now let's say I want to make a change + +21 +00:00:41,000 --> 00:00:43,000 +for the frontend developer. + +22 +00:00:43,000 --> 00:00:44,000 +Now instead of saying frontend developer, let's say, + +23 +00:00:44,000 --> 00:00:48,000 +I want to specifically hire a React developer. + +24 +00:00:48,000 --> 00:00:49,000 +So I want to update this. + +25 +00:00:49,000 --> 00:00:51,000 +So I want to change the profile + +26 +00:00:51,000 --> 00:00:54,000 +from frontend developer to react developer. + +27 +00:00:54,000 --> 00:00:56,000 +Next I want to change the number of experience + +28 +00:00:56,000 --> 00:00:58,000 +to two instead of three. + +29 +00:00:58,000 --> 00:01:01,000 +And I also want to add maybe some other library + +30 +00:01:01,000 --> 00:01:04,000 +or let's not work with the tech stack. + +31 +00:01:04,000 --> 00:01:07,000 +Let's only change this two front developer. + +32 +00:01:07,000 --> 00:01:08,000 +We want to make it React. + +33 +00:01:08,000 --> 00:01:11,000 +And this two, which I mean the React, + +34 +00:01:11,000 --> 00:01:12,000 +require experience from 232. + +35 +00:01:12,000 --> 00:01:13,000 +Okay, how do I do that? + +36 +00:01:13,000 --> 00:01:15,000 +Now first of all, let me copy this data. + +37 +00:01:15,000 --> 00:01:17,000 +So copy done. + +38 +00:01:17,000 --> 00:01:18,000 +Okay, now how do you update? + +39 +00:01:18,000 --> 00:01:19,000 +It's very simple. + +40 +00:01:19,000 --> 00:01:23,000 +You go to the method and change it to put. + +41 +00:01:23,000 --> 00:01:25,000 +Next, we'll change the URL, + +42 +00:01:25,000 --> 00:01:27,000 +we'll keep it to job post only. + +43 +00:01:27,000 --> 00:01:30,000 +And you are thinking, okay, we did job post + +44 +00:01:30,000 --> 00:01:31,000 +for adding the job post + +45 +00:01:31,000 --> 00:01:34,000 +and also we have used job post for the searching + +46 +00:01:34,000 --> 00:01:36,000 +for a particular job, right? + +47 +00:01:36,000 --> 00:01:39,000 +But we can also use job post the same URL for put as well. + +48 +00:01:39,000 --> 00:01:42,000 +What is different is the method. + +49 +00:01:42,000 --> 00:01:43,000 +The method now is put. + +50 +00:01:43,000 --> 00:01:46,000 +Okay, now we are sending a put request. + +51 +00:01:46,000 --> 00:01:48,000 +We are specifying the URL. + +52 +00:01:48,000 --> 00:01:48,000 +What next? + +53 +00:01:48,000 --> 00:01:51,000 +We have to also send the new data, right? + +54 +00:01:51,000 --> 00:01:53,000 +You want to update but with what? + +55 +00:01:53,000 --> 00:01:55,000 +So what I will do is I will go to body + +56 +00:01:55,000 --> 00:01:57,000 +and I would say, okay, let me just take this down. + +57 +00:01:57,000 --> 00:02:00,000 +In this body here, I want to paste this + +58 +00:02:00,000 --> 00:02:01,000 +because that's the data I want to change. + +59 +00:02:01,000 --> 00:02:03,000 +Okay? Not this one, I copied the wrong one. + +60 +00:02:03,000 --> 00:02:05,000 +So basically I want to change this Frontend Developer + +61 +00:02:05,000 --> 00:02:09,000 +and then instead of Frontend, I want to say React. + +62 +00:02:09,000 --> 00:02:10,000 +And then I want to change this as well, + +63 +00:02:10,000 --> 00:02:12,000 +which is required experience to two. + +64 +00:02:12,000 --> 00:02:13,000 +Okay? + +65 +00:02:13,000 --> 00:02:14,000 +If you want, you can change the text stack as well, + +66 +00:02:14,000 --> 00:02:16,000 +but at this point, I'm not able to recall + +67 +00:02:16,000 --> 00:02:18,000 +what extra thing you need for the developer. + +68 +00:02:18,000 --> 00:02:19,000 +So let's keep it there. + +69 +00:02:19,000 --> 00:02:21,000 +Or if you want to change, you can do that. + +70 +00:02:21,000 --> 00:02:22,000 +So I want this. + +71 +00:02:22,000 --> 00:02:24,000 +So what I'll do is I will click on send + +72 +00:02:24,000 --> 00:02:25,000 +and it should update it. + +73 +00:02:26,000 --> 00:02:27,000 +Will it work? + +74 +00:02:27,000 --> 00:02:28,000 +Let's try. + +75 +00:02:28,000 --> 00:02:31,000 +So I will click on send and you can see it's not working. + +76 +00:02:31,000 --> 00:02:31,000 +You know why? + +77 +00:02:31,000 --> 00:02:35,000 +Because we don't have job post with the method put. + +78 +00:02:35,000 --> 00:02:37,000 +So that's why it's not saying 404. + +79 +00:02:37,000 --> 00:02:41,000 +404 means we don't have any working with job post. + +80 +00:02:41,000 --> 00:02:45,000 +We do have it, but we don't have a method which is put,. + +81 +00:02:45,000 --> 00:02:46,000 +Okay? + +82 +00:02:46,000 --> 00:02:46,000 +How do we change that? + +83 +00:02:46,000 --> 00:02:47,000 +It's very simple. + +84 +00:02:47,000 --> 00:02:50,000 +Go to your code and in the controller, + +85 +00:02:50,000 --> 00:02:53,000 +we have to create one more now for the job post. + +86 +00:02:53,000 --> 00:02:55,000 +So I can say public + +87 +00:02:55,000 --> 00:02:56,000 +and I want to return the job post as well. + +88 +00:02:56,000 --> 00:02:59,000 +S I will say job post. + +89 +00:02:59,000 --> 00:03:02,000 +Then instead of saying addJob, we have to say updateJob. + +90 +00:03:02,000 --> 00:03:05,000 +And since we are accepting the object, + +91 +00:03:05,000 --> 00:03:07,000 +so we have to say RequestBody_JobPost. + +92 +00:03:09,000 --> 00:03:11,000 +Let's say I will go for JobPost. + +93 +00:03:11,000 --> 00:03:13,000 +And now how do you update it. + +94 +00:03:13,000 --> 00:03:15,000 +Again, we will controller will not do that. + +95 +00:03:15,000 --> 00:03:17,000 +It's a job of service method. + +96 +00:03:17,000 --> 00:03:19,000 +So it's a service.updateJob. + +97 +00:03:20,000 --> 00:03:22,000 +And of course, we don't have this object yet. + +98 +00:03:22,000 --> 00:03:24,000 +We don't have this method yet, we'll create one. + +99 +00:03:24,000 --> 00:03:26,000 +But before that, we have to also do the mapping. + +100 +00:03:26,000 --> 00:03:27,000 +Now what do you think? + +101 +00:03:27,000 --> 00:03:29,000 +What will the mapping? + +102 +00:03:29,000 --> 00:03:30,000 +You get it right. + +103 +00:03:30,000 --> 00:03:31,000 +It is put mapping. + +104 +00:03:31,000 --> 00:03:35,000 +So for changing, for update, we have to use put mapping. + +105 +00:03:35,000 --> 00:03:38,000 +And in the bracket, we have to specify the URL + +106 +00:03:38,000 --> 00:03:40,000 +or the path, which is the JobPost. + +107 +00:03:40,000 --> 00:03:43,000 +So again, if you observe, post mapping + +108 +00:03:43,000 --> 00:03:44,000 +is also using JobPost, + +109 +00:03:44,000 --> 00:03:46,000 +put mapping was also using JobPost. + +110 +00:03:46,000 --> 00:03:49,000 +The difference is the method, okay? + +111 +00:03:49,000 --> 00:03:52,000 +And that's how basically the REST API works, okay? + +112 +00:03:52,000 --> 00:03:53,000 +But this will not work + +113 +00:03:53,000 --> 00:03:55,000 +is because we don't have the update job + +114 +00:03:55,000 --> 00:03:57,000 +and also we need to return, right? + +115 +00:03:57,000 --> 00:04:01,000 +So a return service.getJob. + +116 +00:04:01,000 --> 00:04:03,000 +Because I want to make sure that whatever we are updating, + +117 +00:04:03,000 --> 00:04:04,000 +we are getting actually getting reflected + +118 +00:04:04,000 --> 00:04:07,000 +in the repository layer. + +119 +00:04:07,000 --> 00:04:10,000 +So it's a jobPost.get postid. + +120 +00:04:10,000 --> 00:04:11,000 +So whatever we are updating, + +121 +00:04:11,000 --> 00:04:13,000 +I just wanna fetch that particular part. + +122 +00:04:13,000 --> 00:04:15,000 +And this is the same line which we have done + +123 +00:04:15,000 --> 00:04:17,000 +in the add, okay? + +124 +00:04:17,000 --> 00:04:19,000 +But now, this update is something I want to create. + +125 +00:04:19,000 --> 00:04:21,000 +So I will say click here. + +126 +00:04:21,000 --> 00:04:22,000 +Create a method update job. + +127 +00:04:22,000 --> 00:04:23,000 +We have done that. + +128 +00:04:23,000 --> 00:04:25,000 +And again, the service is not going + +129 +00:04:25,000 --> 00:04:26,000 +to change anything, right? + +130 +00:04:26,000 --> 00:04:31,000 +It will simply ask the repository to update the job + +131 +00:04:31,000 --> 00:04:35,000 +and we have to send the JobPost, okay? + +132 +00:04:35,000 --> 00:04:37,000 +But again, in the repository, we don't have this. + +133 +00:04:37,000 --> 00:04:40,000 +So till this point, things are a bit simple. + +134 +00:04:40,000 --> 00:04:43,000 +But the moment you create this method in the repo, + +135 +00:04:43,000 --> 00:04:45,000 +this is where you have tried the actual logic. + +136 +00:04:45,000 --> 00:04:47,000 +Now we have to change something. + +137 +00:04:47,000 --> 00:04:49,000 +Even we have done that for the add, right? + +138 +00:04:49,000 --> 00:04:52,000 +We are saying jobs.add, + +139 +00:04:52,000 --> 00:04:53,000 +but then this is not simply adding, + +140 +00:04:53,000 --> 00:04:55,000 +this is basically updating. + +141 +00:04:55,000 --> 00:04:58,000 +So you have a choice, you can basically delete + +142 +00:04:58,000 --> 00:05:00,000 +the earlier entry and that will be very simple, right? + +143 +00:05:00,000 --> 00:05:03,000 +You can simply say job.remove + +144 +00:05:03,000 --> 00:05:06,000 +and you can pass the object, which which you want to remove. + +145 +00:05:06,000 --> 00:05:09,000 +And then, okay, not this one. + +146 +00:05:09,000 --> 00:05:10,000 +No, that's that. + +147 +00:05:10,000 --> 00:05:11,000 +Actually this is tricky. + +148 +00:05:11,000 --> 00:05:14,000 +Because we want to remove based on the ID, right? + +149 +00:05:14,000 --> 00:05:15,000 +So this will not surely work + +150 +00:05:15,000 --> 00:05:17,000 +because of course you can make it work. + +151 +00:05:17,000 --> 00:05:20,000 +We can get the object and remove and add, + +152 +00:05:20,000 --> 00:05:22,000 +but we can also update this by writing some logic. + +153 +00:05:22,000 --> 00:05:24,000 +So first of all, we have to find + +154 +00:05:24,000 --> 00:05:26,000 +the object which we want to update. + +155 +00:05:26,000 --> 00:05:27,000 +So we'll run a loop here. + +156 +00:05:27,000 --> 00:05:29,000 +I will say JobPost JobPost1 : + +157 +00:05:31,000 --> 00:05:35,000 +and I want it to get from jobs + +158 +00:05:35,000 --> 00:05:37,000 +and we'll manually search now each job. + +159 +00:05:37,000 --> 00:05:42,000 +So we'll check if the JobPost1 getPostId + +160 +00:05:44,000 --> 00:05:48,000 +is similar to JobPost.JobPostId. + +161 +00:05:49,000 --> 00:05:50,000 +If this is matching, + +162 +00:05:50,000 --> 00:05:52,000 +then we'll write a code, then we'll update. + +163 +00:05:52,000 --> 00:05:54,000 +Otherwise, we'll not update of course, right? + +164 +00:05:54,000 --> 00:05:55,000 +The job should be there to update. + +165 +00:05:55,000 --> 00:05:56,000 +So what I think you're going to update. + +166 +00:05:56,000 --> 00:06:00,000 +Now, of course, you don't want to check anything + +167 +00:06:00,000 --> 00:06:04,000 +because what if there's no change in the particular field? + +168 +00:06:04,000 --> 00:06:05,000 +Example, we have not changed the description, + +169 +00:06:05,000 --> 00:06:07,000 +we have not changed tech stack. + +170 +00:06:07,000 --> 00:06:09,000 +So we can check, is it different than you change? + +171 +00:06:09,000 --> 00:06:10,000 +Why do you even check? + +172 +00:06:10,000 --> 00:06:13,000 +We can simply say JobPost1.setPostProfile + +173 +00:06:16,000 --> 00:06:19,000 +and we'll get it from the JobPost get profile, + +174 +00:06:19,000 --> 00:06:20,000 +this is the one update. + +175 +00:06:20,000 --> 00:06:22,000 +Then JobPost.setPostDescription, + +176 +00:06:23,000 --> 00:06:24,000 +JobPost.getDescriptio. + +177 +00:06:26,000 --> 00:06:31,000 +Then JobPost set to set experience. + +178 +00:06:31,000 --> 00:06:36,000 +We'll say JobPost.getExperience, tech stack, + +179 +00:06:36,000 --> 00:06:38,000 +JobPost getTechStack. + +180 +00:06:38,000 --> 00:06:41,000 +Now basically, we have changed all the fields. + +181 +00:06:41,000 --> 00:06:43,000 +You don't even have to check each element there, + +182 +00:06:43,000 --> 00:06:46,000 +which will take more time than setting the values, right? + +183 +00:06:46,000 --> 00:06:49,000 +But yes, if you think this is a database operation + +184 +00:06:49,000 --> 00:06:51,000 +and it will hit multiple, you wattle, + +185 +00:06:51,000 --> 00:06:53,000 +you might think about checking the data + +186 +00:06:53,000 --> 00:06:54,000 +before hitting it. + +187 +00:06:54,000 --> 00:06:55,000 +Okay, so this is the change. + +188 +00:06:55,000 --> 00:06:56,000 +These are the changes we have made. + +189 +00:06:56,000 --> 00:06:57,000 +Now what do you think? + +190 +00:06:57,000 --> 00:06:58,000 +Will it work? + +191 +00:06:58,000 --> 00:07:00,000 +It's worth trying, + +192 +00:07:00,000 --> 00:07:03,000 +but you know, let's test, delete, and update together. + +193 +00:07:03,000 --> 00:07:05,000 +So let's also add the code for delete + +194 +00:07:05,000 --> 00:07:07,000 +because maybe I want to write delete as well. + +195 +00:07:07,000 --> 00:07:09,000 +So I will also return this JobPost. + +196 +00:07:11,000 --> 00:07:11,000 +Maybe while deleting, + +197 +00:07:11,000 --> 00:07:16,000 +we can simply return a string if you want. + +198 +00:07:16,000 --> 00:07:18,000 +And I will say delete job. + +199 +00:07:18,000 --> 00:07:20,000 +And of course, when you say delete, now how do we delete it? + +200 +00:07:20,000 --> 00:07:23,000 +So if you go back here to the URL, + +201 +00:07:23,000 --> 00:07:24,000 +if you want to say delete. + +202 +00:07:24,000 --> 00:07:25,000 +So how do we delete? Delete + +203 +00:07:25,000 --> 00:07:28,000 +So in that case, you can simply pass the ID. + +204 +00:07:28,000 --> 00:07:29,000 +So whatever ID you want to delete, + +205 +00:07:29,000 --> 00:07:31,000 +let's attempt, I'm gonna delete the third job + +206 +00:07:31,000 --> 00:07:32,000 +or the ID three. + +207 +00:07:32,000 --> 00:07:35,000 +So you can simply say JobPost/3, + +208 +00:07:35,000 --> 00:07:38,000 +it will delete the third post or third ID + +209 +00:07:38,000 --> 00:07:40,000 +or the object with ID three. + +210 +00:07:40,000 --> 00:07:41,000 +Okay. + +211 +00:07:41,000 --> 00:07:42,000 +So for this we have to make sure + +212 +00:07:42,000 --> 00:07:45,000 +that you are accepting a value + +213 +00:07:45,000 --> 00:07:49,000 +because the URL will be delete mapping + +214 +00:07:49,000 --> 00:07:53,000 +and then we can say JobPost/ we'll accept the id. + +215 +00:07:53,000 --> 00:07:57,000 +So we'll say postId and then we'll accept that here. + +216 +00:07:57,000 --> 00:08:01,000 +And to accept the value from here, + +217 +00:08:01,000 --> 00:08:02,000 +instead of using request body, + +218 +00:08:02,000 --> 00:08:05,000 +we have to use the path variable. + +219 +00:08:05,000 --> 00:08:08,000 +And we'll store that in a variable called post ID. + +220 +00:08:08,000 --> 00:08:09,000 +Now we can write our code for delete. + +221 +00:08:09,000 --> 00:08:11,000 +Of course, we are not going to going to delete it. + +222 +00:08:11,000 --> 00:08:15,000 +We are going to simply say service. DeleteJob + +223 +00:08:18,000 --> 00:08:20,000 +bypassing the ID, which is PostId. + +224 +00:08:20,000 --> 00:08:21,000 +but of course service + +225 +00:08:21,000 --> 00:08:22,000 +and then we have to return something, right? + +226 +00:08:22,000 --> 00:08:24,000 +So I'll say we are not checking + +227 +00:08:24,000 --> 00:08:25,000 +for an exceptions or something here. + +228 +00:08:25,000 --> 00:08:28,000 +I would simply say deleted. + +229 +00:08:28,000 --> 00:08:30,000 +The ideal way is when you delete the value + +230 +00:08:30,000 --> 00:08:33,000 +from the repo layer, it should return something. + +231 +00:08:33,000 --> 00:08:34,000 +Okay? + +232 +00:08:34,000 --> 00:08:35,000 +If it says yes, + +233 +00:08:35,000 --> 00:08:37,000 +then you can accept the value here and return the status. + +234 +00:08:37,000 --> 00:08:39,000 +Depend upon what it is. + +235 +00:08:39,000 --> 00:08:40,000 +But at this point, I'm saying deleted + +236 +00:08:40,000 --> 00:08:43,000 +because I want to return something. + +237 +00:08:43,000 --> 00:08:44,000 +but we don't have this object. + +238 +00:08:44,000 --> 00:08:45,000 +So, or this method. + +239 +00:08:45,000 --> 00:08:46,000 +So we'll create one. + +240 +00:08:46,000 --> 00:08:48,000 +So I'll say create inservice. + +241 +00:08:48,000 --> 00:08:50,000 +In service, also, we are not gonna do anything. + +242 +00:08:50,000 --> 00:08:55,000 +We'll say, Hey repo, delete the job for the id postId. + +243 +00:08:55,000 --> 00:08:57,000 +And now in the repository layer, + +244 +00:08:57,000 --> 00:08:59,000 +we have to say delete again. + +245 +00:08:59,000 --> 00:09:04,000 +So here also we can say jobs, dot, + +246 +00:09:04,000 --> 00:09:05,000 +how are you going to remove? + +247 +00:09:05,000 --> 00:09:07,000 +Because this is not based on the index, right? + +248 +00:09:07,000 --> 00:09:09,000 +If it is based on index, we can simply delete it. + +249 +00:09:09,000 --> 00:09:11,000 +So again, we have to run a follow loop here + +250 +00:09:11,000 --> 00:09:14,000 +because we are not sure which one, which job to delete. + +251 +00:09:14,000 --> 00:09:17,000 +So we'll say JobPost JobPost : job, + +252 +00:09:17,000 --> 00:09:19,000 +and we'll compare the postId. + +253 +00:09:19,000 --> 00:09:21,000 +So we'll say JobPost. + +254 +00:09:21,000 --> 00:09:24,000 +I mean if the JobPost.getID + +255 +00:09:24,000 --> 00:09:28,000 +is matching with the post ID, + +256 +00:09:28,000 --> 00:09:30,000 +then we can simply delete it. + +257 +00:09:30,000 --> 00:09:32,000 +So it's say jobs dot, how do we delete? + +258 +00:09:32,000 --> 00:09:36,000 +We can say remove and we can pass the object itself, + +259 +00:09:36,000 --> 00:09:39,000 +whatever we are deleting there, right? + +260 +00:09:39,000 --> 00:09:41,000 +And okay, things are looking good. + +261 +00:09:41,000 --> 00:09:43,000 +It should delete because we are saying remove. + +262 +00:09:44,000 --> 00:09:46,000 +Okay, let's test both now. + +263 +00:09:46,000 --> 00:09:49,000 +Let's test the put and delete both. + +264 +00:09:49,000 --> 00:09:52,000 +By doing this changes, I will reset the application. + +265 +00:09:52,000 --> 00:09:54,000 +Let's head back to the Postman + +266 +00:09:54,000 --> 00:09:55,000 +and first we'll update instead of delete. + +267 +00:09:55,000 --> 00:09:57,000 +So I will say put, + +268 +00:09:57,000 --> 00:10:00,000 +and I want to update, let's say this object, + +269 +00:10:00,000 --> 00:10:03,000 +which is two, and we have already done the changes. + +270 +00:10:03,000 --> 00:10:04,000 +I will click on send. + +271 +00:10:04,000 --> 00:10:05,000 +Okay, it worked. + +272 +00:10:05,000 --> 00:10:08,000 +And you can see we got react developer here, + +273 +00:10:08,000 --> 00:10:09,000 +and this is coming from the repository. + +274 +00:10:09,000 --> 00:10:11,000 +Okay? + +275 +00:10:11,000 --> 00:10:12,000 +If you want to make sure it is working, + +276 +00:10:12,000 --> 00:10:14,000 +you can also send requests + +277 +00:10:14,000 --> 00:10:16,000 +for all the job post, click consent, + +278 +00:10:16,000 --> 00:10:18,000 +and you can see now second + +279 +00:10:18,000 --> 00:10:20,000 +is React Developer, not Frontend. + +280 +00:10:20,000 --> 00:10:23,000 +And we are saying record experience too. + +281 +00:10:23,000 --> 00:10:23,000 +Cool. + +282 +00:10:23,000 --> 00:10:26,000 +So the put is working, what about delete? + +283 +00:10:26,000 --> 00:10:27,000 +Let's try delete. + +284 +00:10:27,000 --> 00:10:29,000 +So we say delete and we'll say /3 + +285 +00:10:29,000 --> 00:10:31,000 +because we're deleting the third job, + +286 +00:10:31,000 --> 00:10:34,000 +and I'll click on send. + +287 +00:10:34,000 --> 00:10:37,000 +Okay, something went wrong, internal server error. + +288 +00:10:39,000 --> 00:10:41,000 +Let's see what went wrong for delete. + +289 +00:10:41,000 --> 00:10:42,000 +It says null. + +290 +00:10:43,000 --> 00:10:45,000 +Something broke. + +291 +00:10:45,000 --> 00:10:49,000 +Okay, it says concurrent modification exception. + +292 +00:10:49,000 --> 00:10:51,000 +We are not returning anything. + +293 +00:10:51,000 --> 00:10:52,000 +Click on send again. + +294 +00:10:52,000 --> 00:10:54,000 +Okay, so maybe the earlier request, + +295 +00:10:55,000 --> 00:10:57,000 +it happened at the same time. + +296 +00:10:57,000 --> 00:10:59,000 +There was some issue with the latency or something, + +297 +00:10:59,000 --> 00:11:01,000 +but you can see now it says deleted. + +298 +00:11:01,000 --> 00:11:02,000 +So it is working. + +299 +00:11:02,000 --> 00:11:07,000 +So I'll go back to the JobPost and click on on send. + +300 +00:11:07,000 --> 00:11:09,000 +And if you go back, you can see we don't have three anymore. + +301 +00:11:09,000 --> 00:11:10,000 +Okay? + +302 +00:11:10,000 --> 00:11:11,000 +It's working. + +303 +00:11:11,000 --> 00:11:14,000 +So if you go back, still showing some problem. + +304 +00:11:14,000 --> 00:11:16,000 +But anyway, we were able to delete devalue. + +305 +00:11:16,000 --> 00:11:19,000 +So that's how basically we use the put mapping + +306 +00:11:19,000 --> 00:11:21,000 +and the delete mapping. + +307 +00:11:21,000 --> 00:11:22,000 +So I hope this makes sense. + +308 +00:11:22,000 --> 00:11:25,000 +And you can also enhance this particular code if you want. + +309 +00:11:25,000 --> 00:11:28,000 +Depend upon how do you want to return this status? + +310 +00:11:28,000 --> 00:11:31,000 +We are just saying deleted, but you can send something else. + +311 +00:11:31,000 --> 00:11:33,000 +So that's it from this video where we talked about + +312 +00:11:33,000 --> 00:11:35,000 +the put mapping and delete mapping. + diff --git a/15 - REST using Spring Boot/010 Source-Code.url b/15 - REST using Spring Boot/010 Source-Code.url new file mode 100644 index 0000000000000000000000000000000000000000..6d7418c04d32ff7c96b0db567cc4133b750bed16 --- /dev/null +++ b/15 - REST using Spring Boot/010 Source-Code.url @@ -0,0 +1,2 @@ +[InternetShortcut] +URL=https://github.com/navinreddy20/spring6-course/tree/36d783117044564847940ba5046b35cc59f55346/9%20REST%20using%20Spring%20Boot/8.10%20Put%20and%20Delete%20Mapping/spring-boot-rest4 \ No newline at end of file diff --git a/15 - REST using Spring Boot/011 Content Negotiation_en.srt b/15 - REST using Spring Boot/011 Content Negotiation_en.srt new file mode 100644 index 0000000000000000000000000000000000000000..d572058e5fd8c5af8274586b6dbe252abc247348 --- /dev/null +++ b/15 - REST using Spring Boot/011 Content Negotiation_en.srt @@ -0,0 +1,716 @@ +1 +00:00:00,000 --> 00:00:03,000 +(logo chimes) + +2 +00:00:03,000 --> 00:00:06,000 +-: In this video, we'll talk about content negotiation. + +3 +00:00:06,000 --> 00:00:07,000 +Now, what I mean by that. + +4 +00:00:07,000 --> 00:00:10,000 +So, let's say if I go back to my Postman, + +5 +00:00:10,000 --> 00:00:12,000 +and when you send a request here, + +6 +00:00:12,000 --> 00:00:16,000 +you can see we are getting all this data in the JSON format. + +7 +00:00:16,000 --> 00:00:20,000 +But what if you want in XML format? Can we do that? + +8 +00:00:20,000 --> 00:00:21,000 +Actually, we can. + +9 +00:00:21,000 --> 00:00:24,000 +So, if you can go back to the Headers here, + +10 +00:00:24,000 --> 00:00:27,000 +and in the Header, you can mention the key that you want. + +11 +00:00:27,000 --> 00:00:31,000 +So, basically, you want to accept not JSON, + +12 +00:00:31,000 --> 00:00:33,000 +but you want to accept an XML. + +13 +00:00:33,000 --> 00:00:36,000 +So, you can simply say application/xml. + +14 +00:00:36,000 --> 00:00:38,000 +Now, when you do that, when you send a request for XML, + +15 +00:00:38,000 --> 00:00:42,000 +it'll get the XML data from the server. + +16 +00:00:42,000 --> 00:00:44,000 +Oh, but unfortunately, it's not working. + +17 +00:00:44,000 --> 00:00:47,000 +You can see we got the error, which is 406. + +18 +00:00:47,000 --> 00:00:48,000 +Why it's not working? + +19 +00:00:48,000 --> 00:00:49,000 +See, the thing is, + +20 +00:00:49,000 --> 00:00:51,000 +whenever you want to serialize your data, + +21 +00:00:51,000 --> 00:00:54,000 +so whatever data you are sending, + +22 +00:00:54,000 --> 00:00:55,000 +remember, all your data, + +23 +00:00:55,000 --> 00:00:57,000 +which you're returning from this server, + +24 +00:00:57,000 --> 00:00:59,000 +if you can see here for jobPosts, + +25 +00:00:59,000 --> 00:01:02,000 +you are returning a list of objects. + +26 +00:01:02,000 --> 00:01:06,000 +And what you are receiving on the client side is JSON. + +27 +00:01:06,000 --> 00:01:07,000 +Who is converting it? + +28 +00:01:07,000 --> 00:01:08,000 +Someone should be there, right? + +29 +00:01:08,000 --> 00:01:10,000 +Otherwise, it's not magic + +30 +00:01:10,000 --> 00:01:12,000 +that it will be automatically converted into a JSON format. + +31 +00:01:12,000 --> 00:01:15,000 +Now, to do that, we have a special library, + +32 +00:01:15,000 --> 00:01:17,000 +and we have not added that library. + +33 +00:01:17,000 --> 00:01:20,000 +Basically, if you can expand your external libraries, + +34 +00:01:20,000 --> 00:01:23,000 +you will find a library called Jackson. + +35 +00:01:23,000 --> 00:01:26,000 +Now, this is Jackson who is responsible + +36 +00:01:26,000 --> 00:01:28,000 +to convert your objects. + +37 +00:01:28,000 --> 00:01:30,000 +The Java objects into JSON. + +38 +00:01:30,000 --> 00:01:32,000 +And, of course, this is not the only library available, + +39 +00:01:32,000 --> 00:01:34,000 +but Spring uses Jackson by default. + +40 +00:01:34,000 --> 00:01:37,000 +So, just to reiterate, it is Jackson Library + +41 +00:01:37,000 --> 00:01:40,000 +who is converting your object into JSON. + +42 +00:01:40,000 --> 00:01:43,000 +Okay, but then why XML is not working? + +43 +00:01:43,000 --> 00:01:46,000 +It should also return XML format, right? + +44 +00:01:46,000 --> 00:01:47,000 +See, the thing is, + +45 +00:01:47,000 --> 00:01:49,000 +by default, the Jackson Library, which you have added, + +46 +00:01:49,000 --> 00:01:50,000 +only works with JSON. + +47 +00:01:50,000 --> 00:01:53,000 +It'll not work with XML. + +48 +00:01:53,000 --> 00:01:54,000 +If you want it to work, + +49 +00:01:54,000 --> 00:01:56,000 +basically, we have to add one more library, + +50 +00:01:56,000 --> 00:01:58,000 +of course, of Jackson, + +51 +00:01:58,000 --> 00:01:59,000 +but with the XML support. + +52 +00:01:59,000 --> 00:02:02,000 +So, you have to go to your pom.xml file. + +53 +00:02:02,000 --> 00:02:04,000 +And here, we have to add that for the library, + +54 +00:02:04,000 --> 00:02:08,000 +which is for the Jackson XML. + +55 +00:02:08,000 --> 00:02:10,000 +Now, to do that, I will go back to my browser, + +56 +00:02:10,000 --> 00:02:15,000 +and we will go to our favorite website, mvnrepository. + +57 +00:02:15,000 --> 00:02:19,000 +And here, you just have to search for Jackson XML. + +58 +00:02:19,000 --> 00:02:20,000 +So, this is a library which you have to use, + +59 +00:02:20,000 --> 00:02:22,000 +which is Jackson Dataformat XML. + +60 +00:02:22,000 --> 00:02:24,000 +Click here. And now, we have to pick a version. + +61 +00:02:24,000 --> 00:02:25,000 +Now, which version to pick up? + +62 +00:02:25,000 --> 00:02:29,000 +Now, whatever version you have for the Jackson code, + +63 +00:02:29,000 --> 00:02:30,000 +just pick up the same version. + +64 +00:02:30,000 --> 00:02:32,000 +So, you can see the version which we're using here + +65 +00:02:32,000 --> 00:02:33,000 +is 2.15.3. + +66 +00:02:33,000 --> 00:02:34,000 +Let's pick up the same one. + +67 +00:02:34,000 --> 00:02:38,000 +Copy dependency, go back to your project, and paste it here. + +68 +00:02:38,000 --> 00:02:38,000 +That's it. + +69 +00:02:38,000 --> 00:02:40,000 +Once you add this, + +70 +00:02:40,000 --> 00:02:42,000 +of course, since we have changed the Maven, + +71 +00:02:42,000 --> 00:02:47,000 +we might need to reload this just to be on the safer side, + +72 +00:02:47,000 --> 00:02:50,000 +and you should be able to find your XML here somewhere. + +73 +00:02:50,000 --> 00:02:53,000 +So, you can see we got Dataformat XML. + +74 +00:02:53,000 --> 00:02:56,000 +Now, I think it'll do the work. + +75 +00:02:56,000 --> 00:02:59,000 +Let's restart the application. Go back to Postman. + +76 +00:02:59,000 --> 00:03:02,000 +And now, with the same application/xml, + +77 +00:03:02,000 --> 00:03:04,000 +click on Send and Voila. + +78 +00:03:04,000 --> 00:03:07,000 +You can see we got the data in the XML format. + +79 +00:03:07,000 --> 00:03:09,000 +So, in the earlier case, why it was not working? + +80 +00:03:09,000 --> 00:03:11,000 +Because we were not having any library + +81 +00:03:11,000 --> 00:03:14,000 +who will convert your object into XML. + +82 +00:03:14,000 --> 00:03:16,000 +And now, with the help of the library, + +83 +00:03:16,000 --> 00:03:19,000 +we got the XML data here. + +84 +00:03:19,000 --> 00:03:22,000 +Again, the same data, but in the XML format. + +85 +00:03:22,000 --> 00:03:23,000 +Now, if you look at the formats, + +86 +00:03:23,000 --> 00:03:25,000 +of course, JSON looks better than XML, + +87 +00:03:25,000 --> 00:03:26,000 +but let's say if you have an application + +88 +00:03:26,000 --> 00:03:29,000 +where you just want to consume XML, + +89 +00:03:29,000 --> 00:03:30,000 +then you don't have a choice, right? + +90 +00:03:30,000 --> 00:03:32,000 +You have to use XML format there. + +91 +00:03:32,000 --> 00:03:35,000 +So, this works, but what if you have one more restriction, + +92 +00:03:35,000 --> 00:03:39,000 +that from the server side, only JSON should go. + +93 +00:03:39,000 --> 00:03:42,000 +You don't want your client to accept XML. + +94 +00:03:42,000 --> 00:03:44,000 +One way you can remove the library. + +95 +00:03:44,000 --> 00:03:47,000 +Or, when you turn the data here, you can also mention + +96 +00:03:47,000 --> 00:03:50,000 +that this particular method will only work with JSON. + +97 +00:03:50,000 --> 00:03:51,000 +Can we do that? + +98 +00:03:51,000 --> 00:03:53,000 +Can we negotiate a content whereby, + +99 +00:03:53,000 --> 00:03:57,000 +by saying, let's only send JSON, let's not send XML. + +100 +00:03:57,000 --> 00:03:59,000 +The way you do that is, + +101 +00:03:59,000 --> 00:04:00,000 +I mean, of course, you cannot specify + +102 +00:04:00,000 --> 00:04:02,000 +that you don't want to send XML, + +103 +00:04:02,000 --> 00:04:05,000 +but you can specify what you want to send. + +104 +00:04:05,000 --> 00:04:08,000 +So, first of all, which was the default path, + +105 +00:04:08,000 --> 00:04:11,000 +let's mention the variable name path there, give a comma, + +106 +00:04:11,000 --> 00:04:14,000 +and you can say it'll only produce, + +107 +00:04:14,000 --> 00:04:16,000 +in the curly brackets, you can mention, + +108 +00:04:16,000 --> 00:04:19,000 +and you can mention multiple things, not just one. + +109 +00:04:19,000 --> 00:04:22,000 +So, in the double quotes, you can mention application/json. + +110 +00:04:22,000 --> 00:04:25,000 +Now, by doing this, what you're saying is, hey, you know, + +111 +00:04:25,000 --> 00:04:28,000 +this particular method will only return the JSON data, + +112 +00:04:28,000 --> 00:04:29,000 +not XML. + +113 +00:04:29,000 --> 00:04:32,000 +I mean, we are saying it'll only return JSON, + +114 +00:04:32,000 --> 00:04:34,000 +we are not saying you're not going to return XML. + +115 +00:04:34,000 --> 00:04:35,000 +Let's not talk about negative stuff. + +116 +00:04:35,000 --> 00:04:37,000 +We can say positive stuff. + +117 +00:04:37,000 --> 00:04:38,000 +What you want to return? JSON. + +118 +00:04:38,000 --> 00:04:40,000 +But if you request for something else. + +119 +00:04:40,000 --> 00:04:42,000 +If you go back here, + +120 +00:04:42,000 --> 00:04:44,000 +and you can see I'm still requesting for XML, + +121 +00:04:44,000 --> 00:04:45,000 +click on Send. + +122 +00:04:45,000 --> 00:04:47,000 +It'll not work. + +123 +00:04:47,000 --> 00:04:49,000 +It'll say Not Acceptable. + +124 +00:04:49,000 --> 00:04:51,000 +You got this status error, 406. + +125 +00:04:51,000 --> 00:04:52,000 +But yeah, if you request for JSON, + +126 +00:04:52,000 --> 00:04:54,000 +and by default it will send JSON request. + +127 +00:04:54,000 --> 00:04:55,000 +Click on Send. + +128 +00:04:55,000 --> 00:04:57,000 +It works with JSON, but not with XML. + +129 +00:04:58,000 --> 00:05:01,000 +Likewise, you can also send data. + +130 +00:05:01,000 --> 00:05:03,000 +Example, let's say if you want to create a new post now. + +131 +00:05:03,000 --> 00:05:06,000 +Okay, so let's say it'll work with JSON, + +132 +00:05:06,000 --> 00:05:08,000 +and only work with JSON, let's say. + +133 +00:05:08,000 --> 00:05:10,000 +So, what I will do is... + +134 +00:05:10,000 --> 00:05:12,000 +Okay, we've got JSON. + +135 +00:05:12,000 --> 00:05:15,000 +Let me copy this, and let me create a new post. + +136 +00:05:15,000 --> 00:05:17,000 +So, this was a POST request. I will go back to the body. + +137 +00:05:17,000 --> 00:05:19,000 +I already have a body here, + +138 +00:05:19,000 --> 00:05:20,000 +so I don't have to copy anything. + +139 +00:05:20,000 --> 00:05:23,000 +Let me create a sixth post here. + +140 +00:05:23,000 --> 00:05:26,000 +But then what I can do is, in the Headers, + +141 +00:05:26,000 --> 00:05:30,000 +I can say we are basically sending, + +142 +00:05:30,000 --> 00:05:32,000 +so we can specify the content type. + +143 +00:05:32,000 --> 00:05:33,000 +And by default, it'll use JSON, + +144 +00:05:33,000 --> 00:05:35,000 +but let's say if I specifically mention + +145 +00:05:35,000 --> 00:05:39,000 +that we are sending the JSON format, okay? + +146 +00:05:39,000 --> 00:05:41,000 +So, in the post, we are sending JSON, + +147 +00:05:41,000 --> 00:05:44,000 +but let's say on the server side, + +148 +00:05:44,000 --> 00:05:48,000 +if you mention that you want to accept only XML, + +149 +00:05:48,000 --> 00:05:49,000 +can we do that? + +150 +00:05:49,000 --> 00:05:51,000 +Because what we are saying is, we are saying produce, + +151 +00:05:51,000 --> 00:05:55,000 +what it produces, but what about what it consumes? + +152 +00:05:55,000 --> 00:05:56,000 +So, let's say in the POST mapping, + +153 +00:05:56,000 --> 00:06:00,000 +I will say path, and give a comma here, + +154 +00:06:00,000 --> 00:06:03,000 +and we can also specify what it consumes. + +155 +00:06:03,000 --> 00:06:07,000 +So, if you say this consumes only XML. + +156 +00:06:07,000 --> 00:06:10,000 +So now, we are saying that it'll only consume XML. + +157 +00:06:10,000 --> 00:06:11,000 +Let's restart the app. + +158 +00:06:11,000 --> 00:06:14,000 +Let's go back to Postman and click on Send. + +159 +00:06:14,000 --> 00:06:17,000 +You can see we got an error. It says Unsupported Media Type. + +160 +00:06:18,000 --> 00:06:19,000 +So, when you send data, + +161 +00:06:19,000 --> 00:06:21,000 +and if you're sending JSON, + +162 +00:06:21,000 --> 00:06:24,000 +the only acceptable there is XML, then this will not work. + +163 +00:06:24,000 --> 00:06:26,000 +So, what we are doing is we are negotiating the content. + +164 +00:06:26,000 --> 00:06:28,000 +We are saying, "Hey, you know, + +165 +00:06:28,000 --> 00:06:30,000 +what I can produce and what I can consume? + +166 +00:06:30,000 --> 00:06:31,000 +I can specify that." + +167 +00:06:31,000 --> 00:06:33,000 +Most of the time, we don't do it. + +168 +00:06:33,000 --> 00:06:34,000 +But let's say if you have a special requirement + +169 +00:06:34,000 --> 00:06:37,000 +where you say, "I want to specify what it produce, + +170 +00:06:37,000 --> 00:06:39,000 +I want to specify what it consumes." + +171 +00:06:39,000 --> 00:06:42,000 +You can do that with the help of producers and consumes. + +172 +00:06:42,000 --> 00:06:45,000 +So, yeah, that's about how do you do content negotiation. + +173 +00:06:45,000 --> 00:06:48,000 +That's how you specify which format you want to work with. + +174 +00:06:48,000 --> 00:06:50,000 +And by default, in your Spring project, + +175 +00:06:50,000 --> 00:06:52,000 +you'll be getting JSON support. + +176 +00:06:52,000 --> 00:06:54,000 +If you want XML support, then manually, + +177 +00:06:54,000 --> 00:06:58,000 +you have to add this library, which is the Dataformat XML. + +178 +00:06:58,000 --> 00:07:01,000 +So, Jackson Dataformat XML. + +179 +00:07:01,000 --> 00:07:03,000 +That's it from this video. See you in the next part. + diff --git a/15 - REST using Spring Boot/external-links.txt b/15 - REST using Spring Boot/external-links.txt new file mode 100644 index 0000000000000000000000000000000000000000..980f0b74e37750bdcb5fdb47e1501219511bd879 --- /dev/null +++ b/15 - REST using Spring Boot/external-links.txt @@ -0,0 +1,15 @@ + +004 Source-Code +https://github.com/navinreddy20/spring6-course/tree/80e0c059c5c259ef6009838a934ed9e92865c3d7/React%20UI + +006 Source-Code +https://github.com/navinreddy20/spring6-course/tree/36d783117044564847940ba5046b35cc59f55346/9%20REST%20using%20Spring%20Boot/8.6%20Creating%20a%20Rest%20Controller/spring-boot-rest + +008 Source-Code +https://github.com/navinreddy20/spring6-course/tree/36d783117044564847940ba5046b35cc59f55346/9%20REST%20using%20Spring%20Boot/8.8%20PathVariable/spring-boot-rest + +009 Source-Code +https://github.com/navinreddy20/spring6-course/tree/36d783117044564847940ba5046b35cc59f55346/9%20REST%20using%20Spring%20Boot/8.9%20Sending%20Data%20and%20RequestBody/spring-boot-rest + +010 Source-Code +https://github.com/navinreddy20/spring6-course/tree/36d783117044564847940ba5046b35cc59f55346/9%20REST%20using%20Spring%20Boot/8.10%20Put%20and%20Delete%20Mapping/spring-boot-rest4 diff --git a/16 - Spring Data JPA/001 Spring Data JPA Introduction_en.srt b/16 - Spring Data JPA/001 Spring Data JPA Introduction_en.srt new file mode 100644 index 0000000000000000000000000000000000000000..a97dcbb2c52e52ddb739fa70d2bda3b931c4ff00 --- /dev/null +++ b/16 - Spring Data JPA/001 Spring Data JPA Introduction_en.srt @@ -0,0 +1,276 @@ +1 +00:00:00,000 --> 00:00:03,000 +(soft bright music) + +2 +00:00:03,000 --> 00:00:07,000 +-: In this section we'll talk about Spring Data JPA. + +3 +00:00:07,000 --> 00:00:09,000 +The other thing is whatever we have done till now, + +4 +00:00:09,000 --> 00:00:11,000 +we have talked about a job portal + +5 +00:00:11,000 --> 00:00:13,000 +and we were able to build it. + +6 +00:00:13,000 --> 00:00:15,000 +So basically we have different layers + +7 +00:00:15,000 --> 00:00:17,000 +and in this controller layer, + +8 +00:00:17,000 --> 00:00:18,000 +we are able to create the methods + +9 +00:00:18,000 --> 00:00:19,000 +which will accept the get request, + +10 +00:00:19,000 --> 00:00:22,000 +post request, put request, delete request, + +11 +00:00:22,000 --> 00:00:23,000 +and things are working out. + +12 +00:00:23,000 --> 00:00:26,000 +But of course the controller layer is responsible + +13 +00:00:26,000 --> 00:00:28,000 +just to accept the request + +14 +00:00:28,000 --> 00:00:29,000 +and give something back to the client. + +15 +00:00:29,000 --> 00:00:32,000 +But it is the service layer who will do the operations. + +16 +00:00:32,000 --> 00:00:35,000 +And we have not done much of the logical stuff. + +17 +00:00:35,000 --> 00:00:37,000 +But what if you want to face data from database? + +18 +00:00:37,000 --> 00:00:40,000 +And that's why we have a repository layer + +19 +00:00:40,000 --> 00:00:42,000 +in which you have written the code. + +20 +00:00:42,000 --> 00:00:44,000 +But in the repo layer, we have not actually connected + +21 +00:00:44,000 --> 00:00:46,000 +with database, right? + +22 +00:00:46,000 --> 00:00:49,000 +So we were able to build stuff but without database. + +23 +00:00:49,000 --> 00:00:53,000 +Now in this section we'll complete it with database. + +24 +00:00:53,000 --> 00:00:55,000 +Now the way you can implement that is with the, + +25 +00:00:55,000 --> 00:00:59,000 +you can simply use normal JDPC, you can use Spring JDPC. + +26 +00:00:59,000 --> 00:01:01,000 +The way we have done before. + +27 +00:01:01,000 --> 00:01:03,000 +We can also implement spring ORM + +28 +00:01:03,000 --> 00:01:06,000 +where you have to do a lot of code by yourself. + +29 +00:01:06,000 --> 00:01:08,000 +But we are going to use the easiest module + +30 +00:01:08,000 --> 00:01:11,000 +of spring framework, which is Spring Data JPA, + +31 +00:01:11,000 --> 00:01:14,000 +which will make our work very, very easy. + +32 +00:01:14,000 --> 00:01:17,000 +And of course, instead of starting with the portal, + +33 +00:01:17,000 --> 00:01:19,000 +I mean instead of starting with the job application, + +34 +00:01:19,000 --> 00:01:21,000 +let's create a new project + +35 +00:01:21,000 --> 00:01:24,000 +and let's understand how Spring Data JPA works + +36 +00:01:24,000 --> 00:01:26,000 +and then we can in integrate that. + +37 +00:01:26,000 --> 00:01:27,000 +Now what project we are going to build, + +38 +00:01:27,000 --> 00:01:31,000 +of course we'll try to not jump into a new project. + +39 +00:01:31,000 --> 00:01:33,000 +If you remember we have talked about the student project + +40 +00:01:33,000 --> 00:01:35,000 +when we talked about Spring JDBC. + +41 +00:01:35,000 --> 00:01:37,000 +Now I do have a code ready with me. + +42 +00:01:37,000 --> 00:01:40,000 +So if you can see, we have this spring JDBC here. + +43 +00:01:40,000 --> 00:01:42,000 +And what we have done is we have a main method + +44 +00:01:42,000 --> 00:01:45,000 +and then in the pom.xml file, + +45 +00:01:45,000 --> 00:01:47,000 +we have added the spring boot JDBC. + +46 +00:01:47,000 --> 00:01:49,000 +And then we have connected this application + +47 +00:01:49,000 --> 00:01:51,000 +with H2 as well as Postgres. + +48 +00:01:51,000 --> 00:01:54,000 +So we did with H2 first + +49 +00:01:54,000 --> 00:01:55,000 +and then we moved towards Postgres. + +50 +00:01:55,000 --> 00:01:58,000 +In the student class, we have a very simple class. + +51 +00:01:58,000 --> 00:02:02,000 +Here we have three variables, role number, name, marks. + +52 +00:02:02,000 --> 00:02:06,000 +And next we have a student repo here + +53 +00:02:06,000 --> 00:02:09,000 +in which we were able to use JDBC template. + +54 +00:02:09,000 --> 00:02:11,000 +And then based on what you want, + +55 +00:02:11,000 --> 00:02:14,000 +maybe you want to save data, maybe you want to fetch data. + +56 +00:02:14,000 --> 00:02:15,000 +We have written the query. + +57 +00:02:15,000 --> 00:02:17,000 +Literally we have written the SQL query. + +58 +00:02:17,000 --> 00:02:19,000 +A lot of people like SQL queries. + +59 +00:02:19,000 --> 00:02:21,000 +And of course it's not a bad thing. + +60 +00:02:21,000 --> 00:02:24,000 +But then what if you can avoid writing SQL queries? + +61 +00:02:24,000 --> 00:02:26,000 +Can we do that? Can we simply avoid something? + +62 +00:02:26,000 --> 00:02:27,000 +Okay, when I say something, + +63 +00:02:27,000 --> 00:02:29,000 +when you're building a Java application, + +64 +00:02:29,000 --> 00:02:31,000 +why to work with SQL? + +65 +00:02:31,000 --> 00:02:35,000 +And that's where the concept of ORM comes to the picture. + +66 +00:02:35,000 --> 00:02:38,000 +So even before we talk about Spring Data JPA, + +67 +00:02:38,000 --> 00:02:40,000 +let's talk about ORM and you'll be thinking, + +68 +00:02:40,000 --> 00:02:43,000 +hey, why we are talking about ORM when we talked about JPA? + +69 +00:02:43,000 --> 00:02:45,000 +You will understand that in the next video. + diff --git a/16 - Spring Data JPA/002 What is ORM and JPA_en.srt b/16 - Spring Data JPA/002 What is ORM and JPA_en.srt new file mode 100644 index 0000000000000000000000000000000000000000..3a0cfdabc563ea7ee2bba0e553ce38e88328a12e --- /dev/null +++ b/16 - Spring Data JPA/002 What is ORM and JPA_en.srt @@ -0,0 +1,904 @@ +1 +00:00:00,000 --> 00:00:03,000 +(gentle intro music) + +2 +00:00:03,000 --> 00:00:05,000 +-: Now let's talk about ORM. + +3 +00:00:05,000 --> 00:00:09,000 +I know the topic, the entire section, talks about JPA, + +4 +00:00:09,000 --> 00:00:10,000 +but we'll start with ORM + +5 +00:00:10,000 --> 00:00:14,000 +and then we'll try to connect ORM with JPA, okay? + +6 +00:00:14,000 --> 00:00:15,000 +So let's talk about ORM. + +7 +00:00:15,000 --> 00:00:19,000 +Now ORM stands for Object Relational Mapping. + +8 +00:00:19,000 --> 00:00:20,000 +Now why do we need this? + +9 +00:00:20,000 --> 00:00:21,000 +Now think about this. + +10 +00:00:21,000 --> 00:00:22,000 +When you talk about Java, + +11 +00:00:22,000 --> 00:00:25,000 +Java is our object-oriented programming, right? + +12 +00:00:25,000 --> 00:00:28,000 +Which means the most important thing here is object, okay? + +13 +00:00:28,000 --> 00:00:30,000 +So if anybody wanted to do anything, + +14 +00:00:30,000 --> 00:00:31,000 +you think about object first. + +15 +00:00:31,000 --> 00:00:34,000 +Let's say if you want to build a E-commerce website, + +16 +00:00:34,000 --> 00:00:35,000 +everything becomes object. + +17 +00:00:35,000 --> 00:00:37,000 +Your catalog becomes an object, + +18 +00:00:37,000 --> 00:00:39,000 +your users becomes an object, + +19 +00:00:39,000 --> 00:00:40,000 +your admin becomes an object. + +20 +00:00:40,000 --> 00:00:43,000 +So everything in there is an object right? + +21 +00:00:43,000 --> 00:00:46,000 +Now if you are representing everything + +22 +00:00:46,000 --> 00:00:48,000 +in the Java world as object, + +23 +00:00:48,000 --> 00:00:51,000 +and we know that objects are created + +24 +00:00:51,000 --> 00:00:53,000 +with the help of classes, right? + +25 +00:00:53,000 --> 00:00:55,000 +Class is a blueprint for the object. + +26 +00:00:55,000 --> 00:00:56,000 +In class, you mention the class keyword, + +27 +00:00:56,000 --> 00:00:58,000 +then you mention the class name. + +28 +00:00:58,000 --> 00:00:59,000 +And of course, in this class, + +29 +00:00:59,000 --> 00:01:00,000 +we'll be having different variables. + +30 +00:01:00,000 --> 00:01:01,000 +Let's say we have a student class + +31 +00:01:01,000 --> 00:01:03,000 +and in this class we have three variables. + +32 +00:01:03,000 --> 00:01:05,000 +RollNo, name, and marks, okay? + +33 +00:01:05,000 --> 00:01:08,000 +Now these three variables becomes a property + +34 +00:01:08,000 --> 00:01:09,000 +for a class, right? + +35 +00:01:09,000 --> 00:01:11,000 +And of course, in this class, you can have some methods, + +36 +00:01:11,000 --> 00:01:13,000 +but methods at this point is not important for us. + +37 +00:01:13,000 --> 00:01:14,000 +Let's only talk about that data. + +38 +00:01:14,000 --> 00:01:16,000 +So when you talk about a class, + +39 +00:01:16,000 --> 00:01:19,000 +which is student in this case, we got three variables. + +40 +00:01:19,000 --> 00:01:20,000 +And for the student class, + +41 +00:01:20,000 --> 00:01:22,000 +we can create multiple objects, not just one. + +42 +00:01:22,000 --> 00:01:25,000 +We can have 10, 20, 100, 1 million. + +43 +00:01:25,000 --> 00:01:25,000 +That's your choice, + +44 +00:01:25,000 --> 00:01:28,000 +provided your machine can bear 1 million objects, + +45 +00:01:28,000 --> 00:01:30,000 +but we can create any number of objects. + +46 +00:01:30,000 --> 00:01:33,000 +Now what makes all this objects different? + +47 +00:01:33,000 --> 00:01:34,000 +It's the data, right? + +48 +00:01:34,000 --> 00:01:37,000 +Of course, when you have 10 students object, + +49 +00:01:37,000 --> 00:01:38,000 +every student will have a different data. + +50 +00:01:38,000 --> 00:01:39,000 +They will have a different roll number, + +51 +00:01:39,000 --> 00:01:40,000 +they will have a different name, + +52 +00:01:40,000 --> 00:01:42,000 +they will have a different marks. + +53 +00:01:42,000 --> 00:01:44,000 +Maybe they will have the same marks if they're copying. + +54 +00:01:44,000 --> 00:01:47,000 +But the point is, the data, most of the time, + +55 +00:01:47,000 --> 00:01:48,000 +will be different. + +56 +00:01:48,000 --> 00:01:51,000 +And that's what makes the object different. + +57 +00:01:51,000 --> 00:01:52,000 +Now come back to database world. + +58 +00:01:52,000 --> 00:01:53,000 +Now why are we talking about database + +59 +00:01:53,000 --> 00:01:55,000 +is because you want to store data. + +60 +00:01:55,000 --> 00:01:57,000 +I mean, that's very important, right? + +61 +00:01:57,000 --> 00:01:58,000 +And we know the importance of database. + +62 +00:01:58,000 --> 00:02:01,000 +So let's directly talk about how do you store data. + +63 +00:02:01,000 --> 00:02:03,000 +Now in the world of database, + +64 +00:02:03,000 --> 00:02:05,000 +we have different ways of storing data. + +65 +00:02:05,000 --> 00:02:08,000 +Primarily, we have relational databases + +66 +00:02:08,000 --> 00:02:10,000 +and then we have a NoSQL databases. + +67 +00:02:10,000 --> 00:02:12,000 +Now in the relational database, + +68 +00:02:12,000 --> 00:02:13,000 +we normally follow tables, right? + +69 +00:02:13,000 --> 00:02:15,000 +So in one database, you'll be having multiple tables. + +70 +00:02:15,000 --> 00:02:18,000 +Might be you have tables which are related, right? + +71 +00:02:18,000 --> 00:02:21,000 +So we call them a parent table or child table, + +72 +00:02:21,000 --> 00:02:23,000 +or a primary key or a foreign key. + +73 +00:02:23,000 --> 00:02:25,000 +So we connect them with primary key, foreign key. + +74 +00:02:25,000 --> 00:02:28,000 +Complex concepts, but important to know. + +75 +00:02:28,000 --> 00:02:30,000 +On the other hand, we have a NoSQL world, + +76 +00:02:30,000 --> 00:02:34,000 +where you don't actually store data in a table structure, + +77 +00:02:34,000 --> 00:02:36,000 +you store them a document format + +78 +00:02:36,000 --> 00:02:37,000 +or maybe table in some framework. + +79 +00:02:37,000 --> 00:02:39,000 +Example in Cassandra, we do that. + +80 +00:02:39,000 --> 00:02:42,000 +But the idea is we can directly store data + +81 +00:02:42,000 --> 00:02:45,000 +in the database without using SQL query. + +82 +00:02:45,000 --> 00:02:47,000 +Or there might be some other query language. + +83 +00:02:47,000 --> 00:02:49,000 +Example in Cassandra, we use SQL, + +84 +00:02:49,000 --> 00:02:51,000 +but the idea is we have two different worlds. + +85 +00:02:51,000 --> 00:02:53,000 +Example in MongoDB, we actually store data + +86 +00:02:53,000 --> 00:02:55,000 +as a document, right? + +87 +00:02:55,000 --> 00:02:57,000 +Now let's say if we talk about relational database, + +88 +00:02:57,000 --> 00:02:59,000 +let's focus on that here. + +89 +00:02:59,000 --> 00:03:00,000 +Now if we talk about relational database, + +90 +00:03:00,000 --> 00:03:03,000 +we store data in a tabular format, right? + +91 +00:03:03,000 --> 00:03:06,000 +That means, even if you want to store a student data, + +92 +00:03:06,000 --> 00:03:09,000 +you have to store that in a tabular format. + +93 +00:03:09,000 --> 00:03:11,000 +Now how do you create a table? + +94 +00:03:11,000 --> 00:03:13,000 +Of course, you don't directly create a table. + +95 +00:03:13,000 --> 00:03:14,000 +You think about a table, right? + +96 +00:03:14,000 --> 00:03:16,000 +What should be the table name? + +97 +00:03:16,000 --> 00:03:18,000 +How many columns you want, + +98 +00:03:18,000 --> 00:03:20,000 +and what should be the name of the column? + +99 +00:03:20,000 --> 00:03:21,000 +What should be the type of the column? + +100 +00:03:21,000 --> 00:03:23,000 +So we decide all those things. + +101 +00:03:23,000 --> 00:03:28,000 +Now what if we can directly connect your class and a table? + +102 +00:03:28,000 --> 00:03:29,000 +Okay? + +103 +00:03:29,000 --> 00:03:31,000 +So example, if I give you a class, + +104 +00:03:31,000 --> 00:03:34,000 +you should be able to create a table for it. + +105 +00:03:34,000 --> 00:03:35,000 +And the way we can do that + +106 +00:03:35,000 --> 00:03:37,000 +is what if you can take a class name + +107 +00:03:37,000 --> 00:03:39,000 +and make it a table name? + +108 +00:03:39,000 --> 00:03:40,000 +So the class name is student, + +109 +00:03:40,000 --> 00:03:43,000 +table name becomes student, as simple as that. + +110 +00:03:43,000 --> 00:03:44,000 +How about the columns? + +111 +00:03:44,000 --> 00:03:46,000 +How do you know what columns you need? + +112 +00:03:46,000 --> 00:03:50,000 +So if I ask you, "Hey, create a table for me for a student." + +113 +00:03:50,000 --> 00:03:52,000 +You will say, "Give me the column names." + +114 +00:03:52,000 --> 00:03:55,000 +I will say, "Okay, this is my class, take it from here." + +115 +00:03:55,000 --> 00:03:57,000 +Now you will say, "Okay, I got a class. + +116 +00:03:57,000 --> 00:04:01,000 +This class has three variables or three properties. + +117 +00:04:01,000 --> 00:04:06,000 +Let me create three columns, rollNo, name, and marks." + +118 +00:04:06,000 --> 00:04:09,000 +So basically, we have solved the problem of table name + +119 +00:04:09,000 --> 00:04:10,000 +and table column names, + +120 +00:04:10,000 --> 00:04:12,000 +and how many columns you need. + +121 +00:04:12,000 --> 00:04:14,000 +But what about a data type? + +122 +00:04:14,000 --> 00:04:15,000 +Of course, right on table also, + +123 +00:04:15,000 --> 00:04:18,000 +you have to specify the type of column. + +124 +00:04:18,000 --> 00:04:20,000 +Now this type will be coming from the Java world. + +125 +00:04:20,000 --> 00:04:22,000 +So you can say, "Okay, so we have a rollNo, + +126 +00:04:22,000 --> 00:04:23,000 +which is our type INT. + +127 +00:04:23,000 --> 00:04:26,000 +Let's make type INT here in table as well. + +128 +00:04:26,000 --> 00:04:27,000 +In name, we have a string. + +129 +00:04:27,000 --> 00:04:30,000 +Let's make a VARCHAR or text here in the table. + +130 +00:04:30,000 --> 00:04:33,000 +We have marks, which is again INT, + +131 +00:04:33,000 --> 00:04:34,000 +let's make it INT here. + +132 +00:04:34,000 --> 00:04:35,000 +So you know what we are doing? + +133 +00:04:35,000 --> 00:04:38,000 +We are trying to create a table from a class. + +134 +00:04:38,000 --> 00:04:42,000 +If you can do it, can't we ask a framework + +135 +00:04:42,000 --> 00:04:43,000 +or a library to do it for us? + +136 +00:04:43,000 --> 00:04:45,000 +So let's say we have a library and we say, + +137 +00:04:45,000 --> 00:04:47,000 +"Hey library, this is my class. + +138 +00:04:47,000 --> 00:04:48,000 +Give me a table." + +139 +00:04:48,000 --> 00:04:50,000 +And that is something we can do + +140 +00:04:50,000 --> 00:04:53,000 +with the help of ORM tool. + +141 +00:04:53,000 --> 00:04:54,000 +Because what we have done here + +142 +00:04:54,000 --> 00:04:58,000 +is we tried to connect the object world + +143 +00:04:58,000 --> 00:05:00,000 +and relational world and we tried to map it, + +144 +00:05:00,000 --> 00:05:03,000 +object relational mapping. + +145 +00:05:03,000 --> 00:05:04,000 +Okay, that's the concept. + +146 +00:05:04,000 --> 00:05:07,000 +Now question arise how you are going to implement it. + +147 +00:05:07,000 --> 00:05:10,000 +And that's why we have different ORM tools. + +148 +00:05:10,000 --> 00:05:11,000 +One of them is Hibernate. + +149 +00:05:11,000 --> 00:05:12,000 +We got TopLink. + +150 +00:05:12,000 --> 00:05:14,000 +There are multiple options, right? + +151 +00:05:14,000 --> 00:05:15,000 +So it's not just one. + +152 +00:05:15,000 --> 00:05:17,000 +We have list of ORM tools. + +153 +00:05:17,000 --> 00:05:20,000 +The most famous one is Hibernate, okay? + +154 +00:05:20,000 --> 00:05:21,000 +So you can simply use Hibernate + +155 +00:05:21,000 --> 00:05:23,000 +and you can implement this concept. + +156 +00:05:23,000 --> 00:05:25,000 +So basically, we have a ORM concept. + +157 +00:05:25,000 --> 00:05:26,000 +The tool is Hibernate. + +158 +00:05:26,000 --> 00:05:28,000 +So using Hibernate, you can ask, + +159 +00:05:28,000 --> 00:05:30,000 +I mean, talk to the library, which I was talking about. + +160 +00:05:30,000 --> 00:05:31,000 +That's Hibernate. + +161 +00:05:31,000 --> 00:05:33,000 +So you can say, "Hey, Hibernate, + +162 +00:05:33,000 --> 00:05:37,000 +I have a class here and I got the objects of this class. + +163 +00:05:37,000 --> 00:05:40,000 +Just store these objects in the database." + +164 +00:05:40,000 --> 00:05:42,000 +Hibernate will say, "Okay, done." + +165 +00:05:42,000 --> 00:05:45,000 +Because I know how to create those table based on a class. + +166 +00:05:45,000 --> 00:05:48,000 +Okay, but then we have one question here. + +167 +00:05:48,000 --> 00:05:50,000 +We talked about the columns and table name, + +168 +00:05:50,000 --> 00:05:52,000 +what about the rules? + +169 +00:05:52,000 --> 00:05:56,000 +Now every object in the Java world becomes one row. + +170 +00:05:56,000 --> 00:05:58,000 +So let's say for a student, we have 10 objects + +171 +00:05:58,000 --> 00:06:00,000 +and all this object will have a different data. + +172 +00:06:00,000 --> 00:06:04,000 +And this becomes your 10 rows in the table. + +173 +00:06:04,000 --> 00:06:06,000 +Hibernate says, "Every time you give an object to save, + +174 +00:06:06,000 --> 00:06:09,000 +I will create a new row," as simple as that. + +175 +00:06:09,000 --> 00:06:11,000 +And every time you say, "Hey, I want some data." + +176 +00:06:11,000 --> 00:06:14,000 +You want some data in the object format, + +177 +00:06:14,000 --> 00:06:18,000 +the Hibernate will get it from the table and give it to you. + +178 +00:06:18,000 --> 00:06:21,000 +So one row becomes one object, right? + +179 +00:06:21,000 --> 00:06:23,000 +And the way it was before, one object becomes one row. + +180 +00:06:23,000 --> 00:06:27,000 +So that's ORM and that's Hibernate. + +181 +00:06:27,000 --> 00:06:30,000 +Okay, but then we still not talked about JPA here. + +182 +00:06:30,000 --> 00:06:31,000 +See, the thing is, as I mentioned before, + +183 +00:06:31,000 --> 00:06:33,000 +there are different tools available for ORM, right? + +184 +00:06:33,000 --> 00:06:35,000 +Hibernate is not the only one. + +185 +00:06:35,000 --> 00:06:37,000 +And different projects can use different tools. + +186 +00:06:37,000 --> 00:06:40,000 +Maybe in one project, you're using Hibernate. + +187 +00:06:40,000 --> 00:06:41,000 +In other project, you're using something else. + +188 +00:06:41,000 --> 00:06:43,000 +And now let's say you're using Hibernate + +189 +00:06:43,000 --> 00:06:46,000 +and you want to switch to some other tool. + +190 +00:06:46,000 --> 00:06:48,000 +You have to basically change the entire code. + +191 +00:06:48,000 --> 00:06:51,000 +Can't we just have a common specification, + +192 +00:06:51,000 --> 00:06:53,000 +where you can say, "Okay, you know, + +193 +00:06:53,000 --> 00:06:56,000 +let's not be very specific to Hibernate or this tool. + +194 +00:06:56,000 --> 00:06:59,000 +Let's build for some specification." + +195 +00:06:59,000 --> 00:07:00,000 +And all these tools + +196 +00:07:00,000 --> 00:07:02,000 +are going to implement that specification. + +197 +00:07:02,000 --> 00:07:05,000 +Now what will happen is, even if you change your library + +198 +00:07:05,000 --> 00:07:07,000 +from Hibernate to something else, + +199 +00:07:07,000 --> 00:07:09,000 +you don't have to change a lot of your code + +200 +00:07:09,000 --> 00:07:11,000 +because you have not specified it for Hibernate. + +201 +00:07:11,000 --> 00:07:14,000 +You have worked with that specification. + +202 +00:07:14,000 --> 00:07:18,000 +And that specification is called JPA, + +203 +00:07:18,000 --> 00:07:21,000 +which is Java Persistence API, okay? + +204 +00:07:21,000 --> 00:07:24,000 +And Hibernate basically implements JPA. + +205 +00:07:24,000 --> 00:07:24,000 +It's awesome, right? + +206 +00:07:24,000 --> 00:07:28,000 +Likewise, we have something called Spring ORM, okay? + +207 +00:07:28,000 --> 00:07:31,000 +So in Spring, we can use Spring ORM to achieve that. + +208 +00:07:31,000 --> 00:07:33,000 +So if you are using Hibernate, + +209 +00:07:33,000 --> 00:07:34,000 +it provides you some extra features. + +210 +00:07:34,000 --> 00:07:36,000 +But then Spring ORM connects + +211 +00:07:36,000 --> 00:07:39,000 +with a Spring framework in a good way. + +212 +00:07:39,000 --> 00:07:40,000 +So you can use Spring ORM there. + +213 +00:07:40,000 --> 00:07:42,000 +Both this, Hibernate and Spring ORM, + +214 +00:07:42,000 --> 00:07:44,000 +basically implements the JPA. + +215 +00:07:44,000 --> 00:07:46,000 +Now if you try to use Hibernate, of course, + +216 +00:07:46,000 --> 00:07:48,000 +we can do that in this project. + +217 +00:07:48,000 --> 00:07:51,000 +But if you try to use Hibernate or Spring ORM, + +218 +00:07:51,000 --> 00:07:53,000 +you will have to write a lot of code. + +219 +00:07:53,000 --> 00:07:57,000 +And that can be simplified with Spring Data JPA. + +220 +00:07:57,000 --> 00:08:01,000 +So Spring Data JPA is a module in Spring ecosystem, + +221 +00:08:01,000 --> 00:08:02,000 +which will simplify your task + +222 +00:08:02,000 --> 00:08:04,000 +and you can build this projects + +223 +00:08:04,000 --> 00:08:07,000 +or you can have that layer of repository + +224 +00:08:07,000 --> 00:08:09,000 +in a very easy and simple way. + +225 +00:08:09,000 --> 00:08:12,000 +You'll be giving a short code there, but how do we use it? + +226 +00:08:12,000 --> 00:08:14,000 +Let's see that in the next video. + diff --git a/16 - Spring Data JPA/003 Creating Table And Inserting Data_en.srt b/16 - Spring Data JPA/003 Creating Table And Inserting Data_en.srt new file mode 100644 index 0000000000000000000000000000000000000000..f1a01eccf9276e9eef98207b588617d6a3073791 --- /dev/null +++ b/16 - Spring Data JPA/003 Creating Table And Inserting Data_en.srt @@ -0,0 +1,1364 @@ +1 +00:00:03,000 --> 00:00:05,000 +-: So let's start our discussion + +2 +00:00:05,000 --> 00:00:07,000 +with this Spring JDBC project. + +3 +00:00:07,000 --> 00:00:10,000 +Now, as I mentioned before, we have done the same thing, + +4 +00:00:10,000 --> 00:00:12,000 +but then we have used JDBC, + +5 +00:00:12,000 --> 00:00:15,000 +in which in the repository layer we have + +6 +00:00:15,000 --> 00:00:16,000 +to write all these lines of code. + +7 +00:00:16,000 --> 00:00:19,000 +Just remember that we have written multiple lines + +8 +00:00:19,000 --> 00:00:23,000 +of code here, but also when we wanted to create the table, + +9 +00:00:23,000 --> 00:00:25,000 +we have also returned this code. + +10 +00:00:25,000 --> 00:00:27,000 +Remember, we have created this schema dot sql? + +11 +00:00:27,000 --> 00:00:30,000 +we don't have to do that in the Spring data JDBC project. + +12 +00:00:30,000 --> 00:00:32,000 +How, let's do that. + +13 +00:00:32,000 --> 00:00:33,000 +So what I will do is let's create a new project + +14 +00:00:33,000 --> 00:00:35,000 +and we'll use some of the code from this + +15 +00:00:35,000 --> 00:00:36,000 +file to create a project. + +16 +00:00:36,000 --> 00:00:39,000 +I will go to Spring initializer + +17 +00:00:39,000 --> 00:00:41,000 +and I'm going to create a avenue project. + +18 +00:00:41,000 --> 00:00:43,000 +This is the Springboard version. + +19 +00:00:43,000 --> 00:00:46,000 +I would say this is com dot tolusko which is my group ID. + +20 +00:00:46,000 --> 00:00:48,000 +The project is Spring + +21 +00:00:48,000 --> 00:00:52,000 +data JPA example, + +22 +00:00:53,000 --> 00:00:56,000 +and I'm going to use Java 21 here. + +23 +00:00:56,000 --> 00:00:58,000 +Packaging is Jar. + +24 +00:00:58,000 --> 00:00:59,000 +Now what about dependencies? + +25 +00:00:59,000 --> 00:01:01,000 +Now this will be tricky. + +26 +00:01:01,000 --> 00:01:04,000 +So first of all, we need data JPA. + +27 +00:01:04,000 --> 00:01:07,000 +So you have to search for Spring data JPA. + +28 +00:01:07,000 --> 00:01:10,000 +So as you can see it says persist data in SQL store + +29 +00:01:10,000 --> 00:01:12,000 +with the Java Persistence API + +30 +00:01:12,000 --> 00:01:13,000 +using Spring data and hibernate. + +31 +00:01:13,000 --> 00:01:17,000 +So behind the scene it uses the hibernate as a tool. + +32 +00:01:17,000 --> 00:01:19,000 +So we are using Spring data, JPA, + +33 +00:01:19,000 --> 00:01:21,000 +data JPA will use hibernate + +34 +00:01:21,000 --> 00:01:25,000 +because JPA is just a specification. + +35 +00:01:25,000 --> 00:01:26,000 +Okay? + +36 +00:01:26,000 --> 00:01:28,000 +Okay, next we need a database driver. + +37 +00:01:28,000 --> 00:01:30,000 +So if you want to use Edge two, you can download, + +38 +00:01:30,000 --> 00:01:32,000 +you can get Edge two, but I'm going to use Postgre. + +39 +00:01:32,000 --> 00:01:35,000 +So I'm directly going for PostgreSQL, and that's it. + +40 +00:01:35,000 --> 00:01:37,000 +These are the two libraries we need + +41 +00:01:37,000 --> 00:01:39,000 +and we are not building a web application here. + +42 +00:01:39,000 --> 00:01:42,000 +Once we go back to our job application, + +43 +00:01:42,000 --> 00:01:45,000 +we are going to integrate with the web as well. + +44 +00:01:45,000 --> 00:01:47,000 +But at this point, let's say we are building a + +45 +00:01:47,000 --> 00:01:50,000 +console application with the help of Spring data JPA. + +46 +00:01:50,000 --> 00:01:51,000 +And click on generate, + +47 +00:01:51,000 --> 00:01:54,000 +it'll give me a project which I have to unzip. + +48 +00:01:54,000 --> 00:01:57,000 +So got the project, unzip it + +49 +00:01:57,000 --> 00:02:01,000 +and let me open the project, open and done. + +50 +00:02:01,000 --> 00:02:02,000 +So I want to open this a new window + +51 +00:02:02,000 --> 00:02:04,000 +because I want to copy some code from there. + +52 +00:02:04,000 --> 00:02:08,000 +So you can see I do have my Spring Data JDBC project here. + +53 +00:02:08,000 --> 00:02:09,000 +Click on here. + +54 +00:02:09,000 --> 00:02:10,000 +Okay, what are things I'm going to copy + +55 +00:02:10,000 --> 00:02:13,000 +from the Spring JDBC? + +56 +00:02:13,000 --> 00:02:15,000 +I need the model class because I don't know, topic. + +57 +00:02:15,000 --> 00:02:16,000 +Copy it. + +58 +00:02:16,000 --> 00:02:18,000 +So I will put that in a model package. + +59 +00:02:18,000 --> 00:02:22,000 +So in the src, go to map main Java. + +60 +00:02:22,000 --> 00:02:25,000 +And this I'm going to create a model, + +61 +00:02:25,000 --> 00:02:28,000 +okay, not a class but a package. + +62 +00:02:28,000 --> 00:02:30,000 +New package. I will say model. + +63 +00:02:30,000 --> 00:02:34,000 +And let me put the string class here, that's one. + +64 +00:02:34,000 --> 00:02:37,000 +Next I need a service. + +65 +00:02:37,000 --> 00:02:38,000 +In fact, you know, let's skip service + +66 +00:02:38,000 --> 00:02:41,000 +because what service is doing is service is simply + +67 +00:02:41,000 --> 00:02:44,000 +taking our data and sending it to Depo. + +68 +00:02:44,000 --> 00:02:44,000 +Can we skip that? + +69 +00:02:44,000 --> 00:02:47,000 +Yes we can, so let's not use service. + +70 +00:02:47,000 --> 00:02:49,000 +And that's it, those are the thing. + +71 +00:02:49,000 --> 00:02:51,000 +That's one class we need. + +72 +00:02:51,000 --> 00:02:52,000 +I think we'll take one more. + +73 +00:02:52,000 --> 00:02:53,000 +In the applicant properties, + +74 +00:02:53,000 --> 00:02:56,000 +remember we have done the configuration for Postgres. + +75 +00:02:56,000 --> 00:02:58,000 +How do you connect with Postgres? + +76 +00:02:58,000 --> 00:02:59,000 +So I will need the same thing. + +77 +00:02:59,000 --> 00:03:01,000 +I will just copy that. + +78 +00:03:01,000 --> 00:03:04,000 +Go back to my project in the resources application + +79 +00:03:04,000 --> 00:03:06,000 +properties, let's page it here. + +80 +00:03:06,000 --> 00:03:07,000 +But we have to also make sure + +81 +00:03:07,000 --> 00:03:10,000 +that we don't have a table called student in the database. + +82 +00:03:10,000 --> 00:03:13,000 +So in this database status quo, I have to make sure + +83 +00:03:13,000 --> 00:03:18,000 +that I don't have the student class or student table. + +84 +00:03:18,000 --> 00:03:19,000 +So let me open my PG admin, + +85 +00:03:19,000 --> 00:03:20,000 +which will take some time to open. + +86 +00:03:20,000 --> 00:03:23,000 +Okay, so I got my PG admin open + +87 +00:03:23,000 --> 00:03:25,000 +and now I will just enter a password which is + +88 +00:03:25,000 --> 00:03:28,000 +zero, zero, zero in this case, four times zero. + +89 +00:03:28,000 --> 00:03:33,000 +And if I expand my servers, I do have a Postgre, SQL here. + +90 +00:03:33,000 --> 00:03:36,000 +And if you can see we have telusko database + +91 +00:03:36,000 --> 00:03:38,000 +and we also have a student class. + +92 +00:03:38,000 --> 00:03:41,000 +Let me delete table, sorry, let me delete this. + +93 +00:03:41,000 --> 00:03:44,000 +I will just say delete the table and done. + +94 +00:03:44,000 --> 00:03:47,000 +Now we don't have any table called student. + +95 +00:03:47,000 --> 00:03:49,000 +Okay that's one thing which have to make sure, + +96 +00:03:49,000 --> 00:03:53,000 +let me go back to my code, which is this + +97 +00:03:53,000 --> 00:03:55,000 +and let's write our code for, + +98 +00:03:57,000 --> 00:03:59,000 +okay, let me close this. + +99 +00:03:59,000 --> 00:04:00,000 +Spring Data JDBC. + +100 +00:04:00,000 --> 00:04:01,000 +Let's only focus on data JPA. + +101 +00:04:01,000 --> 00:04:03,000 +Okay, so what we got is we got a student class, + +102 +00:04:03,000 --> 00:04:04,000 +which is a very simple class. + +103 +00:04:04,000 --> 00:04:06,000 +We got three variables, rule number, name + +104 +00:04:06,000 --> 00:04:10,000 +and marks, importing packages, code, nothing, no problem. + +105 +00:04:10,000 --> 00:04:12,000 +We got application properties. + +106 +00:04:12,000 --> 00:04:14,000 +And now let me go back to the main file. + +107 +00:04:14,000 --> 00:04:17,000 +Now this is where basically we have to + +108 +00:04:17,000 --> 00:04:19,000 +create the object for student. + +109 +00:04:19,000 --> 00:04:21,000 +And the way you can do that, first of all, I just want + +110 +00:04:21,000 --> 00:04:23,000 +to get the hold on the application context. + +111 +00:04:23,000 --> 00:04:26,000 +I'll say context equal to, + +112 +00:04:26,000 --> 00:04:29,000 +and then let me create the object for student. + +113 +00:04:29,000 --> 00:04:32,000 +So I'll say student S one equal to + +114 +00:04:32,000 --> 00:04:36,000 +context dot getBean + +115 +00:04:36,000 --> 00:04:39,000 +I want the object for student dot class + +116 +00:04:39,000 --> 00:04:41,000 +and not just one maybe I need three, + +117 +00:04:41,000 --> 00:04:42,000 +at least three students. + +118 +00:04:42,000 --> 00:04:44,000 +And let's set some data for that. + +119 +00:04:44,000 --> 00:04:48,000 +So we'll say S1 dot set roll number 101. + +120 +00:04:48,000 --> 00:04:51,000 +Okay, so you can see we got this three student object here + +121 +00:04:51,000 --> 00:04:54,000 +and now we just have to store that in database. + +122 +00:04:54,000 --> 00:04:56,000 +Now in this project basically we were able + +123 +00:04:56,000 --> 00:04:59,000 +to set the properties for the database. + +124 +00:04:59,000 --> 00:05:01,000 +You can see we are doing that here + +125 +00:05:01,000 --> 00:05:03,000 +and we do have a class student. + +126 +00:05:03,000 --> 00:05:07,000 +Right, now I just want to store the data in database. + +127 +00:05:07,000 --> 00:05:08,000 +Now that's tricky, right? + +128 +00:05:08,000 --> 00:05:09,000 +How we are going to do that? + +129 +00:05:09,000 --> 00:05:12,000 +Now basically if you want to store this data in database, + +130 +00:05:12,000 --> 00:05:15,000 +we have to make sure that we use JPA. + +131 +00:05:15,000 --> 00:05:18,000 +And the way you do that is by creating a repository. + +132 +00:05:18,000 --> 00:05:20,000 +So let me create a new class + +133 +00:05:20,000 --> 00:05:23,000 +and we'll say this is a student repo + +134 +00:05:23,000 --> 00:05:26,000 +and we have done the same thing in JDBC as well. + +135 +00:05:26,000 --> 00:05:29,000 +But the difference is here, I'm not going to create a class, + +136 +00:05:29,000 --> 00:05:31,000 +let me create the interface, okay? + +137 +00:05:31,000 --> 00:05:32,000 +Just be with me and you will see the magic. + +138 +00:05:32,000 --> 00:05:36,000 +And here let me extend this particular interface + +139 +00:05:36,000 --> 00:05:39,000 +to something called A JPA repository. + +140 +00:05:39,000 --> 00:05:41,000 +Now this is something new right. + +141 +00:05:41,000 --> 00:05:42,000 +Now this is interface. + +142 +00:05:42,000 --> 00:05:44,000 +We got this interface because we have added the library + +143 +00:05:44,000 --> 00:05:48,000 +for Spring data JPA and we are getting from there. + +144 +00:05:48,000 --> 00:05:50,000 +Now it'll just ask you for two things. + +145 +00:05:50,000 --> 00:05:52,000 +First, which class type of you're working with. + +146 +00:05:52,000 --> 00:05:54,000 +So I'm working with student type of class + +147 +00:05:54,000 --> 00:05:56,000 +and what is a type of primary key? + +148 +00:05:56,000 --> 00:05:59,000 +Now table needs a primary key. + +149 +00:05:59,000 --> 00:06:01,000 +And if you go back to a student, what do you think? + +150 +00:06:01,000 --> 00:06:03,000 +Which one looks more like a primary key? + +151 +00:06:03,000 --> 00:06:04,000 +Of course role number, right? + +152 +00:06:04,000 --> 00:06:06,000 +And the type of role number is integer. + +153 +00:06:06,000 --> 00:06:09,000 +So you have to mention that here, integer. + +154 +00:06:09,000 --> 00:06:11,000 +So the type of student, you have to specify that, + +155 +00:06:11,000 --> 00:06:14,000 +the type of object you're working with, and that's it. + +156 +00:06:14,000 --> 00:06:16,000 +You just need to add this + +157 +00:06:16,000 --> 00:06:17,000 +and let's see what happens. + +158 +00:06:17,000 --> 00:06:20,000 +We just have to make sure that we add a repository + +159 +00:06:20,000 --> 00:06:21,000 +orientation on top of it. + +160 +00:06:21,000 --> 00:06:25,000 +Remember when we talked about making a managed bin + +161 +00:06:25,000 --> 00:06:28,000 +for a normal class we use component for controllers, + +162 +00:06:28,000 --> 00:06:31,000 +we use controller for service clear we use service. + +163 +00:06:31,000 --> 00:06:34,000 +And for repository layer we use add repository. + +164 +00:06:34,000 --> 00:06:36,000 +Okay, that's it, nothing much. + +165 +00:06:36,000 --> 00:06:39,000 +And now we can just go back to application. + +166 +00:06:39,000 --> 00:06:43,000 +I need the object of repository as well. + +167 +00:06:43,000 --> 00:06:44,000 +So just go back here + +168 +00:06:44,000 --> 00:06:49,000 +and say hey, you know, I just want object for repository, + +169 +00:06:49,000 --> 00:06:51,000 +which is student repo. + +170 +00:06:51,000 --> 00:06:54,000 +repo is equal to, I will get it from the context + +171 +00:06:54,000 --> 00:06:56,000 +of the context dot getBean.. + +172 +00:06:56,000 --> 00:07:01,000 +I want the object for student repo dot class. + +173 +00:07:01,000 --> 00:07:03,000 +Okay, so basically I want the reposit, + +174 +00:07:03,000 --> 00:07:05,000 +I got the repository object. + +175 +00:07:05,000 --> 00:07:08,000 +So we got three students and we got the repository object. + +176 +00:07:08,000 --> 00:07:12,000 +Now when I try to say repository dot. + +177 +00:07:12,000 --> 00:07:15,000 +Now of course you should not get any op, any method here + +178 +00:07:15,000 --> 00:07:18,000 +because in the repository, which is the interface, + +179 +00:07:18,000 --> 00:07:20,000 +first of all, we don't even have a class + +180 +00:07:20,000 --> 00:07:23,000 +and which we don't have any methods here, right? + +181 +00:07:23,000 --> 00:07:25,000 +We have not even declared them. + +182 +00:07:25,000 --> 00:07:27,000 +But if you go back to your main, + +183 +00:07:27,000 --> 00:07:28,000 +and if you say report dot, + +184 +00:07:28,000 --> 00:07:30,000 +you can see we have so many methods. + +185 +00:07:30,000 --> 00:07:32,000 +Now this is weird. + +186 +00:07:32,000 --> 00:07:34,000 +Now push your eyes from where you're getting these methods. + +187 +00:07:34,000 --> 00:07:36,000 +Maybe you're getting these methods from + +188 +00:07:37,000 --> 00:07:40,000 +this particular interface JPA repository. + +189 +00:07:40,000 --> 00:07:43,000 +And if you click on that, yes, it has a lot of methods. + +190 +00:07:43,000 --> 00:07:46,000 +Additionally, this JPA repository also extends from the + +191 +00:07:46,000 --> 00:07:48,000 +least credit repository + +192 +00:07:48,000 --> 00:07:50,000 +and the least cloud repository extends from + +193 +00:07:50,000 --> 00:07:52,000 +the third repository. + +194 +00:07:52,000 --> 00:07:54,000 +In the cloud we have all the credit operations. + +195 +00:07:54,000 --> 00:07:58,000 +You know, we have delete, save, find, okay. + +196 +00:07:58,000 --> 00:07:59,000 +So we got all these methods + +197 +00:07:59,000 --> 00:08:03,000 +and that's why if you see when you say dot, + +198 +00:08:03,000 --> 00:08:04,000 +we are getting all these methods, + +199 +00:08:04,000 --> 00:08:06,000 +but logically it should not work is + +200 +00:08:06,000 --> 00:08:09,000 +because we have created the interface, not the class. + +201 +00:08:09,000 --> 00:08:11,000 +And we have not specified. + +202 +00:08:11,000 --> 00:08:12,000 +When you say save, what it means, + +203 +00:08:12,000 --> 00:08:14,000 +when you say delete what it means. + +204 +00:08:14,000 --> 00:08:16,000 +But still I will try to do that. + +205 +00:08:16,000 --> 00:08:20,000 +Still I will try to say save and S one. + +206 +00:08:20,000 --> 00:08:21,000 +I just want to test out + +207 +00:08:21,000 --> 00:08:24,000 +and let's see what others you get. + +208 +00:08:24,000 --> 00:08:25,000 +And of course I know as I mentioned + +209 +00:08:25,000 --> 00:08:27,000 +before, you learn from the others. + +210 +00:08:27,000 --> 00:08:30,000 +And when I click this and say run, what worst can happen. + +211 +00:08:30,000 --> 00:08:32,000 +It'll give you error, let's see. + +212 +00:08:32,000 --> 00:08:34,000 +Yeah, so we were expecting error, we got the error. + +213 +00:08:34,000 --> 00:08:38,000 +Maybe it says, hey, you know why you're trying to save. + +214 +00:08:38,000 --> 00:08:39,000 +I mean where is the implementation for that? + +215 +00:08:39,000 --> 00:08:42,000 +Where is the implementation for your student + +216 +00:08:42,000 --> 00:08:43,000 +repo or which is the interface? + +217 +00:08:43,000 --> 00:08:45,000 +But it says something else. + +218 +00:08:45,000 --> 00:08:49,000 +It says either creating a bean name, + +219 +00:08:49,000 --> 00:08:53,000 +a student repo defined in this, + +220 +00:08:53,000 --> 00:08:57,000 +declared on JPA not a managed bean of type student. + +221 +00:08:57,000 --> 00:09:01,000 +Okay, so student is not a bean, it's a component, okay. + +222 +00:09:01,000 --> 00:09:04,000 +Not able to get the solution. + +223 +00:09:04,000 --> 00:09:07,000 +But if you see, cause it says something else. + +224 +00:09:07,000 --> 00:09:10,000 +But if you say cause it says the same thing, okay/ + +225 +00:09:10,000 --> 00:09:14,000 +So basically what happens is when you go back to student, + +226 +00:09:14,000 --> 00:09:18,000 +we are expecting that the framework should create a table + +227 +00:09:18,000 --> 00:09:21,000 +based on this student object, right, Student class. + +228 +00:09:21,000 --> 00:09:22,000 +Now to achieve that, we have + +229 +00:09:22,000 --> 00:09:26,000 +to use something called at entity. + +230 +00:09:26,000 --> 00:09:29,000 +Now what happens is in the database we treat every table + +231 +00:09:29,000 --> 00:09:31,000 +as an entity, right. + +232 +00:09:31,000 --> 00:09:32,000 +And the way you can achieve that, + +233 +00:09:32,000 --> 00:09:35,000 +the way you can create a table from a class is by writing + +234 +00:09:35,000 --> 00:09:37,000 +at entity on top of it, okay. + +235 +00:09:37,000 --> 00:09:40,000 +That should solve the problem and will it? + +236 +00:09:40,000 --> 00:09:41,000 +Let's try. + +237 +00:09:41,000 --> 00:09:44,000 +So we just relaunched the application expecting + +238 +00:09:44,000 --> 00:09:45,000 +a different error at this time. + +239 +00:09:45,000 --> 00:09:47,000 +And yeah, we got the error, but, + +240 +00:09:47,000 --> 00:09:49,000 +and you can see we have a different error. + +241 +00:09:49,000 --> 00:09:52,000 +Now it's not saying that this, it is not managed, + +242 +00:09:52,000 --> 00:09:55,000 +but it says the student has no identifier. + +243 +00:09:55,000 --> 00:09:57,000 +Okay, now what do you mean by identifier? + +244 +00:09:57,000 --> 00:09:59,000 +Every table needs a primary key + +245 +00:09:59,000 --> 00:10:02,000 +and to achieve the primary key, it also mentioned that + +246 +00:10:02,000 --> 00:10:04,000 +what you can do, so you can see it says at least + +247 +00:10:04,000 --> 00:10:06,000 +one ID should be there. + +248 +00:10:06,000 --> 00:10:08,000 +So what I will do is I will make the + +249 +00:10:08,000 --> 00:10:09,000 +role number as a primary key. + +250 +00:10:09,000 --> 00:10:13,000 +And the way you do that is by using at ID, okay. + +251 +00:10:13,000 --> 00:10:14,000 +So you're saying at ID, + +252 +00:10:14,000 --> 00:10:18,000 +which means let's make the role number as a primary key. + +253 +00:10:18,000 --> 00:10:22,000 +Okay, let's try once again now and let's see what happens. + +254 +00:10:22,000 --> 00:10:23,000 +Okay, again, we got the error, + +255 +00:10:23,000 --> 00:10:25,000 +but this time we have a different error. + +256 +00:10:25,000 --> 00:10:26,000 +You know what it says? + +257 +00:10:26,000 --> 00:10:30,000 +It says the student table does not exist. + +258 +00:10:30,000 --> 00:10:31,000 +See, that's a different thing, right? + +259 +00:10:31,000 --> 00:10:32,000 +It says table not exist. + +260 +00:10:32,000 --> 00:10:34,000 +I know we don't have that table, + +261 +00:10:34,000 --> 00:10:37,000 +but it is trying to save it. + +262 +00:10:37,000 --> 00:10:38,000 +I mean that's weird. + +263 +00:10:38,000 --> 00:10:40,000 +We have not done any code + +264 +00:10:40,000 --> 00:10:43,000 +to say the SQL queries or something. + +265 +00:10:43,000 --> 00:10:46,000 +We are simply using an interface which is, + +266 +00:10:46,000 --> 00:10:51,000 +which says student repo and we are saying save here. + +267 +00:10:51,000 --> 00:10:52,000 +And it it is trying to save it. + +268 +00:10:52,000 --> 00:10:55,000 +What it is not able to find is a table. + +269 +00:10:55,000 --> 00:10:56,000 +What if you can create a table? + +270 +00:10:56,000 --> 00:10:57,000 +Will it work? + +271 +00:10:57,000 --> 00:10:58,000 +Of course, right? + +272 +00:10:58,000 --> 00:10:59,000 +But you know what? + +273 +00:10:59,000 --> 00:11:02,000 +I am bit lazy. + +274 +00:11:02,000 --> 00:11:06,000 +I want my application to create a table. + +275 +00:11:06,000 --> 00:11:07,000 +And the way you can do that is + +276 +00:11:07,000 --> 00:11:10,000 +by adding some properties here. + +277 +00:11:10,000 --> 00:11:12,000 +Now basically Spring is using + +278 +00:11:12,000 --> 00:11:14,000 +hibernate behind the scenes, right? + +279 +00:11:14,000 --> 00:11:15,000 +And it is searching for the table. + +280 +00:11:15,000 --> 00:11:18,000 +What if we say, hey hibernate, + +281 +00:11:18,000 --> 00:11:20,000 +you have to create a table for us. + +282 +00:11:20,000 --> 00:11:24,000 +And the way you can do that is by saying, Spring dot jpa, + +283 +00:11:24,000 --> 00:11:28,000 +dot hyphenate dot ddl hypen auto. + +284 +00:11:28,000 --> 00:11:32,000 +Now DDL stands for Data Definition Language. + +285 +00:11:32,000 --> 00:11:35,000 +So when you want to create a table, delete that table + +286 +00:11:35,000 --> 00:11:36,000 +that comes on the ddl. + +287 +00:11:36,000 --> 00:11:40,000 +So we are saying by default you should be creating a table. + +288 +00:11:40,000 --> 00:11:43,000 +So when you say it, Spring dot jpa dot hyphenate dot ddl, + +289 +00:11:43,000 --> 00:11:45,000 +auto create, it'll create a table. + +290 +00:11:45,000 --> 00:11:47,000 +But the problem is it'll create a table every + +291 +00:11:47,000 --> 00:11:49,000 +time you load the application. + +292 +00:11:49,000 --> 00:11:50,000 +We don't want that, we don't want it + +293 +00:11:50,000 --> 00:11:52,000 +to create table every time. + +294 +00:11:52,000 --> 00:11:54,000 +So it will drop the old table, create new table. + +295 +00:11:54,000 --> 00:11:56,000 +What we can say is we can say update. + +296 +00:11:56,000 --> 00:11:59,000 +Update means if you don't have a table, create one. + +297 +00:11:59,000 --> 00:12:02,000 +But if you have a table, just update it, that's one. + +298 +00:12:02,000 --> 00:12:06,000 +Next I also want to see the query. It fires. + +299 +00:12:06,000 --> 00:12:11,000 +That's right, you are not writing any query, + +300 +00:12:11,000 --> 00:12:13,000 +but behind the scene hibernate will + +301 +00:12:13,000 --> 00:12:15,000 +generate a query for you. + +302 +00:12:15,000 --> 00:12:16,000 +See, ultimately your databases + +303 +00:12:16,000 --> 00:12:19,000 +on IDBMS runs with SQL Query. + +304 +00:12:19,000 --> 00:12:20,000 +So who will get the SQ query? + +305 +00:12:20,000 --> 00:12:22,000 +It is your hibernate. + +306 +00:12:22,000 --> 00:12:24,000 +And we want to see what query it creates. + +307 +00:12:24,000 --> 00:12:28,000 +So I will say Spring dot jpa dot + +308 +00:12:28,000 --> 00:12:30,000 +show SQL is equal to true. + +309 +00:12:30,000 --> 00:12:31,000 +It'll show the query it was. + +310 +00:12:31,000 --> 00:12:33,000 +Now let's see if this works. + +311 +00:12:33,000 --> 00:12:37,000 +Let's relaunch the application after making those changes. + +312 +00:12:37,000 --> 00:12:41,000 +And if you see the output, oh, can you see that? + +313 +00:12:41,000 --> 00:12:44,000 +It says create insert into student. + +314 +00:12:44,000 --> 00:12:47,000 +We are inserting data, that's weird. + +315 +00:12:47,000 --> 00:12:49,000 +It is also creating a table. + +316 +00:12:49,000 --> 00:12:51,000 +So it says create table student + +317 +00:12:52,000 --> 00:12:54,000 +with this role number, which is integer. + +318 +00:12:54,000 --> 00:12:57,000 +Marks, which is Integer, + +319 +00:12:57,000 --> 00:12:58,000 +name, which is wildcard. + +320 +00:12:58,000 --> 00:13:00,000 +And that's a primary key. + +321 +00:13:01,000 --> 00:13:04,000 +Awesome, I mean we have a primary key which is role number + +322 +00:13:04,000 --> 00:13:07,000 +and now let's verify that from the PG admin. + +323 +00:13:07,000 --> 00:13:10,000 +Let's go to database and let's refresh my database. + +324 +00:13:10,000 --> 00:13:13,000 +I will say refresh. + +325 +00:13:13,000 --> 00:13:14,000 +We got the table. + +326 +00:13:14,000 --> 00:13:16,000 +Let's see, right leg + +327 +00:13:17,000 --> 00:13:19,000 +view all rows + +328 +00:13:21,000 --> 00:13:22,000 +and boom. + +329 +00:13:23,000 --> 00:13:26,000 +We have not returned any quality in the project + +330 +00:13:26,000 --> 00:13:28,000 +and see the project, there is no query. + +331 +00:13:28,000 --> 00:13:29,000 +We just created this file + +332 +00:13:29,000 --> 00:13:31,000 +where we are saying we got the data. + +333 +00:13:31,000 --> 00:13:33,000 +Just say save. + +334 +00:13:33,000 --> 00:13:35,000 +We got a student class, which is simple class. + +335 +00:13:35,000 --> 00:13:37,000 +We have set some properties here. + +336 +00:13:37,000 --> 00:13:39,000 +And repo is just an interface. + +337 +00:13:39,000 --> 00:13:40,000 +And that's the beauty. + +338 +00:13:40,000 --> 00:13:43,000 +This is your Spring data, JPA. + +339 +00:13:43,000 --> 00:13:45,000 +And we have just saved it. + +340 +00:13:45,000 --> 00:13:46,000 +But what about fetching data? + +341 +00:13:46,000 --> 00:13:48,000 +Let's see that in the next video. + diff --git a/16 - Spring Data JPA/003 Source-Code.url b/16 - Spring Data JPA/003 Source-Code.url new file mode 100644 index 0000000000000000000000000000000000000000..862a73e4dbb653caea0fa3270dd902278040f069 --- /dev/null +++ b/16 - Spring Data JPA/003 Source-Code.url @@ -0,0 +1,2 @@ +[InternetShortcut] +URL=https://github.com/navinreddy20/spring6-course/tree/36d783117044564847940ba5046b35cc59f55346/10%20Spring%20DataJPA/9.3%20Creating%20Table%20And%20Inserting%20Data/spring-data-jpa-ex \ No newline at end of file diff --git a/16 - Spring Data JPA/004 Source-Code.url b/16 - Spring Data JPA/004 Source-Code.url new file mode 100644 index 0000000000000000000000000000000000000000..5a60faa99f4bc9c50f303109a449da9496a73663 --- /dev/null +++ b/16 - Spring Data JPA/004 Source-Code.url @@ -0,0 +1,2 @@ +[InternetShortcut] +URL=https://github.com/navinreddy20/spring6-course/tree/36d783117044564847940ba5046b35cc59f55346/10%20Spring%20DataJPA/9.4%20Findall/spring-data-jpa-ex \ No newline at end of file diff --git a/16 - Spring Data JPA/005 Source-Code.url b/16 - Spring Data JPA/005 Source-Code.url new file mode 100644 index 0000000000000000000000000000000000000000..4bdf2d99cb21eb274ae1ff704dd5ac349471bf17 --- /dev/null +++ b/16 - Spring Data JPA/005 Source-Code.url @@ -0,0 +1,2 @@ +[InternetShortcut] +URL=https://github.com/navinreddy20/spring6-course/tree/fa914a08f0f89f7d8a8a16362d928b0bdb45d337/10%20Spring%20DataJPA/9.5%20Findbyid/spring-data-jpa-ex3 \ No newline at end of file diff --git a/16 - Spring Data JPA/005 findById_en.srt b/16 - Spring Data JPA/005 findById_en.srt new file mode 100644 index 0000000000000000000000000000000000000000..9f639a14b9c01f04d0f26a9aca16abbc9b129e97 --- /dev/null +++ b/16 - Spring Data JPA/005 findById_en.srt @@ -0,0 +1,352 @@ +1 +00:00:00,000 --> 00:00:03,000 +(gentle music) + +2 +00:00:03,000 --> 00:00:05,000 +-: So basically, we were able to get the data, right? + +3 +00:00:05,000 --> 00:00:07,000 +So when you say find all, + +4 +00:00:07,000 --> 00:00:09,000 +basically you are receiving everything, + +5 +00:00:09,000 --> 00:00:13,000 +but now, we want to fetch, let's say, one element, not all. + +6 +00:00:13,000 --> 00:00:14,000 +Now what you want to fetch? + +7 +00:00:14,000 --> 00:00:16,000 +So let's go back to our PG admin. + +8 +00:00:16,000 --> 00:00:17,000 +So we got our PG admin. + +9 +00:00:17,000 --> 00:00:20,000 +If I go to PostgreSQL, + +10 +00:00:20,000 --> 00:00:22,000 +and if you go back to student + +11 +00:00:22,000 --> 00:00:24,000 +just to see what data we have, + +12 +00:00:24,000 --> 00:00:27,000 +and this is the data, right, which is, yeah. + +13 +00:00:27,000 --> 00:00:30,000 +So we got 101, Navin, 102, Kiran, 103, Harsh. + +14 +00:00:30,000 --> 00:00:32,000 +So we got all this data. + +15 +00:00:32,000 --> 00:00:35,000 +I want to fetch one particular row here. + +16 +00:00:35,000 --> 00:00:37,000 +Let's say I want to fetch 103. + +17 +00:00:37,000 --> 00:00:40,000 +So what you can do is you can go back to your code + +18 +00:00:40,000 --> 00:00:44,000 +and instead of saying findAll, we'll not do that now, + +19 +00:00:44,000 --> 00:00:45,000 +we can find different method. + +20 +00:00:45,000 --> 00:00:47,000 +So if you say .repo, + +21 +00:00:47,000 --> 00:00:50,000 +we have different methods apart from find all. + +22 +00:00:50,000 --> 00:00:52,000 +If you go down, there's also count, + +23 +00:00:52,000 --> 00:00:55,000 +which will give you the number of rows you have, + +24 +00:00:55,000 --> 00:01:00,000 +but we want to go with this, which is called find by ID. + +25 +00:01:00,000 --> 00:01:02,000 +Now find by ID is a special method, + +26 +00:01:02,000 --> 00:01:06,000 +which will give you a row based on the primary key. + +27 +00:01:06,000 --> 00:01:09,000 +Now what value you want to go for, let's say 103. + +28 +00:01:09,000 --> 00:01:11,000 +Of course, you can ask this value from the user, + +29 +00:01:11,000 --> 00:01:13,000 +but let's try 103 here + +30 +00:01:13,000 --> 00:01:15,000 +And now with this, if you run this code, + +31 +00:01:15,000 --> 00:01:18,000 +so you can see we got it is filing a select query, + +32 +00:01:18,000 --> 00:01:22,000 +which is select, roll number, marks, name from student + +33 +00:01:22,000 --> 00:01:24,000 +where the roll number is equal to... + +34 +00:01:24,000 --> 00:01:27,000 +So whatever value you mentioned, it will search for that. + +35 +00:01:27,000 --> 00:01:28,000 +Now basically why roll number + +36 +00:01:28,000 --> 00:01:30,000 +is because roll number is our primary key, right? + +37 +00:01:30,000 --> 00:01:33,000 +And we got the data, which is this. + +38 +00:01:33,000 --> 00:01:36,000 +But also if you see, it says optional. + +39 +00:01:36,000 --> 00:01:37,000 +Now why it is optional? + +40 +00:01:37,000 --> 00:01:40,000 +So what I will do is I will try to say repo.findById, + +41 +00:01:43,000 --> 00:01:46,000 +and if you see the written type of this, + +42 +00:01:46,000 --> 00:01:48,000 +this returns an optional. + +43 +00:01:48,000 --> 00:01:51,000 +Now, to secure yourself from null point exception, + +44 +00:01:51,000 --> 00:01:54,000 +because that's a very common error, right, + +45 +00:01:54,000 --> 00:01:55,000 +what if you are searching for something? + +46 +00:01:55,000 --> 00:01:57,000 +Let's say you're searching for 104, + +47 +00:01:57,000 --> 00:01:58,000 +and we don't have this data, + +48 +00:01:58,000 --> 00:02:00,000 +so it will return you null, right? + +49 +00:02:00,000 --> 00:02:03,000 +So if you're trying to accept that into a student object, + +50 +00:02:03,000 --> 00:02:07,000 +so if I say Student s is equal to, + +51 +00:02:07,000 --> 00:02:09,000 +you can see it will give you error + +52 +00:02:09,000 --> 00:02:10,000 +because you're not getting student object, + +53 +00:02:10,000 --> 00:02:12,000 +but you're getting an optional object. + +54 +00:02:12,000 --> 00:02:15,000 +So basically you have to convert this + +55 +00:02:15,000 --> 00:02:18,000 +from student to optional student. + +56 +00:02:18,000 --> 00:02:20,000 +As I mentioned, optional means it'll have a value + +57 +00:02:20,000 --> 00:02:23,000 +or it can handle null value basically. + +58 +00:02:23,000 --> 00:02:28,000 +So instead of printing directly this object like this, + +59 +00:02:28,000 --> 00:02:30,000 +we should say get the value, + +60 +00:02:30,000 --> 00:02:32,000 +but what if the value is not there? + +61 +00:02:32,000 --> 00:02:35,000 +So you can say s, or you can say orElse. + +62 +00:02:35,000 --> 00:02:36,000 +If the data is not there, + +63 +00:02:36,000 --> 00:02:39,000 +maybe I want to return a blank student object, + +64 +00:02:39,000 --> 00:02:40,000 +something like this. + +65 +00:02:40,000 --> 00:02:42,000 +So now if you run this code, it will give you the value. + +66 +00:02:42,000 --> 00:02:44,000 +Otherwise, it will give you a blank object. + +67 +00:02:44,000 --> 00:02:46,000 +Let's see what happens. + +68 +00:02:46,000 --> 00:02:48,000 +So you can see we got a blank object here, + +69 +00:02:48,000 --> 00:02:50,000 +basically an object with default values. + +70 +00:02:50,000 --> 00:02:53,000 +And this is not specific to Spring or Hypernet. + +71 +00:02:53,000 --> 00:02:55,000 +This is a Java 8 concept, + +72 +00:02:55,000 --> 00:02:58,000 +which I mean, it was introduced in Java 8. + +73 +00:02:58,000 --> 00:03:00,000 +So basically if you are getting data from somewhere, + +74 +00:03:00,000 --> 00:03:02,000 +the data might not be available, + +75 +00:03:02,000 --> 00:03:04,000 +so it's better to use optional. + +76 +00:03:04,000 --> 00:03:05,000 +But what if you have data? + +77 +00:03:05,000 --> 00:03:07,000 +In that case, it will give you the real data. + +78 +00:03:07,000 --> 00:03:08,000 +So run this. + +79 +00:03:08,000 --> 00:03:10,000 +So you can see we got the data. + +80 +00:03:10,000 --> 00:03:11,000 +This time it's not optional. + +81 +00:03:11,000 --> 00:03:14,000 +We actually got the data. + +82 +00:03:14,000 --> 00:03:16,000 +Okay, so that's how we can solve this. + +83 +00:03:16,000 --> 00:03:18,000 +So basically we're able to find with the primary key, + +84 +00:03:18,000 --> 00:03:20,000 +but what if you want to find + +85 +00:03:20,000 --> 00:03:21,000 +with a data which is not primary? + +86 +00:03:21,000 --> 00:03:22,000 +Maybe you want to search by name. + +87 +00:03:22,000 --> 00:03:25,000 +Maybe you want to search by marks. + +88 +00:03:25,000 --> 00:03:27,000 +Let's see how to do that in the next video. + diff --git a/16 - Spring Data JPA/006 JPQL Query_en.srt b/16 - Spring Data JPA/006 JPQL Query_en.srt new file mode 100644 index 0000000000000000000000000000000000000000..ae2c3dce8b62d66fecb875fc36357e062fe1b347 --- /dev/null +++ b/16 - Spring Data JPA/006 JPQL Query_en.srt @@ -0,0 +1,904 @@ +1 +00:00:00,000 --> 00:00:03,000 +(gentle music) + +2 +00:00:03,000 --> 00:00:06,000 +-: Okay, so now, let's search by name. + +3 +00:00:06,000 --> 00:00:08,000 +Okay, so, how do we do that? + +4 +00:00:08,000 --> 00:00:10,000 +Of course, we have to do something else. + +5 +00:00:10,000 --> 00:00:11,000 +We'll delete this content, + +6 +00:00:11,000 --> 00:00:13,000 +and I want to get the data, right? + +7 +00:00:13,000 --> 00:00:14,000 +So I will say repo., + +8 +00:00:14,000 --> 00:00:16,000 +and of course, you can get the data by primary key. + +9 +00:00:16,000 --> 00:00:18,000 +You have this method, find by ID, + +10 +00:00:18,000 --> 00:00:20,000 +but what if you want to search by name? + +11 +00:00:20,000 --> 00:00:22,000 +So it should have a method, right? + +12 +00:00:22,000 --> 00:00:23,000 +So it should say findByName. + +13 +00:00:25,000 --> 00:00:28,000 +Okay, unfortunately, if you can see, we don't have it. + +14 +00:00:28,000 --> 00:00:31,000 +Let's say I want to search for Navin in this case. + +15 +00:00:31,000 --> 00:00:33,000 +So when you're searching for Navin, + +16 +00:00:33,000 --> 00:00:35,000 +and we are expecting that this should work, + +17 +00:00:35,000 --> 00:00:36,000 +but it's not working. + +18 +00:00:36,000 --> 00:00:38,000 +You can see find by name is not working. + +19 +00:00:38,000 --> 00:00:39,000 +You know why? + +20 +00:00:39,000 --> 00:00:43,000 +Because in the student repo, we don't have this method, + +21 +00:00:43,000 --> 00:00:45,000 +not the one in the JPA repository. + +22 +00:00:45,000 --> 00:00:47,000 +And how can you expect that? + +23 +00:00:47,000 --> 00:00:51,000 +Because every example will have a different class, + +24 +00:00:51,000 --> 00:00:52,000 +different names of the variable. + +25 +00:00:52,000 --> 00:00:53,000 +Here we have name. + +26 +00:00:53,000 --> 00:00:54,000 +That's why we are searching for name, + +27 +00:00:54,000 --> 00:00:56,000 +but what if you have a different variable? + +28 +00:00:56,000 --> 00:00:58,000 +Let's say a person name, a student name. + +29 +00:00:58,000 --> 00:01:00,000 +How can you expect that those method + +30 +00:01:00,000 --> 00:01:02,000 +will be available, right? + +31 +00:01:02,000 --> 00:01:05,000 +So, how do I make it work? + +32 +00:01:05,000 --> 00:01:07,000 +In that case, maybe one of the solution + +33 +00:01:07,000 --> 00:01:08,000 +is to write a query, okay? + +34 +00:01:08,000 --> 00:01:10,000 +So, let's try to write a query. + +35 +00:01:10,000 --> 00:01:13,000 +So let me create a method, which is string. + +36 +00:01:13,000 --> 00:01:15,000 +And okay, because it will... + +37 +00:01:15,000 --> 00:01:15,000 +Okay, what it'll return, + +38 +00:01:15,000 --> 00:01:17,000 +it'll return the list of student. + +39 +00:01:17,000 --> 00:01:19,000 +Now, why it will return a list of student + +40 +00:01:19,000 --> 00:01:22,000 +is because multiple people or multiple rows + +41 +00:01:22,000 --> 00:01:25,000 +can have the same name, of course, right? + +42 +00:01:25,000 --> 00:01:27,000 +Navin is not the unique name in the world. + +43 +00:01:27,000 --> 00:01:29,000 +Let me import the package. + +44 +00:01:30,000 --> 00:01:34,000 +And then you can specify the method name, + +45 +00:01:34,000 --> 00:01:37,000 +and I will say findBy Name, okay? + +46 +00:01:37,000 --> 00:01:40,000 +And then, you can mention the student name, + +47 +00:01:41,000 --> 00:01:43,000 +which is string name. + +48 +00:01:43,000 --> 00:01:44,000 +I mean, whatever data you're passing. + +49 +00:01:44,000 --> 00:01:46,000 +But then will this work? + +50 +00:01:46,000 --> 00:01:49,000 +For this, we have to basically write a query, okay? + +51 +00:01:50,000 --> 00:01:51,000 +Now how do you write a query? + +52 +00:01:51,000 --> 00:01:52,000 +It's very simple. + +53 +00:01:52,000 --> 00:01:53,000 +If you want to specify + +54 +00:01:53,000 --> 00:01:55,000 +whenever someone calls this method, + +55 +00:01:55,000 --> 00:01:58,000 +which is find by name, execute a query. + +56 +00:01:58,000 --> 00:02:02,000 +So we can use a query annotation here, okay? + +57 +00:02:02,000 --> 00:02:04,000 +And we can specify the query. + +58 +00:02:04,000 --> 00:02:06,000 +Now, not a normal query like SQL query. + +59 +00:02:06,000 --> 00:02:08,000 +Since we are using JPA, + +60 +00:02:08,000 --> 00:02:10,000 +we have a special type of query, + +61 +00:02:10,000 --> 00:02:13,000 +which is called a JPQL, + +62 +00:02:13,000 --> 00:02:15,000 +which is your JPA query language. + +63 +00:02:15,000 --> 00:02:17,000 +So basically we have to use JPQL here, + +64 +00:02:17,000 --> 00:02:21,000 +and how it looks like, it looks like a SQL query. + +65 +00:02:21,000 --> 00:02:22,000 +The differences is in SQL, + +66 +00:02:22,000 --> 00:02:24,000 +we use table names, column names. + +67 +00:02:24,000 --> 00:02:29,000 +In JPQL, we use the class name and the property names. + +68 +00:02:29,000 --> 00:02:31,000 +Example, if I want to say select, + +69 +00:02:31,000 --> 00:02:32,000 +I want to fetch everything, + +70 +00:02:32,000 --> 00:02:34,000 +or maybe I want to fetch a student, right? + +71 +00:02:34,000 --> 00:02:38,000 +So I would say select student, which student in S, + +72 +00:02:38,000 --> 00:02:41,000 +from, and then you have to mention the class name, + +73 +00:02:41,000 --> 00:02:41,000 +not the table name. + +74 +00:02:41,000 --> 00:02:43,000 +So Student, capital, S capital. + +75 +00:02:43,000 --> 00:02:45,000 +And then you have to say where, + +76 +00:02:45,000 --> 00:02:47,000 +and then you have to say s.name, okay? + +77 +00:02:47,000 --> 00:02:49,000 +So basically we are fetching a student, + +78 +00:02:49,000 --> 00:02:52,000 +so we have to say s.name, which is a variable. + +79 +00:02:52,000 --> 00:02:53,000 +Okay, treat this as an object, + +80 +00:02:53,000 --> 00:02:55,000 +and this is a variable, equal to, + +81 +00:02:55,000 --> 00:02:58,000 +and then you have to put a question mark, right? + +82 +00:02:58,000 --> 00:03:01,000 +Now this question mark will be replaced by name. + +83 +00:03:01,000 --> 00:03:02,000 +It's that simple. + +84 +00:03:02,000 --> 00:03:04,000 +But then you might be having multiple question marks, right? + +85 +00:03:04,000 --> 00:03:06,000 +So let's say if you have a complex query + +86 +00:03:06,000 --> 00:03:09,000 +and then you have two or three question marks, + +87 +00:03:09,000 --> 00:03:10,000 +how do you differentiate + +88 +00:03:10,000 --> 00:03:11,000 +that this particular question mark + +89 +00:03:11,000 --> 00:03:12,000 +is for the first variable, + +90 +00:03:12,000 --> 00:03:14,000 +the other question mark is with the second variable? + +91 +00:03:14,000 --> 00:03:17,000 +In that case, you have to also give a number here, + +92 +00:03:17,000 --> 00:03:17,000 +which is one. + +93 +00:03:17,000 --> 00:03:19,000 +So what we are saying is this question mark + +94 +00:03:19,000 --> 00:03:23,000 +will be replaced by the first parameter, which is this. + +95 +00:03:23,000 --> 00:03:25,000 +If you're passing in other parameters, + +96 +00:03:25,000 --> 00:03:27,000 +it will be for the second question mark + +97 +00:03:27,000 --> 00:03:28,000 +if you specify that. + +98 +00:03:28,000 --> 00:03:30,000 +But now let's see if it works. + +99 +00:03:30,000 --> 00:03:32,000 +Let's rerun this application, + +100 +00:03:32,000 --> 00:03:35,000 +and you can see there's no problem here. + +101 +00:03:35,000 --> 00:03:36,000 +The error gone. + +102 +00:03:36,000 --> 00:03:37,000 +But will this work? + +103 +00:03:37,000 --> 00:03:38,000 +Let's try. + +104 +00:03:38,000 --> 00:03:40,000 +So, we are running the code, + +105 +00:03:40,000 --> 00:03:43,000 +And, okay, we got an error. + +106 +00:03:43,000 --> 00:03:44,000 +Let's all this. + +107 +00:03:44,000 --> 00:03:45,000 +Oh, I made one mistake. + +108 +00:03:45,000 --> 00:03:47,000 +So basically we have to give an alias. + +109 +00:03:47,000 --> 00:03:51,000 +So we have to say Student s, which is the alias for this, + +110 +00:03:51,000 --> 00:03:53,000 +and then that's what you're fetching. + +111 +00:03:53,000 --> 00:03:53,000 +My bad. + +112 +00:03:53,000 --> 00:03:55,000 +And now this should work. + +113 +00:03:55,000 --> 00:03:57,000 +Okay, so you can see it is firing a query here. + +114 +00:03:57,000 --> 00:03:59,000 +Okay, we got the data, but we forgot to do one thing. + +115 +00:03:59,000 --> 00:04:02,000 +We are not printing it, okay? + +116 +00:04:02,000 --> 00:04:04,000 +Now this is a list, so I can simply print it out, + +117 +00:04:04,000 --> 00:04:05,000 +the entire list. + +118 +00:04:05,000 --> 00:04:07,000 +It is not fetching one record. + +119 +00:04:07,000 --> 00:04:08,000 +It's fetching multiple. + +120 +00:04:08,000 --> 00:04:09,000 +And you can see we got the record. + +121 +00:04:09,000 --> 00:04:11,000 +And you can see it is printing in the square bracket. + +122 +00:04:11,000 --> 00:04:13,000 +That means it's a list here or collection. + +123 +00:04:13,000 --> 00:04:15,000 +So basically, we are printing the name, + +124 +00:04:15,000 --> 00:04:17,000 +a roll number, name, and marks, right? + +125 +00:04:17,000 --> 00:04:19,000 +So basically if you want to have a method, + +126 +00:04:19,000 --> 00:04:22,000 +which might not be there by default in the JP repository, + +127 +00:04:22,000 --> 00:04:27,000 +in that case, we have to specify a query annotation, okay? + +128 +00:04:28,000 --> 00:04:32,000 +But let me tell you magic here, or let me show you a magic. + +129 +00:04:32,000 --> 00:04:35,000 +Basically, even if you remove this, it works. + +130 +00:04:35,000 --> 00:04:36,000 +Okay, let me show you. + +131 +00:04:36,000 --> 00:04:38,000 +So let me remove the entire query. + +132 +00:04:38,000 --> 00:04:40,000 +Okay, there's no query now, and let me relaunch it. + +133 +00:04:40,000 --> 00:04:41,000 +And let's see what happens. + +134 +00:04:41,000 --> 00:04:42,000 +And it works. + +135 +00:04:42,000 --> 00:04:44,000 +I mean, I wasted you a few minutes + +136 +00:04:44,000 --> 00:04:45,000 +just to talk about something + +137 +00:04:45,000 --> 00:04:47,000 +where you already have a method there, okay? + +138 +00:04:47,000 --> 00:04:49,000 +I mean, it is working without it. + +139 +00:04:49,000 --> 00:04:51,000 +See, the thing is, it works, + +140 +00:04:51,000 --> 00:04:54,000 +but it will not work for everything, okay? + +141 +00:04:54,000 --> 00:04:56,000 +So what JPA does is JPA uses something + +142 +00:04:56,000 --> 00:04:59,000 +called a domain-specific language, which is DSL. + +143 +00:04:59,000 --> 00:05:03,000 +So using this DSL, it creates certain methods + +144 +00:05:03,000 --> 00:05:04,000 +for you behind the scene. + +145 +00:05:04,000 --> 00:05:07,000 +So it will look for the column name or the property names. + +146 +00:05:07,000 --> 00:05:10,000 +We have a property called name via property called marks. + +147 +00:05:10,000 --> 00:05:13,000 +So it will create certain queries behind the scene for you, + +148 +00:05:13,000 --> 00:05:15,000 +and you can use those names directly. + +149 +00:05:15,000 --> 00:05:17,000 +You can use those methods directly. + +150 +00:05:17,000 --> 00:05:19,000 +But, yes, if you specify something else here, + +151 +00:05:19,000 --> 00:05:22,000 +something like this, findBySName, then it will not work + +152 +00:05:22,000 --> 00:05:25,000 +because JPA has no idea that what is his name here? + +153 +00:05:25,000 --> 00:05:27,000 +But JPA knows what is name. + +154 +00:05:27,000 --> 00:05:29,000 +But in case if you want something extra, + +155 +00:05:29,000 --> 00:05:31,000 +which is not provided by JPA, + +156 +00:05:31,000 --> 00:05:33,000 +in that case, you have to write the query notation. + +157 +00:05:33,000 --> 00:05:35,000 +So you have to specify the query by yourself. + +158 +00:05:35,000 --> 00:05:39,000 +But most of the time, JPA will have the methods for you. + +159 +00:05:39,000 --> 00:05:41,000 +Example, we got find by name. + +160 +00:05:41,000 --> 00:05:43,000 +What about you want to find by marks? + +161 +00:05:43,000 --> 00:05:44,000 +We can do that. + +162 +00:05:44,000 --> 00:05:45,000 +So I can say the same thing. + +163 +00:05:45,000 --> 00:05:49,000 +I can just copy paste this, and I can say findByMarks, + +164 +00:05:49,000 --> 00:05:52,000 +but you have to make sure that the method theme starts + +165 +00:05:52,000 --> 00:05:55,000 +with findBy because that's the standard. + +166 +00:05:55,000 --> 00:05:57,000 +And then you have to mention the variable name, + +167 +00:05:57,000 --> 00:05:59,000 +which is name, the marks, or you can also specify ID, + +168 +00:05:59,000 --> 00:06:00,000 +which is the primary key. + +169 +00:06:00,000 --> 00:06:01,000 +So you can specify the whole number. + +170 +00:06:01,000 --> 00:06:03,000 +You can specify ID. + +171 +00:06:03,000 --> 00:06:05,000 +And here, instead of saying string, + +172 +00:06:05,000 --> 00:06:07,000 +you have to say int marks, okay? + +173 +00:06:07,000 --> 00:06:08,000 +Now this should work + +174 +00:06:08,000 --> 00:06:10,000 +provided you change something here. + +175 +00:06:10,000 --> 00:06:11,000 +So instead of saying findByName, + +176 +00:06:12,000 --> 00:06:14,000 +I would say findByMarks, + +177 +00:06:16,000 --> 00:06:17,000 +but what should be the marks? + +178 +00:06:17,000 --> 00:06:19,000 +Let me just check my database. + +179 +00:06:19,000 --> 00:06:20,000 +And let's say I want to search for 80. + +180 +00:06:20,000 --> 00:06:22,000 +So I will say 80 here. + +181 +00:06:22,000 --> 00:06:24,000 +And again, this will give you a list of values, + +182 +00:06:24,000 --> 00:06:27,000 +not just one because multiple children + +183 +00:06:27,000 --> 00:06:29,000 +can have the same marks. + +184 +00:06:29,000 --> 00:06:31,000 +And if you see, we got the record. + +185 +00:06:31,000 --> 00:06:32,000 +Okay, that's how it works. + +186 +00:06:32,000 --> 00:06:35,000 +But what if I want to do something extra? + +187 +00:06:35,000 --> 00:06:40,000 +Let's say, I want to say find by marks greater than 70, + +188 +00:06:40,000 --> 00:06:42,000 +something like this, or 75. + +189 +00:06:42,000 --> 00:06:45,000 +So again, you should not be judging students + +190 +00:06:45,000 --> 00:06:45,000 +based on their marks. + +191 +00:06:45,000 --> 00:06:50,000 +That's wrong, but we can do it for the example. + +192 +00:06:50,000 --> 00:06:51,000 +Okay, so let's say I want to search students + +193 +00:06:51,000 --> 00:06:55,000 +based on their marks greater than 70, 75, + +194 +00:06:55,000 --> 00:06:56,000 +or maybe let's say 72. + +195 +00:06:56,000 --> 00:06:58,000 +So let's greater than 72. + +196 +00:06:58,000 --> 00:07:00,000 +In that case, what should be done? + +197 +00:07:00,000 --> 00:07:02,000 +So let's go back to our repo. + +198 +00:07:02,000 --> 00:07:05,000 +Instead of saying Marks, I can say MarksGreaterThan, + +199 +00:07:06,000 --> 00:07:08,000 +and then you can specify the marks, okay? + +200 +00:07:08,000 --> 00:07:11,000 +So, certain things are there like greater than, less than, + +201 +00:07:11,000 --> 00:07:12,000 +everything which comes in the query, right? + +202 +00:07:12,000 --> 00:07:15,000 +So we have greater than, less than, equals, + +203 +00:07:15,000 --> 00:07:16,000 +so we can use those methods. + +204 +00:07:16,000 --> 00:07:18,000 +And now, let's switch it from here. + +205 +00:07:18,000 --> 00:07:20,000 +So instead of saying get by marks, + +206 +00:07:20,000 --> 00:07:24,000 +I will say get by marks greater than, and let's say 72. + +207 +00:07:24,000 --> 00:07:27,000 +And we have two students who has marks greater than 72. + +208 +00:07:27,000 --> 00:07:30,000 +Let's run and see if that works. + +209 +00:07:30,000 --> 00:07:32,000 +And you can see we got two records now, + +210 +00:07:32,000 --> 00:07:36,000 +one, Navin, which is 75, and Kiran, which is 80. + +211 +00:07:36,000 --> 00:07:37,000 +And that's how it works. + +212 +00:07:37,000 --> 00:07:38,000 +So basically, we have talked about something + +213 +00:07:38,000 --> 00:07:40,000 +called a query DSL. + +214 +00:07:40,000 --> 00:07:43,000 +So basically, DSL, domain-specific language, + +215 +00:07:43,000 --> 00:07:46,000 +JPA will have certain queries for you pre created, + +216 +00:07:46,000 --> 00:07:48,000 +already created, which you can use + +217 +00:07:48,000 --> 00:07:49,000 +with the help of method names, + +218 +00:07:49,000 --> 00:07:52,000 +but you have to make sure that it is find by, + +219 +00:07:52,000 --> 00:07:53,000 +and then you can mention the variable name + +220 +00:07:53,000 --> 00:07:56,000 +and whatever operators you want to use, + +221 +00:07:56,000 --> 00:07:58,000 +greater than, less than, or something like that. + +222 +00:07:58,000 --> 00:07:59,000 +So yeah, that's it from this video + +223 +00:07:59,000 --> 00:08:00,000 +where we talked about how do you find, + +224 +00:08:00,000 --> 00:08:03,000 +but then we have two more operations, delete and update. + +225 +00:08:03,000 --> 00:08:04,000 +Will that work? + +226 +00:08:04,000 --> 00:08:05,000 +Let's try in the next video. + diff --git a/16 - Spring Data JPA/006 Source-Code.url b/16 - Spring Data JPA/006 Source-Code.url new file mode 100644 index 0000000000000000000000000000000000000000..1494b0264e3e6b54c7cd1622774ac65b3e6fed55 --- /dev/null +++ b/16 - Spring Data JPA/006 Source-Code.url @@ -0,0 +1,2 @@ +[InternetShortcut] +URL=https://github.com/navinreddy20/spring6-course/tree/fa914a08f0f89f7d8a8a16362d928b0bdb45d337/10%20Spring%20DataJPA/9.6%20Query%20Dsl/spring-data-jpa-ex \ No newline at end of file diff --git a/16 - Spring Data JPA/007 Source-Code.url b/16 - Spring Data JPA/007 Source-Code.url new file mode 100644 index 0000000000000000000000000000000000000000..5fc09cb6128908f64ecf17fb0ceed6a6bf276483 --- /dev/null +++ b/16 - Spring Data JPA/007 Source-Code.url @@ -0,0 +1,2 @@ +[InternetShortcut] +URL=https://github.com/navinreddy20/spring6-course/tree/fa914a08f0f89f7d8a8a16362d928b0bdb45d337/10%20Spring%20DataJPA/9.7%20Update%20And%20Delete/spring-data-jpa-ex \ No newline at end of file diff --git a/16 - Spring Data JPA/007 Update and Delete_en.srt b/16 - Spring Data JPA/007 Update and Delete_en.srt new file mode 100644 index 0000000000000000000000000000000000000000..6b4251c1274e01009a6fcab47fcd226945414bcd --- /dev/null +++ b/16 - Spring Data JPA/007 Update and Delete_en.srt @@ -0,0 +1,304 @@ +1 +00:00:00,000 --> 00:00:03,000 +(gentle intro music) + +2 +00:00:03,000 --> 00:00:05,000 +-: Now let's work with Update and Delete. + +3 +00:00:05,000 --> 00:00:06,000 +So what I will do is, + +4 +00:00:06,000 --> 00:00:09,000 +I don't want this student printing. + +5 +00:00:09,000 --> 00:00:10,000 +I do hold... + +6 +00:00:10,000 --> 00:00:11,000 +I do have all these things. + +7 +00:00:11,000 --> 00:00:13,000 +Let's say I want to update a student. + +8 +00:00:13,000 --> 00:00:14,000 +So let's say + +9 +00:00:14,000 --> 00:00:15,000 +I want to update S3. + +10 +00:00:15,000 --> 00:00:16,000 +Okay? + +11 +00:00:16,000 --> 00:00:17,000 +So what you can do is, + +12 +00:00:17,000 --> 00:00:19,000 +you can simply use repo dot + +13 +00:00:19,000 --> 00:00:21,000 +and you'll find a method to update. + +14 +00:00:21,000 --> 00:00:23,000 +Now, there is no actual update here. + +15 +00:00:23,000 --> 00:00:28,000 +If you see, if you scroll down and down and down. + +16 +00:00:28,000 --> 00:00:29,000 +So this we don't have update, + +17 +00:00:29,000 --> 00:00:32,000 +but you can use save to update also. + +18 +00:00:32,000 --> 00:00:34,000 +So let me update with the same object. + +19 +00:00:34,000 --> 00:00:37,000 +Okay, so let's say I want to update Kiran. + +20 +00:00:37,000 --> 00:00:39,000 +So I'll just uncommend this, set the values, + +21 +00:00:39,000 --> 00:00:40,000 +and then I will simply change certain values. + +22 +00:00:40,000 --> 00:00:41,000 +We already have this data + +23 +00:00:41,000 --> 00:00:46,000 +and I want to change the marks to let's say 65. + +24 +00:00:48,000 --> 00:00:49,000 +Okay, so I'm changing only one field, + +25 +00:00:49,000 --> 00:00:51,000 +but will it update? + +26 +00:00:51,000 --> 00:00:53,000 +Let's try. So I'll just rerun this + +27 +00:00:53,000 --> 00:00:54,000 +and just to + +28 +00:00:54,000 --> 00:00:57,000 +make sure that you know our database, we have + +29 +00:00:57,000 --> 00:00:58,000 +80 and let's rerun. + +30 +00:00:58,000 --> 00:00:59,000 +Okay, it says something expected. Of course, + +31 +00:00:59,000 --> 00:01:02,000 +of course. + +32 +00:01:02,000 --> 00:01:05,000 +How can you forgot to do that? + +33 +00:01:05,000 --> 00:01:06,000 +And of course we forgot + +34 +00:01:06,000 --> 00:01:09,000 +to even mention the object which you + +35 +00:01:09,000 --> 00:01:10,000 +and we want to store this two, not S3. + +36 +00:01:10,000 --> 00:01:11,000 +want to store. + +37 +00:01:11,000 --> 00:01:13,000 +This is what happens + +38 +00:01:14,000 --> 00:01:14,000 +Let's rerun something is happening + +39 +00:01:14,000 --> 00:01:16,000 +when you are excited to see the output. + +40 +00:01:16,000 --> 00:01:19,000 +and you can see it is firing an update query. + +41 +00:01:19,000 --> 00:01:20,000 +And if you observe + +42 +00:01:20,000 --> 00:01:23,000 +before updating it is firing a select query just + +43 +00:01:23,000 --> 00:01:25,000 +to check do we have that data? + +44 +00:01:25,000 --> 00:01:26,000 +If you have that data, + +45 +00:01:26,000 --> 00:01:27,000 +it'll fire the update query. + +46 +00:01:27,000 --> 00:01:29,000 +If you don't have that data, it'll, + +47 +00:01:29,000 --> 00:01:31,000 +it'll fire a create query. + +48 +00:01:31,000 --> 00:01:33,000 +That's how it works. Let's verify the database + +49 +00:01:34,000 --> 00:01:37,000 +and let's refresh this view all data, all rows. + +50 +00:01:37,000 --> 00:01:40,000 +And you can see we got 65. So update works. + +51 +00:01:40,000 --> 00:01:41,000 +What about delete? So it's very simple. + +52 +00:01:41,000 --> 00:01:43,000 +You can just go, come back here + +53 +00:01:43,000 --> 00:01:44,000 +and say dot delete, + +54 +00:01:44,000 --> 00:01:46,000 +pass the object you wanna delete. + +55 +00:01:46,000 --> 00:01:49,000 +Let's say I want to delete second object itself + +56 +00:01:49,000 --> 00:01:51,000 +and let's relaunch. + +57 +00:01:51,000 --> 00:01:53,000 +It'll happen. It'll file the delete query, + +58 +00:01:53,000 --> 00:01:55,000 +but still I will wait to see the query + +59 +00:01:55,000 --> 00:01:57,000 +and you can see it is filing the query. + +60 +00:01:57,000 --> 00:01:59,000 +First, do we have that particular row? + +61 +00:01:59,000 --> 00:02:00,000 +And then it deletes that particular row + +62 +00:02:00,000 --> 00:02:02,000 +with the help of row number of course, + +63 +00:02:02,000 --> 00:02:03,000 +because that's how you delete the data. + +64 +00:02:03,000 --> 00:02:07,000 +Let's go back here and see if you have the data. + +65 +00:02:07,000 --> 00:02:10,000 +So I'll say view all rows and + +66 +00:02:10,000 --> 00:02:11,000 +boom. + +67 +00:02:11,000 --> 00:02:12,000 +You can see, we don't have Kiran now. + +68 +00:02:12,000 --> 00:02:14,000 +We have Navin and Hersch. + +69 +00:02:14,000 --> 00:02:15,000 +So yeah, + +70 +00:02:15,000 --> 00:02:16,000 +that's how basically you update and delete. + +71 +00:02:16,000 --> 00:02:17,000 +And whereby doing this, + +72 +00:02:17,000 --> 00:02:19,000 +we have done with killer operations, + +73 +00:02:19,000 --> 00:02:21,000 +but then we also want + +74 +00:02:21,000 --> 00:02:22,000 +to add this particular feature + +75 +00:02:22,000 --> 00:02:25,000 +in our job portal, right? + +76 +00:02:25,000 --> 00:02:26,000 +So let's do that in the next video. + diff --git a/16 - Spring Data JPA/008 JPA in Job App_en.srt b/16 - Spring Data JPA/008 JPA in Job App_en.srt new file mode 100644 index 0000000000000000000000000000000000000000..0af40993ca4ba8c37153ae1484e4ca7024d1fc9f --- /dev/null +++ b/16 - Spring Data JPA/008 JPA in Job App_en.srt @@ -0,0 +1,784 @@ +1 +00:00:00,000 --> 00:00:03,000 +-: So now we know how do we use SpringDataJpa. + +2 +00:00:03,000 --> 00:00:05,000 +And to do that we have created the application for Student. + +3 +00:00:05,000 --> 00:00:09,000 +But now we want to implement this in our job application. + +4 +00:00:09,000 --> 00:00:11,000 +So if you go back to job application, + +5 +00:00:11,000 --> 00:00:14,000 +what we have done 'till now is we have a controller + +6 +00:00:14,000 --> 00:00:19,000 +which deals with getting the jobs, getting the job by ID, + +7 +00:00:19,000 --> 00:00:23,000 +maybe you are adding a new job, updating a job, + +8 +00:00:23,000 --> 00:00:24,000 +and deleting the job, right? + +9 +00:00:24,000 --> 00:00:26,000 +So, we have done these things. + +10 +00:00:26,000 --> 00:00:28,000 +But then whenever you do any operation, + +11 +00:00:28,000 --> 00:00:32,000 +we are sending the request from client to the controller, + +12 +00:00:32,000 --> 00:00:35,000 +from controller to service, from service to repo. + +13 +00:00:35,000 --> 00:00:36,000 +But in repo we are expecting + +14 +00:00:36,000 --> 00:00:38,000 +that it'll connect with database. + +15 +00:00:38,000 --> 00:00:41,000 +But no, we have created our own list here, right? + +16 +00:00:41,000 --> 00:00:43,000 +And we have some default values. + +17 +00:00:43,000 --> 00:00:46,000 +I have changed these values from the previous one + +18 +00:00:46,000 --> 00:00:48,000 +because I want to do some searching as well. + +19 +00:00:48,000 --> 00:00:50,000 +But yeah, we have this thing here. + +20 +00:00:50,000 --> 00:00:51,000 +Almost same thing which we have done, + +21 +00:00:51,000 --> 00:00:54,000 +we got postId, profiles, description, experience, + +22 +00:00:54,000 --> 00:00:59,000 +and a list a technology expected in that particular job. + +23 +00:00:59,000 --> 00:01:02,000 +But now whatever we are doing, we are doing with a list. + +24 +00:01:02,000 --> 00:01:04,000 +Now we want to convert this into a JPA. + +25 +00:01:04,000 --> 00:01:06,000 +How would we do that? Step-by-step. + +26 +00:01:06,000 --> 00:01:09,000 +First of all, if you want to use data JPA here, + +27 +00:01:09,000 --> 00:01:11,000 +we have to add the dependency, + +28 +00:01:11,000 --> 00:01:13,000 +which means we have to go back + +29 +00:01:13,000 --> 00:01:15,000 +to your pom.xml file, + +30 +00:01:15,000 --> 00:01:18,000 +and here we need to add the dependency for JPA. + +31 +00:01:18,000 --> 00:01:20,000 +Now, from where you will get this, + +32 +00:01:20,000 --> 00:01:21,000 +we do have a project, right? + +33 +00:01:21,000 --> 00:01:23,000 +So we'll go back to our project, + +34 +00:01:23,000 --> 00:01:25,000 +which is the student application. + +35 +00:01:25,000 --> 00:01:28,000 +And if you go to the pom of this particular file, + +36 +00:01:28,000 --> 00:01:32,000 +and if you search, we have data-jpa. + +37 +00:01:32,000 --> 00:01:33,000 +We'll also need Postgres + +38 +00:01:33,000 --> 00:01:36,000 +because that's the database I'm going to use. + +39 +00:01:36,000 --> 00:01:40,000 +So that go back to our application and paste it here. + +40 +00:01:40,000 --> 00:01:44,000 +So done. So we have added the data-jpa and then postgres. + +41 +00:01:44,000 --> 00:01:46,000 +Of course we need to load this. Let's reload this. + +42 +00:01:46,000 --> 00:01:51,000 +Okay, it is showing some issue with the dependencies. + +43 +00:01:51,000 --> 00:01:56,000 +Okay, I've copied the wrong tag. Okay, so no problem. + +44 +00:01:56,000 --> 00:01:58,000 +We got this. Let's refresh. + +45 +00:01:58,000 --> 00:02:00,000 +Reload the Maven. + +46 +00:02:00,000 --> 00:02:02,000 +And taking some time. Okay, done. + +47 +00:02:02,000 --> 00:02:03,000 +So that's the first thing you have to do. + +48 +00:02:03,000 --> 00:02:05,000 +You have to make sure you have your JPA. + +49 +00:02:05,000 --> 00:02:08,000 +Next. I want to change this JobRepo. + +50 +00:02:08,000 --> 00:02:10,000 +So till this point, we had all this code. + +51 +00:02:10,000 --> 00:02:12,000 +I don't want all this code now, + +52 +00:02:12,000 --> 00:02:13,000 +so I can simply comment this. + +53 +00:02:13,000 --> 00:02:16,000 +But before commenting, I do want this particular code + +54 +00:02:16,000 --> 00:02:19,000 +because I want at least there some data in the database + +55 +00:02:19,000 --> 00:02:21,000 +before we start. + +56 +00:02:21,000 --> 00:02:25,000 +So I will just copy this, and where should I keep it? + +57 +00:02:25,000 --> 00:02:27,000 +Maybe I will keep it in this service. + +58 +00:02:28,000 --> 00:02:32,000 +So let me say save multiple jobs. + +59 +00:02:32,000 --> 00:02:33,000 +Let me create a method here. + +60 +00:02:33,000 --> 00:02:34,000 +Or maybe I can just keep it here, + +61 +00:02:34,000 --> 00:02:36,000 +for time, we'll use it later. + +62 +00:02:36,000 --> 00:02:38,000 +So yeah, so it's there. + +63 +00:02:38,000 --> 00:02:39,000 +We are not going to use it as of now, + +64 +00:02:39,000 --> 00:02:41,000 +but we'll use it later. + +65 +00:02:41,000 --> 00:02:43,000 +Let's go back to the job. + +66 +00:02:43,000 --> 00:02:45,000 +And we don't need any of this code now. + +67 +00:02:45,000 --> 00:02:46,000 +So I can just select everything + +68 +00:02:46,000 --> 00:02:49,000 +and I can just cut it from here, paste it here. + +69 +00:02:49,000 --> 00:02:52,000 +But I also need to comment all these sections + +70 +00:02:52,000 --> 00:02:53,000 +just for the reference. + +71 +00:02:53,000 --> 00:02:54,000 +So at this point you can see + +72 +00:02:54,000 --> 00:02:56,000 +we have a empty class here, right? + +73 +00:02:56,000 --> 00:02:59,000 +But now if you want to use data JPA here, + +74 +00:02:59,000 --> 00:03:00,000 +what are the steps? + +75 +00:03:00,000 --> 00:03:01,000 +If you remember in the code + +76 +00:03:01,000 --> 00:03:03,000 +which we have written for the student, + +77 +00:03:03,000 --> 00:03:05,000 +if you go back to the repo of student, + +78 +00:03:05,000 --> 00:03:06,000 +we were not using a class, + +79 +00:03:06,000 --> 00:03:08,000 +we were using an interface. + +80 +00:03:08,000 --> 00:03:11,000 +So here also we have to use an interface + +81 +00:03:11,000 --> 00:03:13,000 +and this interface will extend. + +82 +00:03:13,000 --> 00:03:17,000 +So we have to extend the JPA repository, + +83 +00:03:17,000 --> 00:03:18,000 +but I'm not getting that. + +84 +00:03:18,000 --> 00:03:22,000 +Let me just check if the dependencies we have added + +85 +00:03:22,000 --> 00:03:26,000 +for data-jpa or not. + +86 +00:03:26,000 --> 00:03:28,000 +Okay, data-jpa has been added. + +87 +00:03:28,000 --> 00:03:31,000 +Is the Maven reloaded properly? + +88 +00:03:31,000 --> 00:03:32,000 +Let me check the external libraries. + +89 +00:03:32,000 --> 00:03:35,000 +Okay, JPA is here. + +90 +00:03:35,000 --> 00:03:36,000 +Okay, I don't know why + +91 +00:03:36,000 --> 00:03:39,000 +it was not able to import it by default. + +92 +00:03:39,000 --> 00:03:41,000 +There might be some issue with the IDE. Anyway. + +93 +00:03:41,000 --> 00:03:43,000 +So you can see, we got the the repository + +94 +00:03:43,000 --> 00:03:46,000 +and here I'll mention we are working with JobPost, + +95 +00:03:46,000 --> 00:03:49,000 +it should give you suggestion, but it's not. + +96 +00:03:49,000 --> 00:03:53,000 +Anyway, sometime we don't have to depend upon the ID. + +97 +00:03:53,000 --> 00:03:55,000 +And then it is asking you for the primary key. + +98 +00:03:55,000 --> 00:03:58,000 +Now in the JobPost, the post ID is our primary key, right? + +99 +00:03:58,000 --> 00:04:00,000 +Which is of type int. + +100 +00:04:00,000 --> 00:04:03,000 +So here we have to mention we are working with integer. + +101 +00:04:03,000 --> 00:04:06,000 +Okay, that's it. So this is your JPA. + +102 +00:04:06,000 --> 00:04:09,000 +So basically we created an interface called JobRepo. + +103 +00:04:09,000 --> 00:04:10,000 +And then it is extending JpaRepository. + +104 +00:04:10,000 --> 00:04:13,000 +That's the first step, right? Let's remove everything. + +105 +00:04:13,000 --> 00:04:16,000 +Now, when you work with this type of things, + +106 +00:04:16,000 --> 00:04:19,000 +you have to make changes in the service, + +107 +00:04:19,000 --> 00:04:23,000 +because in service now we cannot use repo.addJob + +108 +00:04:23,000 --> 00:04:25,000 +because the methods are different. + +109 +00:04:25,000 --> 00:04:26,000 +Now what's the method you have to use? + +110 +00:04:26,000 --> 00:04:30,000 +So if you say repo. the method will be save. + +111 +00:04:30,000 --> 00:04:34,000 +So whatever jobPost you're doing, you have to say save. + +112 +00:04:34,000 --> 00:04:35,000 +What about getAllJobs? + +113 +00:04:35,000 --> 00:04:38,000 +So we'll just go back here and say repo.findAll. + +114 +00:04:40,000 --> 00:04:42,000 +Remember, so we know the methods now, right? + +115 +00:04:42,000 --> 00:04:43,000 +I can simply use it. + +116 +00:04:44,000 --> 00:04:47,000 +Next, instead of this, we have to say get job. + +117 +00:04:47,000 --> 00:04:50,000 +So we have to say findById + +118 +00:04:50,000 --> 00:04:53,000 +and you have to use the postId. + +119 +00:04:53,000 --> 00:04:56,000 +That's one. Okay, there is some issue with this. + +120 +00:04:56,000 --> 00:04:58,000 +It might return optional, remember? + +121 +00:04:58,000 --> 00:05:02,000 +So we are expecting a job post, but it'll return optional. + +122 +00:05:02,000 --> 00:05:06,000 +So what you can do, is you can say or else here + +123 +00:05:06,000 --> 00:05:08,000 +and you can mention if this is empty. + +124 +00:05:08,000 --> 00:05:12,000 +In that case you can return a new job post object + +125 +00:05:12,000 --> 00:05:13,000 +with a default parameter. + +126 +00:05:13,000 --> 00:05:14,000 +So it'll get default values. + +127 +00:05:14,000 --> 00:05:15,000 +There are different ways of handling this. + +128 +00:05:15,000 --> 00:05:18,000 +Maybe you can return a null or you can throw an exception + +129 +00:05:18,000 --> 00:05:21,000 +and then you can have a custom exception handling that. + +130 +00:05:21,000 --> 00:05:23,000 +But at this point, just keep it simple. + +131 +00:05:23,000 --> 00:05:26,000 +Update. How do we update this? + +132 +00:05:26,000 --> 00:05:28,000 +So it's a repo. again, save for the update. + +133 +00:05:28,000 --> 00:05:33,000 +Also, we have to say save. What about delete? + +134 +00:05:33,000 --> 00:05:35,000 +We know this, we can simply say deleteById, + +135 +00:05:35,000 --> 00:05:38,000 +and you can pass postId here. + +136 +00:05:38,000 --> 00:05:39,000 +And that's done. + +137 +00:05:39,000 --> 00:05:42,000 +So basically we have updated all the methods of service. + +138 +00:05:42,000 --> 00:05:44,000 +And you know the magical thing is + +139 +00:05:44,000 --> 00:05:46,000 +the controller has no idea what has changed. + +140 +00:05:46,000 --> 00:05:49,000 +In fact, you don't even have to change your service class + +141 +00:05:49,000 --> 00:05:52,000 +if we have used the same method names, right? + +142 +00:05:52,000 --> 00:05:54,000 +So we have used the different method names before. + +143 +00:05:54,000 --> 00:05:57,000 +I could have done this method name before, + +144 +00:05:57,000 --> 00:05:59,000 +but I just wanted to show you + +145 +00:05:59,000 --> 00:06:01,000 +how we should think in the JPO world. + +146 +00:06:01,000 --> 00:06:04,000 +So it's not add job or fetch job. + +147 +00:06:04,000 --> 00:06:06,000 +So you have to use some specific methods like save, + +148 +00:06:06,000 --> 00:06:09,000 +find all, and all those stuff. + +149 +00:06:09,000 --> 00:06:10,000 +And remember in the repository + +150 +00:06:10,000 --> 00:06:12,000 +we are not writing any method. + +151 +00:06:12,000 --> 00:06:14,000 +This interface is empty, right? + +152 +00:06:14,000 --> 00:06:15,000 +Of course we are extending it, + +153 +00:06:15,000 --> 00:06:18,000 +but what we have defined is empty. + +154 +00:06:18,000 --> 00:06:20,000 +So now if I go back to the job controller, + +155 +00:06:20,000 --> 00:06:22,000 +you can see there's no changes required here. + +156 +00:06:22,000 --> 00:06:24,000 +But will this really work? + +157 +00:06:24,000 --> 00:06:28,000 +In fact, even if it works, I want to do some changes. + +158 +00:06:28,000 --> 00:06:30,000 +What change I want to do is when I load this class, + +159 +00:06:30,000 --> 00:06:32,000 +service class for the first time, + +160 +00:06:32,000 --> 00:06:35,000 +I want this data to be there. + +161 +00:06:35,000 --> 00:06:38,000 +Or maybe we can hit a particular URL to load the data. + +162 +00:06:38,000 --> 00:06:42,000 +So I can say public_void, + +163 +00:06:43,000 --> 00:06:44,000 +I don't want to return anything, + +164 +00:06:44,000 --> 00:06:48,000 +or maybe I will just say String, just to say pass or not. + +165 +00:06:48,000 --> 00:06:50,000 +And I will say loadData. + +166 +00:06:51,000 --> 00:06:53,000 +This request will come coming from the client side, + +167 +00:06:53,000 --> 00:06:54,000 +and I'll send a GetMapping + +168 +00:06:54,000 --> 00:06:57,000 +and I will say that the URL is load. + +169 +00:06:57,000 --> 00:06:59,000 +So basically whenever I call load, + +170 +00:06:59,000 --> 00:07:00,000 +it should load the database. + +171 +00:07:00,000 --> 00:07:02,000 +That's what I want, and we'll do it only once. + +172 +00:07:02,000 --> 00:07:04,000 +So, return, success even if it fails. + +173 +00:07:04,000 --> 00:07:06,000 +That's how you can fake something is working. + +174 +00:07:06,000 --> 00:07:10,000 +But let's load. So I will say service.load. + +175 +00:07:10,000 --> 00:07:12,000 +So I want to basically call this method. + +176 +00:07:12,000 --> 00:07:13,000 +And in service we don't have this method, + +177 +00:07:13,000 --> 00:07:16,000 +so let's create one in the service class. + +178 +00:07:16,000 --> 00:07:18,000 +So whatever I was doing here, + +179 +00:07:18,000 --> 00:07:22,000 +I want to do this inside the load method, + +180 +00:07:22,000 --> 00:07:25,000 +but all this data I want to store in database. + +181 +00:07:25,000 --> 00:07:28,000 +So what I can do is I can say repo. + +182 +00:07:28,000 --> 00:07:31,000 +There's a method called saveAll, if you can see that? + +183 +00:07:31,000 --> 00:07:33,000 +In the saveAll just past jobs, + +184 +00:07:33,000 --> 00:07:35,000 +what it'll do is when you call this method + +185 +00:07:35,000 --> 00:07:36,000 +for the first time, + +186 +00:07:36,000 --> 00:07:38,000 +or whenever you call this method, + +187 +00:07:38,000 --> 00:07:42,000 +it will try to save this entire list in the database. + +188 +00:07:42,000 --> 00:07:45,000 +So by default we'll be having this five entries, okay? + +189 +00:07:45,000 --> 00:07:46,000 +Will this work? What do you think? + +190 +00:07:47,000 --> 00:07:49,000 +It will not, okay, why? I will tell you. + +191 +00:07:49,000 --> 00:07:51,000 +First of all, in the job post, + +192 +00:07:51,000 --> 00:07:53,000 +we have not mentioned this is entity. + +193 +00:07:53,000 --> 00:07:56,000 +We have not mentioned this is id. + +194 +00:07:56,000 --> 00:07:59,000 +Additionally, we have not done any configuration + +195 +00:07:59,000 --> 00:08:01,000 +in the application of properties. + +196 +00:08:01,000 --> 00:08:03,000 +Let's do that in the next video. + diff --git a/16 - Spring Data JPA/008 Source-Code.url b/16 - Spring Data JPA/008 Source-Code.url new file mode 100644 index 0000000000000000000000000000000000000000..7cc8e1700e0b7c381fc247754852e703f482c997 --- /dev/null +++ b/16 - Spring Data JPA/008 Source-Code.url @@ -0,0 +1,2 @@ +[InternetShortcut] +URL=https://github.com/navinreddy20/spring6-course/tree/fa914a08f0f89f7d8a8a16362d928b0bdb45d337/10%20Spring%20DataJPA/9.8%20Jpa%20In%20Job%20App/spring-boot-rest \ No newline at end of file