SQL should reduce business logic as much as possible. The verification of some business logic can be done in the business layer. SQL can be as simple as Insert
For multiple tables, I have the same idea as the person above. After an insert statement is executed, return its primary key and insert it into another table containing a foreign key. For example
Then get the returned primary key in your business logic and insert it into another table. This avoids complex SQL
Slowly write multiple insert statements in the business layer, and it is not troublesome to enable the return of primary keys and correlation. Anyway, they are all generated mappers now.
You don’t have to worry about data integrity, there’s nothing to be afraid of if you control your affairs well.
I have solved the problem. There is no need for the <selectKey> tag in mysql. Just add the two attributes useGeneratedKeys="true" keyProperty="id". After inserting data, the primary key value will be automatically returned to the object. . Then just store the primary key value in the association table, thus establishing an association.
SQL should reduce business logic as much as possible. The verification of some business logic can be done in the business layer. SQL can be as simple as Insert
For multiple tables, I have the same idea as the person above. After an insert statement is executed, return its primary key and insert it into another table containing a foreign key. For example
Then get the returned primary key in your business logic and insert it into another table. This avoids complex SQL
Slowly write multiple insert statements in the business layer, and it is not troublesome to enable the return of primary keys and correlation. Anyway, they are all generated mappers now.
You don’t have to worry about data integrity, there’s nothing to be afraid of if you control your affairs well.
I have solved the problem. There is no need for the <selectKey> tag in mysql. Just add the two attributes useGeneratedKeys="true" keyProperty="id". After inserting data, the primary key value will be automatically returned to the object. . Then just store the primary key value in the association table, thus establishing an association.