Primary Key Echo

Role: In multi-table associated with inserting data, the primary key is generally the main table are automatically generated, so before inserting data not know the primary key of this data, but from a table needs before inserting data on binding primary key of the main table, it is possible to use a primary key echo technique:
method 1: xml configuration
(1) to increase the size of our options, we must know the specifications of the new ID, so we modify pinyougou-dao of TbSpecificationMapper.xml, after the insert node, add the following configuration


SELECT LAST_INSERT_ID() AS id

insert into tb_specification (id, spec_name)
values (#{id,jdbcType=BIGINT}, #{specName,jdbcType=VARCHAR})

After this configuration, data warehousing .pojo before the id have a value, rather than null

Guess you like

Origin www.cnblogs.com/zhz-8919/p/11229201.html