美文网首页
Spring Boot整合MyBatis + SQLite3

Spring Boot整合MyBatis + SQLite3

作者: 笑疯子 | 来源:发表于2019-03-05 21:22 被阅读18次

Spring Boot整合MyBatis + SQLite3

安装SQLite3

访问 SQLite下载页 下载sqlite-tools-win32-.zip 和 sqlite-dll-win64-.zip 压缩文件。

1). 创建一个文件夹,将下载的两个zip包解压到文件夹中

2). 配置环境变量,将文件夹目录配置配置到系统变量path中,例如我的路径为:E:\develop\sqlite,所以,配置如下图:

sqlite-path

3). 测试,在cmd命令提示符中,输入sqlite3即可

cmd中查看

初始化一个Spring Boot项目

1). 选择Spring Initializr

初始化

2). 选择打包方式以及包名等

打包方式等

3). 选择依赖,Web中勾选Web,在SQL中勾选MyBatis,选择工程位置,点击完成。

选择依赖

4). 配置pom文件,添加SQLite的依赖

<!-- SQLite 驱动 -->
<dependency>
   <groupId>org.xerial</groupId>
   <artifactId>sqlite-jdbc</artifactId>
   <version>3.21.0.1</version>
</dependency>

5). 配置文件

server:
    port: 18083
    servlet:
     session:
        timeout: 60
    
spring:
  datasource:
    url: jdbc:sqlite:E:/develop/SQLite/parcelx_fabric.db
    username:
    password:
    driver-class-name: org.sqlite.JDBC

# MyBatis配置
mybatis:
  mapper-locations: classpath*:io/parcelx/**/mapper/xml/**.xml
  type-aliases-package: io.parcelx
  configuration:
    use-generated-keys: true
    map-underscore-to-camel-case: true

6). 修改pom.xml让项目能读到mapper的xml文件

<resources>
    <resource>
        <directory>src/main/java</directory>
        <includes>
            <include>**/*.properties</include>
            <include>**/*.xml</include>
        </includes>
        <filtering>true</filtering>
    </resource>
    <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
    </resource>
</resources>

这样就可以直接的去写Controller、service、mapper了。

文章首发,我自己的博客,
笑疯子的博客

相关文章

网友评论

      本文标题:Spring Boot整合MyBatis + SQLite3

      本文链接:https://www.haomeiwen.com/subject/euoouqtx.html