Home > Common Problem > What are the steps to integrate spring with mybatis?

What are the steps to integrate spring with mybatis?

爱喝马黛茶的安东尼
Release: 2019-07-29 11:27:15
Original
7340 people have browsed it

Mybatis is an upgraded version of ibatis, a persistence layer framework based on Java. Mybatis is an excellent persistence layer framework that supports ordinary SQL queries, stored procedures and advanced mapping. Mybatis eliminates almost all manual settings of JDBC code and parameters and retrieval of result sets. MyBatis uses simple XML or annotations for configuration and original mapping, mapping interfaces and Java POJOs (Plain Old Java Objects, ordinary Java objects) into records in the database. Compared with "one-stop" ORM solutions such as Hibernate and Apache OJB, Mybatis is a "semi-automated" ORM implementation.

What are the steps to integrate spring with mybatis?

1. Create a maven project and build an infrastructure layer

##entity book entity bookid bookname bookprice

dao IBookDAO Add book method addBook()

IBookDAO.XML Sql statement to add book name and price

service has the same method of adding book as dao layer addBook()

serviceimpl Rewrite the addBook() method to inject a dao return dao.addBook()

What are the steps to integrate spring with mybatis?

2. Dependencies of pom files

What are the steps to integrate spring with mybatis?

<!--Mybatis+Spring整合-->
<dependency>
    <groupId>org.mybatis</groupId>
    <artifactId>mybatis-spring</artifactId>
    <version>1.3.0</version>
</dependency>
<!--mybatis依赖包-->
<dependency>
    <groupId>org.mybatis</groupId>
    <artifactId>mybatis</artifactId>
    <version>3.4.1</version>
</dependency>
<!--mysql依赖包-->
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.39</version>
</dependency>
<!--spring JDBC依赖-->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-jdbc</artifactId>
    <version>4.2.0.RELEASE</version>
</dependency>
<!--spring基础jar-->
<!-- https://mvnrepository.com/artifact/org.springframework/spring-beans -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-beans</artifactId>
    <version>4.2.0.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>4.2.0.RELEASE</version>
</dependency>
Copy after login

Related recommendations: "

FAQ"

3. Configuration file under resources

What are the steps to integrate spring with mybatis?

What are the steps to integrate spring with mybatis?

1.jdbc.properties configuration file writes the url to which you are connecting to the database , driver, username, password

Because my Mysql has no password, I don’t need to write password

What are the steps to integrate spring with mybatis?

2.MyBatis-configuration.xml configuration file

You only need to configure an alias

What are the steps to integrate spring with mybatis?

3. The next step is the configuration of the most important applicationContestSSM.xml file

When binding bookservice The ref attribute IBookDAO in the property is red and cannot be recognized by the tool. It is an object stored in memory and can only be obtained by running it. Therefore, the color display is abnormal and does not affect the compilation and operation.

What are the steps to integrate spring with mybatis?What are the steps to integrate spring with mybatis?What are the steps to integrate spring with mybatis?

4. Create a test class and use junit

What are the steps to integrate spring with mybatis?

to test success! Go to the database to query the added book title and price. At this point, a simple integration case is finished!

What are the steps to integrate spring with mybatis?

The above is the detailed content of What are the steps to integrate spring with mybatis?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template