• springboot + Mybatis


    1.maven添加dependency

    <!--数据库开始-->

    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jdbc</artifactId>
    </dependency>
    <dependency>
    <groupId>commons-dbcp</groupId>
    <artifactId>commons-dbcp</artifactId>
    <version>1.4</version>
    </dependency>
    <dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-pool2</artifactId>
    <version>RELEASE</version>
    </dependency>
    <dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.29</version>
    </dependency>
    <dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>druid</artifactId>
    <version>1.1.10</version>
    </dependency>
    <dependency>
    <groupId>org.mybatis.spring.boot</groupId>
    <artifactId>mybatis-spring-boot-starter</artifactId>
    <version>1.3.2</version>
    </dependency>

    2.yml添加数据库连接参数

      

    server:

    port: 8016

    spring:
    cache:
    ehcache:
    config: classpath:/ehcache.xml

    datasource:
    url: jdbc:mysql://127.0.0.1:3306/ipt?useUnicode=true&characterEncoding=utf8&useSSL=false&allowMultiQueries=true
    username: root
    password: 123456
    driver-class-name: com.mysql.jdbc.Driver

    mybatis:
    type-aliases-package: com.example.demo.entity
    mapper-locations: classpath:mapper/*.xml

     3.启动类注释需要扫描文件的路径,添加bean 

    @MapperScan("com.example.demo.dao") //扫描的mapper(*Mapper.java)

    4. 在resource/mapper 目录下建 *Mapper.xml,编写sql语句

    5.实体类entity , user.java

    说明:

    3-5可以通过mybatis generator插件自动生成。

  • 相关阅读:
    Develop an Android Application
    有效提高编程技能
    如何提高团队编程水平
    ruby测试框架
    grep:Binary file (standard input) matches
    python datetime相减
    软件开发的“三重门
    Linux高手之路SVN使用笔记
    机器io高原因排查全命令指南
    代码如写作
  • 原文地址:https://www.cnblogs.com/heshana/p/13188376.html
Copyright © 2020-2023  润新知