SPRINGMVC (ii) various configurations for the SSM framework Integration

Source: Internet
Author: User

SSM:SPRINGMVC, Spring, mybatis the integration of the three frameworks, patience step by step.

--wh

I. SSM Framework Integration

1.1. Integration Ideas

From the bottom of the integration, that is, the first integration of MyBatis and spring, and then write Springmvc.

1.2. Development Requirements

Query Product list (query from database)

1.3. Create a Web project

          

Now SSM project creation is different from the original DAO, service, the web such as the three-level directory, now is mapper, service, controller such directory, Mapper is equivalent to the previous DAO, The controller is equivalent to the previous web, changing the name. Don't read it.

1.4. Add Jar Package

This jar package, the Internet direct Baidu SSM integrated jar package can be

Database-driven, MyBatis core, dependency packages, mybatis and spring integration packages, DBCP connection pool packages, spring packages (including SPRINGMVC packages), AOP dependency packages, Jstl packages, common-logging packages

          

1.5. Start to integrate mapper (MyBatis and spring integration)

Detailed integration ideas explained: MyBatis and spring integration here I directly on the code. Steps

1.5.1, Sqlmapconfig.xml

          

Sqlmapconfig.xml

Configuration of 1.5.2 and Applicationcontext-dao.xml

               

It is important to note that when specifying the path to the global configuration file for MyBatis, that is, when value= "Classpath:SqlMapConfig.xml", if there is a hierarchy of directories in the config file directory of the configuration created, you need to add, for example , config below is divided into MyBatis and spring, then you need to write value= "Classpath:mybatis/sqlmapconfig.xml", see according to your own needs to write

            

Applicationcontext-dao.xml

               

1.5.3, db.properties Configuration

            

Db.properties

1.5.4, develop mapper, add the reverse engineering generation

            

Note: Mapper development, the first to be based on the needs of analysis, whether matching the reverse engineering generated code, if the match is successful, you do not need to develop mapper; if it does not match, then expand a new mapper interface and mapper mapping file to handle the demand, popular point, Is whether the functionality defined in the Mapper interface generated by reverse engineering meets the needs of our development, because reverse engineering is generated for single-table operations, and we sometimes need more complex queries, so if we need to create mapper interfaces and mapper mapping files ourselves, is actually the extension function.

1.6. Integrated service

Add a applicationcontext-service.xml configuration file to handle transactions,

Applicationcontext-service.xml: If you don't understand the meaning of the code, look at the article that explains spring management transactions. Copy the paste directly here, modify some package names, etc.

          

Applicationcontext-service.xml

1.7. Integrated Controller

That means using SPRINGMVC. Very simple.

1.7.1, configuring the front-end controller in Web. XML dispatcherservlet

          

Configuration of the front controller Dispatcherservlet in Web. xml

1.7.2, Configuration Springmvc.xml

          

Springmvc.xml

1.8. Integrate Spring configuration file

is to load all of the spring configuration files to start. That is, configuring the spring Listener in Web. xml

              

Configure load Spring containers and listeners in Web. xml

1.9, summarize all the configuration such as

              

1.10. Deployment Test

1.10.1, Query the product list (query from the database)

1. Write Service layer

Itemsservice interface

              

Itemsserviceimpl implementation classes do not use annotation development

              

The bean that configures the service in Applicationcontext-service.xml

                

Itemsserviceimpl implementation class uses annotations, you do not need to configure the service's Bean in Applicationcontext-service.xml

              

2. Write Controller layer

There are many ways to write this layer, I remember the previous section, such as implementing the Controller interface, using annotations and so on, generally directly using annotations.

Itemscontroller

                  

3. Add JSP page

              

itemslist.jsp

4. Testing

Http://localhost:8080/ssm_test01/queryItems.do, that is, success

              

Second, summary

In this way, the SSM framework integration is over, very simple, follow the steps, first consolidate MyBatis and spring, and then integrate SPRINGMVC. Practice a few times on your own. The next article will be based on this, explaining the various small functions of SPRINGMVC, such as SPRINGMVC parameter binding, Springmvc verifier, image upload and so on.

SPRINGMVC (ii) various configurations for the SSM framework Integration

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.