java - mybatis多表关联新增数据
ringa_lee
ringa_lee 2017-04-18 10:43:43
0
4
591
ringa_lee
ringa_lee

ringa_lee

reply all(4)
黄舟

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!