Target:
Today we are going to realize the function which update our employee's informations
What you need:
(1) you need a update.html
(2) in the EmployeeController you need add something else
(3) in the list.html you also have to add something else
The details:
(1) first let us put our action on the page which named list.html,please attention the red underline. In the very begining it was a <button> mark, now we have to change it to a mark. Otherwise it do not work.
by the explain about <a> to a conclusion ,we can learn about it can transfer some key fields what we set to the other page or the controllers.
and then @{/emp/} means the url which will be caught by the controller and the ${emp.getId()} means the transfer not just taking the url, it also will take the the values.
(2) now please turn our focus on the EmployeeController.
first,we can see the annotation @GetMapping() not only caught the url but also can get the id value of the object. And then @PathVariable can get the Id what the list.html send. next we can use the id to get the object of Emplyee, now it's time to send the object to the front end,so here we use model's addAttribute(). what's next we also can get the all departments whch means we can get the department what we need by id index which we set. In a nutshell, we will return the url which means will be caught tomcat and transfer to the update.html
(3) In here we can get the value by thymeleaf, but there is a thing we have to pay a attention to..... th:check="${emp.getGenter()==1)" means the deault set number (right) will according the value (left) what it get in the object feild.
so here are the same reanson~, but if we not get the original id, the id will get by auto . so the result what we get and see in the end probably will become update opration to add opration.
but most of time we don't want to show the id
so we need to add this code whose function is hidden the id.
In here if we not set the date's format we probably can see that sign. and you probably wander about that why the placeholder do not work now, because you have already set the value in the form.
if we add there is another sign we probably can see
(4) So in here we will use the method post to sumbit the url.
finally, we just need to save it and redirect to the emps
and the emps will return to the list.html.