Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
286 views
in Technique[技术] by (71.8m points)

java - How to get nested JSON by using Spring boot JPA from single Table based on category

I have a below table having entries in 1NF form. product_category column is haven redundant entries.

Columns: product_name varchar(1000) product_category varchar(100) description varchar(2000) product_id int AI PK product_image_url varchar(1000) product_price int

Entries Example:

salaryCard, Mastercard, Salary Card Description, 553535hhfsf7s4w, null, 134353

businessCard, Mastercard, Business Card Description, 553534654fgf4w, null, 134353

salaryCard, VISA, Salary Card Description, 55f453rwrfsf7s4w, null, 134353

businessCard, VISA, Business Card Description, 553fdasa2434fgf4w, null, 134353

I want below nested JSON for above queries.

{"Mastercard":[{"productName":"salaryCard","description":"Salary Card Description","productId":"553535hhfsf7s4w","productUrl":null,"productPrice":134353},{"productName":"businessCard","description":"businessCard Card Description","productId":"553534654fgf4w","productUrl":null,"productPrice":134353}],"VISA":[{"productName":"salaryCard","description":"Salary Card Description","productId":"553535hhfsf7s4w","productUrl":null,"productPrice":134353},{"productName":"businessCard","description":"businessCard Card Description","productId":"553534654fgf4w","productUrl":null,"productPrice":134353}]}

How can I create an Entity and how can I write a JPA query to fetch the records in above format.

question from:https://stackoverflow.com/questions/65884601/how-to-get-nested-json-by-using-spring-boot-jpa-from-single-table-based-on-categ

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...