Configuring mybatis to Springboot project in IDEA

In https://www.cnblogs.com/liuliang1999/p/12635282.html a text that we have built a good Springboot an empty project, the following will describe how to integrate depend mybatis.

 

1, added in pom.xml its dependencies, may have been added Well, here designated realize I am using a database MySQL, and then Alibaba druid effect after additional information on the connection pool.

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>8.0.19</version>
</dependency>
<dependency>
    <groupId>org.mybatis.spring.boot</groupId>
    <artifactId>mybatis-spring-boot-starter</artifactId>
    <version>2.1.1</version>
</dependency>
<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>druid</artifactId>
    <version>1.1.21</version>
</dependency>

2. Create a directory application.yml in resource files, configuration database connection information in it (you can also use the default properties file, think yml configuration is more concise)

Server: 
  Port: port number Start # 7777 
Spring: 
  DataSource: # data source 
    type: com.alibaba.druid.pool.DruidDataSource # connection pool 
    Driver-class-name: com.mysql.cj.jdbc.Driver 
    URL: JDBC: MySQL : // localhost:? 3306 / your database name = GMT% 2B8 serverTimezone & characterEncoding = UTF-8 
    username: your login 
    password: your login password

3, Mybatis mapping relationship configured similarly provided in application.yml

mybatis:
  type-aliases-package: xyz.gisliuliang.esngis.pojo.entity
  mapper-locations: classpath:mybatis/mapper/*Mapper.xml
type-aliases-package is the package corresponds to your database where the entity class, the new mapper package under resources / mybatis, will be behind the new interface and a corresponding file mapping *** Mapper.xml in this package

Guess you like

Origin www.cnblogs.com/liuliang1999/p/12635404.html