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.dbdriver-class-name: org.sqlite.JDBCmybatis-plus:configuration:log-impl: org.apache.ibatis.logging.stdout.StdOutImplcache-enabled: truemap-underscore-to-camel-case: falseglobal-config:db-config:logic-delete-field: isDeletedlogic-not-delete-value: 0logic-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 {@Resourceprivate UserMapper userMapper;@GetMapping("getById")public User getById(@RequestParam("id") String id) {return userMapper.selectById(id);}}
5. IDEA操作
在idea里可以创建SQLite 的数据库和表