Spring MVC Tutorial for Beginners

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so are you a developer and you are walking on sublet and JSP maybe starts framework and if you are looking for some simple solution here we are so we are talking about spring MVC so welcome to that is the learnings my name is Dmytro D and let's talk about spring MVC now so what exactly spring MVC easy I hope you might have heard about this from lots of people let's move to spring MVC let's learn spring MVC so why everyone is moving to spring MVC it's because it is damn easy to work with ok so there are lots of reasons why we are going for spring MVC the first one is it is easy to learn second it provides you that flexibility that you can change anything anytime and third the separation of concerns or separation of the modules example we have different views we have different models and then we have different services to work with spring provides you all those features and if you have already worked on spring you know the power of spring right and this is spring MVC now when you talk about spring MVC we can create amazing websites using things spring MVC I mean nothing different from what you what we done what we do in servlet and JSP but doing the same thing in a very effective way right now if I remember when you work with sublights what we have did is you have created the socket class and then you say exchange HTTP servlet then you have to create a method which is which is service right and then you send a request the client sends the request goes to server and that's how it works how spring MVC works is again when you when you learn these things you might find it bit difficult to grasp everything but trust me if you make one simple application or even a small coding spring MVC after that if you want to expand to it it is very easy okay so let's start with it so let us try to understand the architecture or how exactly spring MVC works so just for that what we will do is let's imagine we have certain controllers here okay so we have certain controllers right so if you go to your server technology every sub let behave like a controller white and your JSP behaves like a view so let's say we have something control now what controllers I'm talking about let's say we have a login controller we have a logout controller we have add a controller we have multiplication controller so let's say we have this four controllers here from the client side when clients sends a request request goes to your favorite file which is web dot XML file right in that XML file we mentioned for which request you want to call which controller right that's what we do in and in your normal survey technology in Summit MVC right but so the problem is if you have lots of controllers sometimes it's difficult to manage all the controllers right let's say we have 15 they have we have 100 controllers so it is difficult to manage all the controllers second each sublight will behave like one controller we wanted something called as multi action controller for that again the spring MVC will help you so if you try to convert the same architecture in spring and we see what we can do is we have a client machine here client machine sends the request to this server and server says ok now we are not using normal MVC we want to use spring MVC that means to handle all this controller we need one more controller who will be the front controller ok so with all these controllers we have one more controller ties your front controller then you will think ok now we have to provoke provide one more controller no you don't have to do that spring MVC will create a controller for you you just have to create your controllers but the front controller will be given by spring MVC now that front controller in spring and base it is called as dispatcher servlet that means all the client requests which goes to web.xml file should know that you are using spring MVC and all the requests should go to your your front controller which is your deployed which is your order dispatcher sublet how can you mention that so it's very simple in your web.xml file just mentioned that for all the requests we have to send the request to dispatcher servlet is that simple right again you know how to do it right you can create a subject tag you can create so that mapping tag and you can do that now once your request goes to despite a sublet then what now despite a servlet will think okay the request is for login I should call a login sublet I mean I want to call a login controller right request is for ad so you have to call add controller request is for logout you have to call logout controller so despite this object should know which one to call but there is one more issue here the issue is how would your dispatch a servlet knows which controls a call now your your dispenser which is not a Superman right it will know everything so what happens is when request goes to web.xml file it sends your request to despite the servlet now this for the servlet needs a configuration file so in that file you have to mention which request to call which controller but then you will say that's not good right because we were very happy with servlets no need I have no need for that extra file but hold out spring MVC provides you something called as annotations so all your controllers should be annotated with the help of controller so we have to use a controller annotation and that's it so with that kind of annotation every controller will have some mapping some mapping steps again we will see that when we do when we do programming or the Blacula implementation but every controller will have a mapping right you have to only mention that configuration file that in which package you have all your configuration and you're done I mean in which package you have audio controllers of course why these are Java files so it you'll be having all this thing in one particular package right or maybe multiple packages so you just have to mention which package you're working with that's it dispatches servlet will specify okay we have to go to this package to find the controllers you didn't have to do that it will be done by your spring MVC okay so let me repeat clients as a request request goes to web.xml file web.xml file says ok we have to send all the requests to the dispatcher servlet and this one subject will check the complication file and say ok we have to send that request to login controller now that login Toula will do some processing of course right when you when you call a method it is views it is done for with the help of it is done for the processing right so after the processing as a client what you need some page right so that controller will return you a page not exactly that controller will give you the name of the page because it might happen that you have lots of pages right so when you say you are building a website you will be having lots of views right when you say views I'm talking about the pages which a client sees right so there will be lots of pages which page to call that's a that's a question second to see we have a page right it needs two things first which pays to call second what is the data now data will be generated by your controller but which page to call you have to mention that in your controller it will mention the page name it will mention the data that data and the page name goes to the dispatcher servlet again your front controller you see that it's not directly controller to page it is through dispatch a servlet so the controller will send the response to the dispatcher servlet now this purchase of it will get two things the data and the view name it will call that particular view okay and it will also add so your view technology will fetch the data from the controller make sense and then that page goes from this first object to decline and if you can see everything is done by dispatcher servlet as a client you are only interacting with your front controller you don't even know how many controllers you have on the backend side right everything is done by your front controller then you will think you know everything is good but why do we need yy-your dispenser that should know which you to call it's because it may happen that let's say for time when you are using JSP as your wheel technology in future if you want to change your view technology let's say you want to use theme leaf if you want to use maybe some other velocity or Freema free marker if you want to use all this view technology just have to change the configuration file you just have to change the configuration file for your what it is for a servlet right you can change it from JSP to theme live like this change your views and just change the conjugation your controllers will not even know which technology which meu technology you're walking so that is the separation of concern your controllers don't know what we we are using and your view technology don't know what controllers we are using is that awesome is that flexible right so spring MVC is awesome there are lots of features you know I feel spring MVC is like a magic and as a developer VR magician right so it's an amazing technology to know more how to do all this request mapping and how to work with the controllers how to create this configuration file how to get a client we already know we'll see all those things in the practical session I hope you are liking this video please click on the like button and do subscribe because subscribers will more subscribers will I will get more motivated and able to make more videos so do subscribe and thanks for watching
Info
Channel: Telusko
Views: 517,073
Rating: undefined out of 5
Keywords: telusko, navin, reddy, tutorial, java, mvc, spring, spring mvc tutorial, spring mvc, spring mvc tutorial by koushik, spring mvc tutorial by koushik java brains, spring mvc tutorial for beginners, spring mvc interview questions and answers, spring mvc tutorial java brains, spring mvc tutorial for beginners with examples, spring day bts, springsteen eric church, spring day, springtrap, spring break, mvc 4, mvc 3, mvc infinite gameplay, mvc2, mvc infinite, java tutorial for beginners
Id: BkRZfxznaOo
Channel Id: undefined
Length: 9min 46sec (586 seconds)
Published: Wed Feb 08 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.