I used the SPRINGMVC integration MyBatis to perform the insert operation in the Sqlmapper configuration file and found that the program did not error, but the database table did not have the record just inserted. Looked up a lot of information, and finally found the answer on a blog: After the completion of the method, must have Session.commit (), this sentence to commit the transaction. Because the transaction is turned on when the insert Update Delete is made, and the MyBatis is not automatically committed (and may be set, I don't know), the transaction must be committed manually. So I just call the method that contains the insert operation and add Session.commit () to record the successful storage.
Interface Definition section: Public InterfaceMenumapper { PublicList<menuvo> Getparentmenu (map<string,object>Parammap); PublicList<menuvo> GetSubMenu (map<string,object>Parammap); Public intSavemenu (Menuvo menuvo);} Interface Invocation section: Try{menumapper Menumapper=sqlsession.getmapper (Menumapper.class); System.out.println (NewGson (). ToJson (Menuvo)); intflag=Menumapper.savemenu (MENUVO); Sqlsession.commit (); returnFlag;}Catch(Exception e) {logger.info ("Save menu failed, error:" +e.getmessage ());} finally{sqlsession.close ();} SQL Mapper configuration file:
<!--An SQL statement that performs an increase in operations. The ID and ParameterType are identical to the name and parameter type of the Savemenu method in the Menumapper interface, respectively. Usegeneratedkeys is set to "true" to indicate that MyBatis gets the primary key generated automatically by the database; keyproperty= "MenuId" Specifies to inject the acquired primary key value into Menuvo, MenuId properties-< Insert Id= "Savemenu" parametertype= "Menuvo" usegeneratedkeys= "true" keyproperty= "MenuId" >INSERT INTO menu (Parentmenuid,menuurl,menuname) VALUES (#{parentmenuid},#{menuurl},#{menuname})
</insert>
Using MyBatis to perform label operations such as INSERT, UPDATE, Delete, and so on in the corresponding SQL mapper configuration, the database record is unchanged