Home >Common Problem >What are the steps to integrate spring with mybatis?
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.
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 priceservice has the same method of adding book as dao layer addBook()serviceimpl Rewrite the addBook() method to inject a dao return dao.addBook()2. Dependencies of pom files
<!--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>Related recommendations: "
FAQ"
3. Configuration file under resources
4. Create a test class and use junit
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!