The difference between insert and insertseletive,updatebyprimarykey,updatebyprimarykeyselective method in MyBatis automatic generation of Mapper

Source: Internet
Author: User
Tags uuid

For insert:

Insert a piece of data
Supports Oracle sequence, UUID, mysql-like indentity automatic growth (automatic writeback)
Use a sequence, UUID, and automatically grow when the parameter value is empty, using the incoming parameter value first
But be aware that if the database field has Default,default, it won't work.

For insertselective:

Inserts a piece of data, inserts a field that is not NULL, and does not affect fields with default values
Supports Oracle sequence, UUID, mysql-like indentity automatic growth (automatic writeback)
Use a sequence, UUID, and automatically grow when the parameter value is empty, using the incoming parameter value first
Insertselective does not ignore default, which is an empty field default AutoFill

For Updatebyprimarykey:

Update all the fields you injected (do not judge whether it is null)

For updatebyprimarykeyselective:

The field is judged and updated (the update is ignored if null)

By distinguishing these, it is easy to select a service layer invocation based on the business.
For more information, you can view the Objectnamemapper.xml source code generated by generator.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.