小编Ank*_*rma的帖子

如何使用 Hibernate / Spring boot 在 mysql 中将 JSON 文件存储为 JSON 数据类型?

我尝试了多种将 json 文件存储在数据库中的方法,但最终为每个条目创建了不同的列。

我想将它存储为单个列中的“json”类型。是否可以?

我的json文件。

用户.json

[
  {
    "id": 1,
    "name": "Leanne Graham",
    "username": "Bret",
    "email": "Sincere@april.biz",
    "address": {
      "street": "Kulas Light",
      "suite": "Apt. 556",
      "city": "Gwenborough",
      "zipcode": "92998-3874",
      "geo": {
        "lat": "-37.3159",
        "lng": "81.1496"
      }
    },
    "phone": "1-770-736-8031 x56442",
    "website": "hildegard.org",
    "company": {
      "name": "Romaguera-Crona",
      "catchPhrase": "Multi-layered client-server neural-net",
      "bs": "harness real-time e-markets"
    }
  },
...
]
Run Code Online (Sandbox Code Playgroud)

这是一个 spring-boot 应用程序,我有相关的控制器和服务。

在我的域包中。(地址和公司是可嵌入的类)

用户.java

[
  {
    "id": 1,
    "name": "Leanne Graham",
    "username": "Bret",
    "email": "Sincere@april.biz",
    "address": {
      "street": "Kulas Light",
      "suite": …
Run Code Online (Sandbox Code Playgroud)

java mysql json hibernate spring-boot

5
推荐指数
1
解决办法
8653
查看次数

标签 统计

hibernate ×1

java ×1

json ×1

mysql ×1

spring-boot ×1