Springmvc learning notes (6)-springmvc integration mybatis (built using maven in IDEA)

Source: Internet
Author: User

Springmvc learning notes (6)-springmvc integration mybatis (built using maven in IDEA)
Springmvc learning notes (6)-springmvc integration mybatis (built using maven in IDEA)

This article mainly shows how to build the springmvc + mybatis framework development environment through maven in intellij IDEA.

Requirement: Use springmvc and mybatis to query the product list

Integration ideas

Step 1: Integrate the dao Layer

Integrate mybatis with spring and use spring to manage er interfaces. Use the er scanner to automatically scan mapper interfaces for registration in spring.

Step 2: Integrate the service layer

Use spring to manage the service interface. Configure the service interface in the spring configuration file. Implement transaction control.

Step 3: integrate springmvc

Springmvc is a spring module and does not need to be integrated. Engineering Structure

Unlike the demo in mybatis Study Notes (17)-spring and mybatis integration,The integration in this article is built using maven.

For how to create a web application built using maven, refer to the previous article springmvc learning notes (1)-framework principles and getting started configuration.

new->project->mavenCreate a bare maven project and manually create a webapp directory

Insrc/mainCreate a folderwebapp

Add dependency

Pom. xml file

<code class="language-xml hljs "><!--{cke_protected}{C}%3C!%2D%2D%3Fxml%20version%3D%221.0%22%20encoding%3D%22UTF-8%22%3F%2D%2D%3E--><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">    <modelversion>4.0.0</modelversion>    <groupid>com.iot.learnssm</groupid>    <artifactid>learnssm-firstssm</artifactid>    <version>1.0-SNAPSHOT</version>    <packaging>war</packaging>    <properties>        <project.build.sourceencoding>UTF-8</project.build.sourceencoding>        <!--{cke_protected}{C}%3C!%2D%2D%20jar%20%E7%89%88%E6%9C%AC%E8%AE%BE%E7%BD%AE%20%2D%2D%3E-->        <spring.version>4.2.4.RELEASE</spring.version>    </properties>    <dependencies>        <!--{cke_protected}{C}%3C!%2D%2D%20spring%E6%A1%86%E6%9E%B6%2D%2D%3E-->        <dependency>            <groupid>org.springframework</groupid>            <artifactid>spring-webmvc</artifactid>            <version>${spring.version}</version>        </dependency>        <dependency>            <groupid>org.springframework</groupid>            <artifactid>spring-core</artifactid>            <version>${spring.version}</version>        </dependency>        <dependency>            <groupid>org.springframework</groupid>            <artifactid>spring-orm</artifactid>            <version>${spring.version}</version>        </dependency>        <dependency>            <groupid>org.springframework</groupid>            <artifactid>spring-aspects</artifactid>            <version>${spring.version}</version>        </dependency>        <dependency>            <groupid>org.springframework</groupid>            <artifactid>spring-test</artifactid>            <version>${spring.version}</version>        </dependency>        <dependency>            <groupid>org.springframework</groupid>            <artifactid>spring-jdbc</artifactid>            <version>${spring.version}</version>        </dependency>        <dependency>            <groupid>mysql</groupid>            <artifactid>mysql-connector-java</artifactid>            <version>5.1.38</version>        </dependency>        <dependency>            <groupid>org.mybatis</groupid>            <artifactid>mybatis</artifactid>            <version>3.3.1</version>        </dependency>        <dependency>            <groupid>org.mybatis</groupid>            <artifactid>mybatis-spring</artifactid>            <version>1.2.4</version>        </dependency>        <dependency>            <groupid>log4j</groupid>            <artifactid>log4j</artifactid>            <version>1.2.17</version>        </dependency>        <dependency>            <groupid>org.slf4j</groupid>            <artifactid>slf4j-api</artifactid>            <version>1.7.18</version>        </dependency>        <dependency>            <groupid>commons-dbcp</groupid>            <artifactid>commons-dbcp</artifactid>            <version>1.4</version>        </dependency>        <!--{cke_protected}{C}%3C!%2D%2D%20JSP%20tag%20%2D%2D%3E-->        <dependency>            <groupid>javax.servlet</groupid>            <artifactid>jstl</artifactid>            <version>1.2</version>        </dependency>        <dependency>            <groupid>taglibs</groupid>            <artifactid>standard</artifactid>            <version>1.1.2</version>        </dependency>    </dependencies></project></code>

There may be many dependencies added here, but they are always better than less-subscribed ones. I started to introduce less dependencies (springframework dependencies only reference spring-mvc, even if spring-core is not introduced), an error will be reported. In the future, a blog will be devoted to debugging problems in this series of notes.

Build package

Create each package in the java directory according to maven's explicit habits:

Com. Company Name. Project name. Module name

Here, my package is:

com.iot.learnssm.firstssm

Contains several sub-packages:

Controller mapper po service
Impl

Project Structure

The following notes record the integration of mapper, service, and controller.

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.