欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

SpringBoot集成內(nèi)存數(shù)據(jù)庫(kù)Derby的實(shí)踐

 更新時(shí)間:2021年09月10日 10:04:19   作者:花生皮編程  
像H2、hsqldb、derby、sqlite這樣的內(nèi)存數(shù)據(jù)庫(kù),小巧可愛(ài),做小型服務(wù)端演示程序,非常好用。最大特點(diǎn)就是不需要你另外安裝一個(gè)數(shù)據(jù)庫(kù)。本文主要介紹了SpringBoot集成內(nèi)存數(shù)據(jù)庫(kù)Derby,感興趣的可以了解一下

目標(biāo)

在SpringBoot中集成內(nèi)存數(shù)據(jù)庫(kù)Derby.

為什么

像H2、hsqldb、derby、sqlite這樣的內(nèi)存數(shù)據(jù)庫(kù),小巧可愛(ài),做小型服務(wù)端演示程序,非常好用。最大特點(diǎn)就是不需要你另外安裝一個(gè)數(shù)據(jù)庫(kù)。

操作步驟

修改pom.xml文件

<dependency>
 <groupId>org.apache.derby</groupId>
 <artifactId>derby</artifactId>
 <scope>runtime</scope>
</dependency>

修改項(xiàng)目配置文件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)
);

導(dǎo)入數(shù)據(jù)腳本:data.sql

insert into blog(id,title) values(1,'花生皮編程博客');

啟動(dòng)類(lèi):HspApplication

@MapperScan({"cn.hsp.blog"})
@SpringBootApplication
public class HspApplication {

 public static void main(String[] args) {
  SpringApplication.run(HspApplication.class, args);
 }

}

Controller類(lèi):BlogController

@RestController
@RequestMapping("/blog")
public class BlogController {

    @Autowired
    private BlogMapper blogMapper;

    @GetMapping(value="/query")
    public List<Blog> query()
    {
        return blogMapper.query();
    }
}

Mapper類(lèi):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;
}

工程截圖

運(yùn)行

運(yùn)行HspApplication即可

效果

完整源代碼

到此這篇關(guān)于SpringBoot集成內(nèi)存數(shù)據(jù)庫(kù)Derby的實(shí)踐的文章就介紹到這了,更多相關(guān)SpringBoot集成Derby 內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家! 

相關(guān)文章

最新評(píng)論