- The SQL statement in the configuration XML file, the INSERT statement has a return value by default, to mark whether the insertion was successful. If additional return values are required, further setup is required.
Take the following code as an example:
1 <InsertID= "Insertandgetid"Parameterclass= "Vnet_stack" > 2 Insert into3 Vnet_stack (stack_name)4 values (#stack_name #)5 <SelectkeyResultClass= "int"Keyproperty= "stack_id" >6 SELECT last_insert_id ()7 </Selectkey>8 9 </Insert>
Where the return value type ResultClass is set to the integer type, Keyproperty sets the data source.
After that, a simple nested query statement can be used to query to the newly added newest row, and take the entry of Keyproperty set as the return value
2. Adding functions in the DAO layer
1 @Override 2 Public int Insertandgetid (Vnet_stack ss) {3 // TODO auto-generated Method Stub 4 return Integer.parseint (String.valueof (Getsqlmapclienttemplate (). Insert ("Vnet_stack.insertandgetid", ss)); 5 6 }
The function is then called to get the required primary key ID as the return value.
How to get the return value using insert in Ibatis and MySQL environments