SpringBoot集成内存数据库Derby的实践
目录
- 目标
- 为什么
- 操作步骤
- 工程截图
- 运行
- 效果
目标
在SpringBoot中集成内存数据库Derby.
【SpringBoot集成内存数据库Derby的实践】
为什么
像H2、hsqldb、derby、sqlite这样的内存数据库,小巧可爱,做小型服务端演示程序,非常好用。最大特点就是不需要你另外安装一个数据库。
操作步骤 修改pom.xml文件
org.apache.derby derby runtime
修改项目配置文件application.yml
spring:datasource:username: hsppassword: 123456url: jdbc:derby:blogDb; create=truedriver-class-name: org.apache.derby.jdbc.EmbeddedDriverschema: classpath:schema.sqldata: classpath:data.sqlinitialization-mode: alwayscontinue-on-error: true
添加初始化数据文件
建表脚本:schema.sql
CREATE TABLE blog (id INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1),title varchar(255) DEFAULT NULL,PRIMARY KEY (id));
导入数据脚本:data.sql
insert into blog(id,title) values(1,'花生皮编程博客');
启动类:HspApplication
@MapperScan({"cn.hsp.blog"})@SpringBootApplicationpublic class HspApplication { public static void main(String[] args) {SpringApplication.run(HspApplication.class, args); }}
Controller类:BlogController
@RestController@RequestMapping("/blog")public class BlogController {@Autowiredprivate BlogMapper blogMapper; @GetMapping(value="https://www.it610.com/query")public Listquery(){return blogMapper.query(); }}
Mapper类:BlogMapper
@Repositorypublic interface BlogMapper {@Select(value = "https://www.it610.com/article/select * from blog")Listquery(); }
数据bean:Blog
@Datapublic class Blog {private int id; private String title; }
工程截图
文章图片
运行
运行HspApplication即可
效果
文章图片
完整源代码
到此这篇关于SpringBoot集成内存数据库Derby的实践的文章就介绍到这了,更多相关SpringBoot集成Derby 内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
推荐阅读
- JAVA(抽象类与接口的区别&重载与重写&内存泄漏)
- Activiti(一)SpringBoot2集成Activiti6
- SpringBoot调用公共模块的自定义注解失效的解决
- 解决SpringBoot引用别的模块无法注入的问题
- 私有化轻量级持续集成部署方案--03-部署web服务(下)
- Java内存泄漏分析系列之二(jstack生成的Thread|Java内存泄漏分析系列之二:jstack生成的Thread Dump日志结构解析)
- Spring集成|Spring集成 Mina
- springboot使用redis缓存
- iOS内存对齐原则
- springboot整合数据库连接池-->druid