Spring-MyBatis

配置文件

  • pom.xml

springboot


    org.mybatis.spring.boot
    mybatis-spring-boot-starter
    1.3.2

spring-mybatis


    org.mybatis
    mybatis-spring
    1.3.2

mysql


    mysql
    mysql-connector-java
    8.0.12

  • application.yaml
mybatis:
  type-aliases-package: org.wyv.monitor.mapper #mapper接口文件位置
  configuration:
    map-underscore-to-camel-case: true #驼峰声明方式
    default-statement-timeout: 30 #SQL运行超时时间
  mapper-locations: classpath:mappers/*.xml #SQL代码文件存放位置

代码

  • java接口文件
@Mapper
@Component("XXXDao") //不用这个会出现报错的情况
public interface XXXMapper{

    List querySOAMessageLogOfHourToday(HashMap map);

}
  • Mapper文件



    


添加springboot配置

application.yml

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/db_cqt?useUnicode=true&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true
    username: root
    password: 12345678
    driver-class-name: com.mysql.cj.jdbc.Driver
  aop:
    proxy-target-class: true
mybatis:
  type-aliases-package: org.yiva.cqtserver.mapper
  configuration:
    map-underscore-to-camel-case: true
  mapper-locations: classpath:mappers/*.xml
server:
  port: 9001

pom.xml



    4.0.0
    
        org.springframework.boot
        spring-boot-starter-parent
        2.1.1.RELEASE
         
    
    org.yiva
    cqtserver
    0.0.1-SNAPSHOT
    
    jar
    demo
    Demo project for Spring Boot

    
        1.8
    

    
        
            org.springframework.boot
            spring-boot-starter-web
        

        
            
            
            
        
        
            org.springframework.boot
            spring-boot-starter-test
            test
        
        
            org.springframework.boot
            spring-boot-starter-aop
        

        
        
            org.mybatis.spring.boot
            mybatis-spring-boot-starter
            1.3.2
        
        
        
            mysql
            mysql-connector-java
            8.0.12
        

        
            com.alibaba
            fastjson
            1.2.49
        
    

    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    



目录结构

目录结构

你可能感兴趣的:(Spring-MyBatis)