[MyBatis] Learning summary three: Spring Boot integrates MyBatis

After learning some usages of MyBtais, I still wrote my personal blog - cms to check whether the MyBatis I learned is available. What is worth celebrating is that the simple cms system is online, the front and back ends are separated, and Spring Boot is developed. A RESTful API for front-end calls.

When learning MyBatis, we know that he has a public configuration file mybatis-config.xml, but when we use Spring Boot to integrate MyBatis, this public configuration file is no longer used. So, where do we write the public configuration file of MyBatis? ?

The answer is application.properties.

In fact, it is very early, in the official documentation of MyBatis has already said how MyBatis integrates with Spring Boot

MyBatis-Spring-Boot-Starter

Very simple, Spring Boot will help us with automatic configuration.

application

mybatis.type-aliases-package=com.example.domain.model
mybatis.type-handlers-package=com.example.typehandler
mybatis.configuration.map-underscore-to-camel-case=true
mybatis.configuration.default-fetch-size=100
mybatis.configuration.default-statement-timeout=30

This is an example provided by the official website.

Summarize

1. Look at what configuration can be provided to us in the configuration file, which may help us to a great extent.

SpringBoot supports MyBtis configuration

2. In actual projects, multiple configuration schemes may be required: configuration during development, configuration during testing, and configuration when going online. Be flexible.

spring.profiles.active=dev

3. Finally, let's look at a common configuration:

mybatis.type-aliases-package=com.fengwenyi.demo1.entity
mybatis.mapper-locations=classpath:mapper/*.xml

material

1、mybatis-spring-boot-autoconfigure

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325563769&siteId=291194637