Hi friends, welcome to TutorSwan channel. In our last class we saw how to work with the student part right
How to read the student details. So we see how to merge two tables. All the stuff we discussed about our student management system using Spring Boot Part 3 Tutorial
In this tutorial I am going to discuss about how to add the student right. So first what I am going to do is I am going to run the project
So select the main class. Here we have to type run as job right. Now you can see the Spring Boot which is running
All right. It is working perfectly. There is no error. Now let's go to the browser and check it. The port, localhost, the port which I am using
Right. Student. It is working perfectly. Now here there will be the add button right. If you click the add button here nothing happens
Now we are going to do the process right. So first what I am going to do is here. I didn't implement at any pages right
So here select the template folder. Right click. New. Others. Select HTML5 next. Add student. Add student. .html. This is the page which I am going to create
Click finish. Now the page has been created successfully. Now what I am going to do is here. So here I will just copy this one and paste it here
Don't worry about this. All the source code I provided in my website you will be able to download it because the time consumes so that I have just copy and paste this code
Because this is simple HTML layout right. So this is the tag. Inside the tag we have bootstrap. All the plugins are there. CSS and JS files
Inside the body we have created the div class. Div class we have added in create a course. After that we have a form. I have created a simple form
The form has a field. Right. First student name. We have input field. After student course. This is very important stuff. After that C. We have three fields there. One submit button
Right. The course. This one should be the important stuff. So here course. We can't enter the course over here. Right. Instead of enter the course. Instead of putting input box
I have put into the drop down. So you will be able to select the course. What is the course you are inserting into the database. What is the course available in your database
For the course name. This course name I have put into the drop down. You are able to select from the drop down. What is the course they selected. Right
That is the things I have need to be done over here. Right. That's the things we have done over here. Right. So that's it. We have done over here. Right
Now let's go to the controller and do the future stuff. Right. Go to the controller. Student controller. Student controller we have all the things we have implemented. Right
This is the add student. Ok. So we have to implement something stuff. So here in the page. Ok. So we have the student index controller page
This page we have a. Right. Ok. So. Right. So when the student come to this page. When the student click on the link of student. It's coming to the student page. Right
This student page we have to create a new student. If you click on this one. It goes to the URL to add student. Right. So this is the URL. This is the page of this. So here I have given the link over here
Add new. Add new means this is the add new part. We have given here. This is the controller. Right. Student controller. The action method we are calling add student
So go to the student controller. Action method we are calling add student. Add student we have given the thing like this. Ok. List of student we are going to load. List of courses we are going to load
Why I am going to load the list of courses means. Then this page is appear on the screen. Along with the course details will be loaded. Right. Ok
When you click on the particular link of the add new student. You will be able to visit the page. When the page is appear on the screen. It is loaded along with the course details
It will be loaded along with the course details over here. That is the thing done so far over here. This course will be explained things. Right. So here this one. List of courses. This is the list of students we are getting. Add student. All the stuff. Ok
This is the thing what is the things mean. This is the student. Add student. Ok. When you add student over here. Course of page. Ok. After that we have a method called save method. We will be explaining it later on. This solves. AD can deal all the stuff. First we have to make this only. Save button. Ok
So let me do the stuff. Ok. Now let's execute the program and check that it is working fine or not. There is the save all. Go here. Click on this one. Terminate and Relaunch. Ok
Once you run the application on the screen boot. No need to run over here. First time only you have to run. After that we have to go to the debug mode. You have to right click and terminate and relaunch. Right. If you have run again by again here. You need to change the fault. Ok. It showed error. Your code already running. Ok. So you execute only once a time over here
After execute the program one time. After that go to debug mode and you have to just stop the project and you have to rerun. Ok. After make the changes. Right. So let's go to go here and refresh the one. Ok. Refresh. Click on this one. Oh it successfully went here. It successfully redirected to the page. Ok. Along with the course drop down. See here. This is drop down. Ok. Here what is the courses are there. It will be drop down over here
The user able to select the course. What is the course they need and they will be able to register. So here I am going to enter the students. What are the students. I am going to enter the different name. Ganesha as a student. Course I am going to get as G.H.P. See I am going to get as 10,000. Click save button. Why what's the problem. It's not working. Let's go here
What was the error. You just go here and find it. Course does not have a default value
See go through the error. The problem said course does not have a value means I have a field called course. The course. Write this course. Guys know I am not setting to the. See this one should be the class student.java. See we have to implement it over here. This one. When you are going to add the record you have to call this class. Right
This is the merchant class. Student. This is the class where we are going to add the record. See I didn't add the property. That is the problem. So just copy this. This is the course. So I have to give the correct name over here
Course. This one should be the int data type. Because we are only getting the data as relevant ID only. Not a course. When you select the course of the drop down. From the drop down. Instead of the course name we have to add that into the respective ID. Ok when you add the insert the recording to the database. That is the things we need. That is the professional way to add the recording to the database
So here we have to make it as data type int. So we have to remove it. Again I am going to generate the get and set method. Go to source. Generate the get and set method. We have to select all. Generate. With generator. Save all
Go over here and run it. Go here. Press enter key. Come here. Click on the student. Add student. Student name Raja. Course I am going to give free
Here you have 13000. See. Click save button. Right here. Record error successfully. If you want to add it one more time. Go here. Raja. Just select this course. This one course. Right. So I am going to create a new course. That is a good stuff. So I am going to create a new course
Right. Ok. This header should be visible to all the pages. We will need later on. Ok. Though it is simple. I am going to create a new course. That simple course I am going to give as a PHP. Duration 6 months. Click save button. Right
Now we are going to go to the student part. Student. Click here. You will be able to see the course PHP. Student Raja. See I am going to interact with 15000. Click save button. It is working perfectly well. That is working perfectly well
Right. I hope that you understood that thing well. In my next tutorial I will be teaching to how to edit the record and delete the record. If you have any doubt on this. You can ask me anytime. So it is very simple. I am going to explain the insert part. Right
So I am going to create a new button. I am going to go to which page. It is a student controller. Action method will be add student. So you go here. Get mapping. It is a get mapping. Get request mapping. You are getting the student request. You are coming here. It received the URL. This URL. You are in this
This particular URL you have received. This is an action method. So getting the request mapping student. This action method is getting. This particular model will be loaded and show the student details of the list of courses. All the courses it will be loaded
After that when you click save button. Save button is here. Add student. This is all the data. Click save button. Save button. It closes the student controller. Save method. Student controller. Save method. It retrieves all the details from the form
So getting to here. Getting to the controller. Getting the controller model. Right. Getting all the details. So here we have to load the details. So you have to put into here
Service. There will be the save method. Service means this is saved. Service means the course student service. There will be the service. Right. So if you go to the student service. What it does. It is managed by all the thread operations. Right. When you click save button. It goes to the student. Get the student details. Repository. Repository via it will be communicated to all the details. It will be communicated with the thread operations. Right
It will be communicated with the thread operations. It will go to the repository. It will be sending the details to the model. Model means the domain. This one will be communicated with the data version. If all the fields are correct. FC name course and all the fields can access this similar page. This name. This name. FC name course. Ok
If it is correct. The data should be accessed into the database. This is the flow working on Spring Book. Right. Ok. Controller will be communicated with the service. Service will be communicated with the repository. Repository will be communicated with the model. Model will be communicated with the database. Record will be added to the database. Right
First template will be crawling to the data and to the controller. Ok. Controller will be passing the data to the service. Service will be passing the data to the repository. Repository will be communicating the database to the layer will be the model. Right. Model will be communicating the database and data added in the database. Right. This is the process you must know about when you are working with Spring Book. This is very important stuff when you are developing the project using Spring Book
Don't worry about that. This source code I provide you. I promise. I will reveal all my secrets what I am having. I am not hiding anything else. Ok. So far. Right. Thank you for watching. If you have any doubt you can ask me anytime. When I am live you can ask me any doubt. Thank you for watching. If you have any doubt you can ask me. Right