所以我有这个想法,这真的超出了我的想象,因为我只编程了很短一段时间,但我想构建一个反应式 Spring webflux 应用程序,将 json 端点暴露给反应前端。
当我决定在 Postgres 中使用 jsonb 格式时,问题就开始了,因为我认为我可能会从数据库一直到前端层一直使用 json。
当我尝试使用反应式 R2dbc 驱动程序使用 jsonb SELECT 表时,出现以下错误:
Caused by: java.lang.IllegalArgumentException: 3802 is not a valid object id
Run Code Online (Sandbox Code Playgroud)
我在 postgres 中有一个表,如下所示:
Column | Type | Collation | Nullable | Default
---------+---------+-----------+----------+------------------------------
id | integer | | not null | generated always as identity
details | jsonb | | |
Indexes:
"snacks_new_pkey" PRIMARY KEY, btree (id)
Run Code Online (Sandbox Code Playgroud)
因此,如果我将其作为文本提取到 Spring webflux,它就可以正常工作,因为它不再是 json。
"SELECT id, details->>'name' as NAME, details->>'price' AS PRICE, details->>'quantity' AS QUANTITY …Run Code Online (Sandbox Code Playgroud)