zoukankan      html  css  js  c++  java
  • SpringBoot 整合Mybatis操作数据库

    1.引入依赖:

     1 <dependency>
     2     <groupId>org.mybatis.spring.boot</groupId>
     3     <artifactId>mybatis-spring-boot-starter</artifactId>
     4     <version>2.0.0</version>
     5 </dependency>
     6 <dependency>
     7     <groupId>mysql</groupId>
     8     <artifactId>mysql-connector-java</artifactId>
     9 </dependency>
    10 <dependency>
    11     <groupId>com.alibaba</groupId>
    12     <artifactId>druid</artifactId>
    13     <version>1.1.10</version>
    14 </dependency>

    2.application.properties

    #DB Configation
    spring.datasource.driver-class-name=com.mysql.jdbc.Driver
    spring.datasource.url=jdbc:mysql://127.0.0.1:3306/springboot?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC
    spring.datasource.username=root
    spring.datasource.password=root
    # JPAConfiguration
    spring.jpa.database=mysql
    spring.jpa.show-sql=true
    spring.jpa.generate-ddl=true
    
    spring.freemarker.suffix=.ftl

    或application.yml

    spring:
      datasource:
        driver-class-name: com.mysql.jdbc.Driver
        url: jdbc:mysql://127.0.0.1:3306/springboot?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC
        username: root
        password: root
      jpa:
        database: mysql
        show-sql: true
        generate-ddl: true
      freemarker:
        suffix: .ftl

    3.在SpringBoot上增加启动类

    @SpringBootApplication
    @MapperScan(basePackages = "com.feiyu.user.dao")
    public class JpaApplication {

    public static void main(String[] args) {
    SpringApplication.run(JpaApplication.class, args);
    }

    }

    即可正常使用

  • 相关阅读:
    生命
    历史的分岔-中日产业发展史的对照和思考
    挑战自已
    丰台往事已成风,上下求索永不停
    VC6.0实现鼠标光标形状及大小的定制
    RelativeLayout
    16进制颜色代码
    html里的option错误
    Android用户界面设计:布局基础
    Activity详细介绍【官网】
  • 原文地址:https://www.cnblogs.com/crazy-lc/p/11801229.html
Copyright © 2011-2022 走看看