Configure additions and deletions in the SQL mapping file:
1. Increase:
Add the Insert label to the SQL mapping file and add the corresponding SQL statement. Add the corresponding method to the corresponding interface (based on the previous post example), and the method name matches the value of the id attribute in the INSERT tag in the SQL mapping file.
650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M01/97/8A/wKiom1kvlGXxkXWOAABXlqFNNmo794.png "title=" 45. PNG "alt=" Wkiom1kvlgxxkxwoaabxlqfnnmo794.png "/>
650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M02/97/8A/wKiom1kvlGWjMEQVAAAszw3ISq4494.png "title=" 46. PNG "alt=" Wkiom1kvlgwjmeqvaaaszw3isq4494.png "/>
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M01/97/8B/wKioL1kvlGaBy33aAABbeKEktwQ028.png "title=" 47. PNG "alt=" Wkiol1kvlgaby33aaabbekektwq028.png "/>
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M02/97/8A/wKiom1kvlGaAu0tzAABKwuVyjIg451.png "style=" float : none; "title=" 48.png "alt=" Wkiom1kvlgaau0tzaabkwuvyjig451.png "/>
Note: You can see that the update was successful in test method test03. However, the Opensession object requires a transaction to be committed manually. (The resulting Opensession object for the Sqlsessionfactory.opensession method, using Sqlsessionfactory.opensession (Boolean autocommit) does not require a transaction to be committed.) )
Attached: How to get the value of the self-increment primary key:
MySQL supports the self-increment primary key, the acquisition of the self-increment primary key, and MyBatis is also obtained using Statement.getgenereatedkeys (). Add usegeneratedkeys= "True" to the insert label (using the self-increment primary key to get the primary key value policy) and the keyproperty= "id" (specifying the corresponding primary key attribute, which is mybatis gets the primary key value, encapsulates the value into which attribute in JavaBean) two properties and attribute values.
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M01/97/8B/wKiom1kvqDLDlRIdAABmYL_j7_g822.png "title=" 55. PNG "alt=" Wkiom1kvqdldlridaabmyl_j7_g822.png "/>
650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M00/97/8B/wKiom1kvqGmg6mrVAACxGgCV0l0517.png "title=" 56. PNG "alt=" Wkiom1kvqgmg6mrvaacxggcv0l0517.png "/>
2. By deleting:
Add the delete tag to the SQL mapping file and add the corresponding SQL statement. (Note: The ID tag in the delete tag needs to be consistent with the method name of the corresponding interface.) )
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M01/97/8A/wKiom1kvmAuQdJSOAABke0H3ne4718.png "title=" 49. PNG "alt=" Wkiom1kvmauqdjsoaabke0h3ne4718.png "/>
650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M01/97/8B/wKioL1kvmAyzj1WKAAAxvZhh9jo781.png "title=" 50. PNG "alt=" Wkiol1kvmayzj1wkaaaxvzhh9jo781.png "/>
650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M01/97/8B/wKioL1kvmA3C_cTPAACKWaciGQk435.png "title=" 51. PNG "alt=" Wkiol1kvma3c_ctpaackwacigqk435.png "/>
3. Change:
Add the update label to the SQL mapping file and add the corresponding SQL statement. Add the corresponding method to the corresponding interface, and the method name must be consistent with the value of the id attribute in the update tag.
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M01/97/8A/wKiom1kvmiOh2m2yAAB8P39PtQY557.png "title=" 52. PNG "alt=" Wkiom1kvmioh2m2yaab8p39ptqy557.png "/>
650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M01/97/8C/wKioL1kvmiSwoeIsAAA3g8TdIZk701.png "title=" 53. PNG "alt=" Wkiol1kvmiswoeisaaa3g8tdizk701.png "/>
650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M01/97/8A/wKiom1kvmg7wvOoQAAC1L5XYKA0332.png "title=" 54. PNG "alt=" Wkiom1kvmg7wvooqaac1l5xyka0332.png "/>
Note: The MyBatis operation method allows the following types of return values:
Integer, Boolean, Long, void
This article is from the "12392717" blog, please be sure to keep this source http://12402717.blog.51cto.com/12392717/1931269
MyBatis SQL mapping file additions and deletions to learn