SpringBoot集成內(nèi)存數(shù)據(jù)庫Derby的實踐
目標
在SpringBoot中集成內(nèi)存數(shù)據(jù)庫Derby.
為什么
像H2、hsqldb、derby、sqlite這樣的內(nèi)存數(shù)據(jù)庫,小巧可愛,做小型服務(wù)端演示程序,非常好用。最大特點就是不需要你另外安裝一個數(shù)據(jù)庫。
操作步驟
修改pom.xml文件
<dependency> <groupId>org.apache.derby</groupId> <artifactId>derby</artifactId> <scope>runtime</scope> </dependency>
修改項目配置文件application.yml
spring: datasource: username: hsp password: 123456 url: jdbc:derby:blogDb;create=true driver-class-name: org.apache.derby.jdbc.EmbeddedDriver schema: classpath:schema.sql data: classpath:data.sql initialization-mode: always continue-on-error: true
添加初始化數(shù)據(jù)文件
建表腳本: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) );
導入數(shù)據(jù)腳本:data.sql
insert into blog(id,title) values(1,'花生皮編程博客');
啟動類:HspApplication
@MapperScan({"cn.hsp.blog"}) @SpringBootApplication public class HspApplication { public static void main(String[] args) { SpringApplication.run(HspApplication.class, args); } }
Controller類:BlogController
@RestController @RequestMapping("/blog") public class BlogController { @Autowired private BlogMapper blogMapper; @GetMapping(value="/query") public List<Blog> query() { return blogMapper.query(); } }
Mapper類:BlogMapper
@Repository public interface BlogMapper { @Select(value = "select * from blog") List<Blog> query(); }
數(shù)據(jù)bean:Blog
@Data public class Blog { private int id; private String title; }
工程截圖
運行
運行HspApplication即可
效果
到此這篇關(guān)于SpringBoot集成內(nèi)存數(shù)據(jù)庫Derby的實踐的文章就介紹到這了,更多相關(guān)SpringBoot集成Derby 內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
詳解PowerDesigner之CDM、PDM、SQL之間轉(zhuǎn)換
這篇文章主要介紹了詳解PowerDesigner之CDM、PDM、SQL之間轉(zhuǎn)換的相關(guān)資料,希望通過本文能幫助到大家,需要的朋友可以參考下2017-10-10MyBatis創(chuàng)建存儲過程的實例代碼_動力節(jié)點Java學院整理
本節(jié)需要用到的有2部分,第一部分是如何在Derby中創(chuàng)建存儲過程,第二部分是如何在Mybatis中調(diào)用存儲過程,具體實例代碼大家參考下本文吧2017-09-09詳解如何開發(fā)一個MyBatis通用Mapper的輪子
因為一些原因,例如:通用數(shù)據(jù)權(quán)限控制、MyBatis-Plus好像不支持聯(lián)合主鍵等,我們不得不開發(fā)一個MyBatis通用Mapper的輪子。文中的示例代碼講解詳細,需要的可以參考一下2022-12-12java圖的深度優(yōu)先遍歷實現(xiàn)隨機生成迷宮
這篇文章主要為大家詳細介紹了java圖的深度優(yōu)先遍歷實現(xiàn)隨機生成迷宮,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-01-01