Here is a transcript of what I learned from crud.
Because there is no database connected, pseudo-data in a static code block is used.
First, build the SPRINGMVC environment, import the jar package, and configure the Dispatcherservlet in the Web. xml file: Configuration file locations for front-end controllers and CONTEXTCONFIGLOACTION:SPRINGMVC (not configured if the default Springmvc profile is under Web-info Applicationcontext.xml file, and I am configuring Classpath:springmvc.xml, which is located in the SRC directory). Configure the annotation scan and view resolver in the Springmvc.xml file. Note: annotation scanning to the use of the annotated class are all included in the change path, or will be error, can not find the corresponding bean!
Second, create the Emtity class, employee and department, and add @repository annotations, create EmployeeDAO and Departmentdao, adding a method that has been censored, note: When invoking the method of another class, you need to give @ autowired annotations, otherwise not recognized!
Third, create the handler class, note: To submit data to the page, you need to use the map container to store the data in the map. Passing the data on the page into the method requires the use of the Post method, and the parameters of the corresponding object are passed in the method. such as: public void Save (Employee enployee) {...}.
There is also a modelattribute annotation, the use of parameters, the client passed the parameters will be injected into the specified object, and the object will be automatically added to the Modelmap, easy to use the view layer!!!
(Modelattribute annotations are important and need to be well understood)
Iv. write code on the JSP page to display the data. Note: The form label and Jstl label are used with SPRINGMVC.
Source Code Reference: Https://github.com/lenghui/springmvc-curd.git
SPRINGMVC-based CRUD operations