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 的数据库和表

相关推荐
水云桐程序员5 小时前
从零开发软件的步骤,软件开发从零到完成应该怎么做?
笔记·学习·软件构建·个人开发
David猪大卫5 小时前
【Linux修炼】环境变量、进程地址空间
linux·c语言·经验分享·笔记·学习·ubuntu·centos
叼烟扛炮6 小时前
Linux 学习笔记(五十六):IO 多路复用初探——select 的“三宗罪”
linux·服务器·数据库·笔记·学习·php
叼烟扛炮12 小时前
Linux 学习笔记(五十八):IO 多路复用封神——epoll 底层原理揭秘
linux·运维·服务器·网络·笔记·学习·php
陈布衣14 小时前
MySQL(1)_MySQL 5.7.21 Linux 安装笔记
linux·笔记·mysql
缘来是你远去是我17 小时前
本地个人笔记exe
笔记
FakeOccupational18 小时前
【电路笔记 STM32】RTC配置:晶振选择+闹钟Configuration+中断设置
笔记·stm32·实时音视频
迪康coolmu18 小时前
企业U盘管控落地实战:基于迪康端点安全一体化管理系统的移动存储安全实践
运维·人工智能·经验分享·笔记·安全·电脑
Z21-X20 小时前
云原生运维学习笔记:容器技术的演进、底层原理与 Docker 全生命周期管理
运维·笔记·学习·云原生
Rabitebla1 天前
【Linux 底层原理】进程(十):进程等待详解---从僵尸进程到 wait、waitpid 与 status
linux·c++·笔记·学习·visual studio