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

相关推荐
想学全栈的菜鸟阿董1 小时前
Django5个人笔记
笔记
ZZHow10247 小时前
JavaWeb开发_Day05
java·笔记·web
饕餮争锋9 小时前
设计模式笔记_行为型_观察者模式
笔记·观察者模式·设计模式
I'm a winner10 小时前
新手入门Makefile:FPGA项目实战教程(二)
笔记·fpga开发
汤姆大聪明13 小时前
【软件设计模式】前置知识类图、七大原则(精简笔记版)
笔记·设计模式
lingggggaaaa14 小时前
小迪安全v2023学习笔记(六十一讲)—— 持续更新中
笔记·学习·安全·web安全·网络安全·反序列化
不太可爱的叶某人15 小时前
【学习笔记】Java并发编程的艺术——第6章 Java并发容器和框架
java·笔记·学习
超勇的阿杰16 小时前
gulimall项目笔记:P54三级分类拖拽功能实现
android·笔记
饕餮争锋17 小时前
设计模式笔记_行为型_策略模式
笔记·设计模式·策略模式
₯㎕星空&繁华18 小时前
Linux-地址空间
linux·运维·服务器·经验分享·笔记