SPRINGMVC-based CRUD operations

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.