SpringBoot 整合 SQLite 数据库

1、SQLite 简介

SQLite 是一个很轻量的关系型数据库,不需要安装服务,数据存储在文件里。

2、引入pom依赖

复制代码
        <!-- SQLite  -->
        <dependency>
            <groupId>org.xerial</groupId>
            <artifactId>sqlite-jdbc</artifactId>
            <version>3.34.0</version>
        </dependency>


        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid-spring-boot-starter</artifactId>
            <version>1.2.9</version>
        </dependency>

        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.5.1</version>
        </dependency>

3. 修改配置文件

复制代码
spring:
  datasource:
    url: jdbc:sqlite:identifier.db
    driver-class-name: org.sqlite.JDBC

mybatis-plus:
  configuration:
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
    cache-enabled: true
    map-underscore-to-camel-case: false
  global-config:
    db-config:
      logic-delete-field: isDeleted
      logic-not-delete-value: 0
      logic-delete-value: 1
复制代码
identifier.db 就是生成的SQLite 数据库文件

4. 代码

Mapper

复制代码
package com.hejjon.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hejjon.entity.User;

public interface UserMapper extends BaseMapper<User> {
    
}

Controller

复制代码
@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserMapper userMapper;

    @GetMapping("getById")
    public User getById(@RequestParam("id") String id) {

        return userMapper.selectById(id);
    }

}

5. IDEA操作

在idea里可以创建SQLite 的数据库和表

相关推荐
qeen876 小时前
【C++】类与对象之类的默认成员函数(二)
android·c语言·开发语言·c++·笔记·学习
m0_736034856 小时前
存储基础和虚拟化
笔记
AOwhisky8 小时前
MySQL 学习笔记(第六期):MySQL 备份与恢复
运维·数据库·笔记·学习·mysql·云计算
华山沦贱9 小时前
open62541 V1.5.4版对C++ Builder支持的bug
笔记
稷下元歌9 小时前
七天学会plc 加机器视觉完整笔记:S7-1200 数据类型、存储区与寻址方式(I/Q/M/DB 详解)。
网络·数据库·笔记
逸模10 小时前
AI+BIM 重构连锁公装新范式 逸模打造数字化营建核心底座
大数据·人工智能·笔记·其他·信息可视化·重构
xqqxqxxq10 小时前
树结构技术学习笔记
数据结构·笔记·学习
十月的皮皮11 小时前
C语言学习笔记202606008- 三角形判断(3种方法)
c语言·笔记·学习
XGeFei11 小时前
【Fastapi学习笔记(6)】—— Fastapi文件上传、请求头自动转换
笔记·学习·fastapi
嘶哈哈哈11 小时前
嘉立创 EDA 入门实操笔记:从原理图到 PCB 布线、差分对、覆铜与 DRC 检查
开发语言·笔记·php