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

相关推荐
努力奋斗的小杨33 分钟前
学习MySQL的第十一天
数据库·笔记·sql·学习·mysql·navicat
愚润求学1 小时前
【数据结构】哈希表
数据结构·c++·笔记·散列表
christine-rr2 小时前
【25软考网工】第三章(3)虚拟局域网VLAN
网络·笔记·软考
明月清了个风2 小时前
数据结构与算法学习笔记(Acwing提高课)----动态规划·数字三角形
笔记·学习·算法·动态规划
美味的大香蕉2 小时前
从Kafka读取数据
笔记
落笔画忧愁e3 小时前
数据通信学习笔记之OSPF的区域
笔记·学习·智能路由器
Always_away4 小时前
26考研|数学分析:数项级数
笔记·学习
xin007hoyo5 小时前
算法笔记.spfa算法(bellman-ford算法的改进)
数据结构·笔记·算法
小羊不会飞9 小时前
Towards Transferable Targeted 3D Adversarial Attack in the Physical World--阅读笔记
笔记
栀栀栀栀栀栀10 小时前
笔记 2025/4/23
笔记