简体   繁体   中英

Dynamically create columns / table using SpringBoot when i make Rest api calls

I am trying to generate a schema dynamically using Spring-Boot when I make a REST API call. For instance, I make a rest call to http://localhost:8080/school with two different JSON bodies.

Call 1:

{id: 1111, name: "XYZ"}

Call 2:

/school
{id: 1234, name: "ABCD", contact: "test@test.com"}

The request body is transformed into a schema of the table or collection for each request.

table or collection name school

For Call 1

{id: Number, name: String}

I make another API call but pass different JSON body (For Call 2):

table or collection name school

{ id: Number, name: String, contact: String}

Can anyone tell me how to do this, please? I am using MySQL database on the backend.

You have a connection to the database. It accepts arbitrary statements.

So long as the user you're connecting with has the necessary privileges, nothing prevents you from using the connection to send DDL statements (like CREATE TABLE and similar) to the DB.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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