yml配置文件内容
spring:
application:
name: user
datasource:
type: com.alibaba.druid.pool.DruidDataSource # 配置当前要使用的数据源的操作类型
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://192.168.0.129:3306/hd?characterEncoding=utf-8&&useSSL=false
username: root
password: 123456
dbcp2:
min-idle: 5 # 数据库连接池的最小维持连接数
initial-size: 5 # 初始化提供的连接数
max-total: 5 # 最大的连接数
max-wait-millis: 200 # 等待连接获取的最大超时时间
thymeleaf:
cache: false
server:
port: 8081
logging:
level:
com.learnhow.springboot.mybatis.dao: debug
mybatis:
mapperLocations: classpath*:mapper/*.xml
启动类
package base;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
/**
* Hello world!
*/
@EnableEurekaClient
@SpringBootApplication
@MapperScan("base.dao")
public class UserApplication {
public static void main(String[] args) {
SpringApplication.run(UserApplication.class, args);
}
}
注意事项
dao层(务必加上@Mapper注解)
mapper.xml
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): base.dao.UserDao.queryById 错误原因
配置文件遗漏
mybatis:
mapperLocations: classpath*:mapper/*.xml