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 天前
学习笔记:SKILLS 能帮助更好的vibe coding
笔记·学习
starlaky5 天前
Django入门笔记
笔记·django
勇气要爆发5 天前
吴恩达《LangChain LLM 应用开发精读笔记》1-Introduction_介绍
笔记·langchain·吴恩达
悠哉悠哉愿意5 天前
【单片机学习笔记】串口、超声波、NE555的同时使用
笔记·单片机·学习
勇气要爆发5 天前
吴恩达《LangChain LLM 应用开发精读笔记》2-Models, Prompts and Parsers 模型、提示和解析器
android·笔记·langchain
qianshanxue115 天前
计算机操作的一些笔记标题
笔记
土拨鼠烧电路5 天前
笔记11:数据中台:不是数据仓库,是业务能力复用的引擎
数据仓库·笔记
土拨鼠烧电路5 天前
笔记14:集成与架构:连接孤岛,构建敏捷响应能力
笔记·架构
烟花落o5 天前
栈和队列的知识点及代码
开发语言·数据结构·笔记·栈和队列·编程学习