简体   繁体   English

如何使用 Z2A2D595E6ED9A0B24F027F2B63B13 将 json object 存储在 mysql 的列中

[英]how to store json object in a column of mysql using spring boot/java

Requirement is like that a json object is send from postman and i need to receive it on a restcontroller and save that whole json object as it is to the mysql database Table Column (in one/single column) using spring boot. Requirement is like that a json object is send from postman and i need to receive it on a restcontroller and save that whole json object as it is to the mysql database Table Column (in one/single column) using spring boot.

{
"name" : "abc",
"address : "xyz"
}

assume the above json object is send from postman to a spring boot restcontroller.假设上面的 json object 从 postman 发送到 Z2A2D595E6ED9A0B24F027F2B63B1 restcontroller。 How can i save that json object in a column of a table.如何将 json object 保存在表格的列中。

There's no way.不可能。 You can save it parsing the JSON to String ( Ex: JSON.stringify() ) and when you query the info, parse the string to JSON (Ex: JSON.parse() ) You can save it parsing the JSON to String ( Ex: JSON.stringify() ) and when you query the info, parse the string to JSON (Ex: JSON.parse() )

JSON.stringify: https://developer.mozilla.org/es/docs/Web/JavaScript/Referencia/Objetos_globales/JSON/stringify JSON.stringify: https://developer.mozilla.org/es/docs/Web/JavaScript/Referencia/Objetos_globales/JSON/stringify

JSON.parse: https://developer.mozilla.org/es/docs/Web/JavaScript/Referencia/Objetos_globales/JSON/parse JSON.parse: https://developer.mozilla.org/es/docs/Web/JavaScript/Referencia/Objetos_globales/JSON/parse

MySQL supports JSON column types. MySQL 支持 JSON 列类型。 https://dev.mysql.com/doc/refman/8.0/en/json.html https://dev.mysql.com/doc/refman/8.0/en/json.html

So, assuming you will be using json column type for your requirement, you can follow below articles.因此,假设您将使用 json 列类型来满足您的要求,您可以按照以下文章进行操作。 I was able to do this for postgres as well, works very well for me, the instructions are pretty straightforward.我也可以为 postgres 执行此操作,对我来说效果很好,说明非常简单。

https://vladmihalcea.com/how-to-map-json-objects-using-generic-hibernate-types/ https://vladmihalcea.com/java-map-json-jpa-hibernate/ https://vladmihalcea.com/how-to-map-json-objects-using-generic-hibernate-types/ https://vladmihalcea.com/java-map-json-jpa-hibernate/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM