When doing an e-commerce project, when adding goods, add the product involves the picture table and the Minimum Sales Unit table, the two tables have the Product ID, add the picture and the smallest sales unit, to first return the product ID. The practice is as follows
<insert id= "addproduct" parametertype= "Product" usegeneratedkeys= "true" keyproperty= "id" >
INSERT statement
</insert>
Where ID represents the method of addition in DAO,
ParameterType represents the type of argument in DAO,
Usegeneratedkeys represents the JDBC Getgeneratedkeys method that gets the primary key and assigns a value to the model set in Keyproperty. The default is False, which is set to true to execute. Support for self-growing IDs in SQL Server and MySQL, which can be used, is not supported for self-growth in Oracle, so it cannot be used.
The keyproperty represents the primary key to return.
DAO in methods:
Public Integer addproduct (product product);
Properties of product in JavaBean
1 Public classProductImplementsserializable{2
3 PrivateInteger ID;4
5 PublicInteger getId () {6 returnID;7 }
8 Public voidsetId (Integer id) {9 This. ID =ID;Ten }
One}
Mybaits INSERT into MySQL database automatically return ID primary key