How does the JavaWeb SSM framework project add multiple tables at the same time and obtain the primary key id

Our preparatory work is to have three tables. The function is to add the data of these three tables at the same time.
sys_sick ​​primary key id
sys_hospital primary key id foreign key sick_id
sys_addition primary key id foreign key sick_id

Step 1: Correspondingly, we need to write the model in po.
insert image description here
Step 2: Write three interfaces in the dao layer (same as adding a single table).
insert image description here
Step 3: Write three sql in mappers (here sys_sick ​​is different to use Get the attributes of the primary key key)
insert image description hereinsert image description here
This is the key step for adding multiple tables, because when the other two tables are added at the same time, sick_id is required,
so when the first table is added, the primary key id must be returned and given to the other two surface.

Step 4: Write the newly-added interface of merging three tables in the service
insert image description here
Step 5: Perform actual business logic operations in service.impl
insert image description here
insert image description here
Step 6: Make a docking request with the page in the controller
insert image description here
insert image description here
Step 7: In jsp Make a request to
insert image description here
add The last addition is successful! In fact, adding a single table is just multiple calls.
The association is that the other two tables need the id of the first table, so you need to return to get the key value.

If you need to modify multiple tables or obtain multiple table ids for backfilling, the next chapter in my blog is already written!

Guess you like

Origin blog.csdn.net/weixin_47336389/article/details/122222606