SSM framework building and learning (2) --- integration of MyBatis and SpringMVC,

Source: Internet
Author: User

SSM framework building and learning (2) --- integration of MyBatis and SpringMVC,

 

After setting up the Mybatis environment, we can use Java Code to get the data we want from the database, but a complete project must have a front-end, so the communication between the front-end and the back-end Java will use the SpringMVC framework we are familiar with. With SpringMVC, we can submit the front-end data to Java Contoller, then, use Mybatis to enter the database to query the desired data and return to the front-end.

So there are both Mabatis and SpringMVC, we need to find a way to integrate the two, that is, the integration of configuration files.

1. Let's take a look at SpringMVC? The mvc framework provided by a product in the spring framework implements functions similar to struts. Main functions: Collect form information, process data, and redirect after processing.

2. Start.

1) first download the jar package of Spring.

Address: http://maven.springframework.org/release/org/springframework/spring/

After downloading the jar package, you can add the nine jar packages. If you want to add other jar packages later.

    

2) Prepare the springmvc environment and configure web. xml.

Spring mvc is based on servlet, so you need to configure DispatcherServlet in web. xml!

Add these two tags to web. xml

  

Pay special attention to servlet-name, which is used to create the springmvc configuration file.

3) create springmvc configuration file WEB-INF under spring-servlet.xml

The name of spring must be the same as that of servlet-name in web. xml!

    

Where:

A. annotation-driven <mvc: annotation-driven/>

B. Set the package name of the controller scan path. spring mvc will automatically instantiate the controller under the package. The controller is equivalent to the action in struts. It is used to process data and complete forwarding.

<Context: component-scan base-package = "javastudy"/>

C. Other configurations are the same as those of spring.

III. in this way. the springMVC configuration file is ready. After SpringMVC is added, the view is OK. however, this is not enough. To be able to run normally, the Spring framework is essential. In the next chapter, let's talk about how to integrate Spring to form the final SSM framework!

    

 

 

 

  

 

    

Related Article

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.