2018 - SpringBoot 集成 Mybatis 及 Freemarker 的使用

一、application.yml 配置如下

ERROR : Failed to load property source from location 'classpath:/application.yml'

注:因为格式或编码问题,所以就把注释去掉了

server:
  #servlet:
    #context-path: /springboot
  port: 80

spring:
  datasource:
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8
    username: root
    password: 200206
    dbcp2:
      min-idle: 5
      max-idle: 30
      initial-size: 10
      max-wait-millis: 300

mybatis:
  configuration:
    cache-enabled: true
    lazy-loading-enabled: true
    aggressive-lazy-loading: true
    multiple-result-sets-enabled: true
    use-column-label: true
    use-generated-keys: true
    auto-mapping-behavior: partial
    default-executor-type: simple
    map-underscore-to-camel-case: true
    local-cache-scope: session
    jdbc-type-for-null: null
    call-setters-on-nulls: true

Freemarker 的依赖,小编已经在搭建SpringBoot的时候选择过了

二、创建测试所需类

默认是 index ,不需要手动

注:Freemarker 必须经过服务端才可跳转,跳转时不能使用重定向与后缀

2018 - SpringBoot 集成 Mybatis 及 Freemarker 的使用

如果连接数据库出现 CLIENT_PLUGIN_AUTH 

解决方案:修改pom.xml,将mysql-connector-java的版本退回到5.1.34

2018 - SpringBoot 集成 Mybatis 及 Freemarker 的使用