使用 REST 访问 JPA 数据,使用 CURL 永久存储 POST

Accessing JPA Data with REST, POSTing using CURL store permanently

按照教程 here,我已经成功地使用我的 localhost:8080/驱动程序上的数据创建了我的应用程序,与教程非常相似。

我的问题是使用 curl 创建新元素的部分:

curl -i -X POST -H "Content-Type:application/json" -d '{  "firstName" : "Frodo",  "lastName" : "Baggins" }' http://localhost:8080/people

它对我有用,显示 here:

但是,当我重新运行服务器时,数据消失了。我如何 store/POST 将数据永久保存到使用 Spring 创建的数据库中?

或者,我可以将来自客户端的现有和单独的 JSON 数据存储到那里吗?除了Batch Service方式。

我觉得这是一个非常基本的问题,但我在 Spring 文档中找不到答案,我想我没有在寻找合适的词。

非常感谢您。

本指南使用的是 H2 in-memory 数据库。因此,每次您 re-run 您的应用程序时,该应用程序的数据都会消失:

<dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
</dependency>

How do I store/POST data permanently to my database created with Spring?

请查看 spring boot's doc