springboot integrated development mybatis

1. Start by creating springboot project

Click: http: //start.spring.io/ can create springboot project online

2. Add the pom file mybatis

<dependency>

<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.4</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>

3. Write the configuration file (application.yml)

spring:
datasource:
url: jdbc:
username: 
password: 
driver-class-name: com.mysql.jdbc.Driver
jpa:
properties:
hibernate:
current_session_context_class: org.springframework.orm.hibernate5.SpringSessionContext
dialect: org.hibernate.dialect.MySQL5Dialect
hbm2ddl:
auto: update
show-sql: 'false'

mybatis:
mapper-locations: classpath:com/ms/mapper/*Mapper.xml  (配置这个包下面的所有mapper)

4. Write entities

 

5. mapper write entity of (@Mapper identify such entities as the mapper. Mybatis loaded when the project will be loaded by looking for the logo)

6. Develop mapper.xml entity of

 

 7. Writing class service and impl

8. The test write controller (springboot unit may also be used to test)

9. Test Results

 

 

 

That's all good tutorial springboot of integrated mybatis. Part II explains how to use mybatisPlus to achieve automatic code generation, so we can better focus to achieve business layer.

 

Guess you like

Origin www.cnblogs.com/MisterLiu/p/10984418.html