Mapper interface files in MyBatis and instance functions of the example class and detailed

Source: Internet
Author: User

# #Example Example =New# #Example (); Example.setorderbyclause ("Field name ASC");//in ascending order, DESC is in descending order. Example.setdistinct (false)//Remove Duplicates, Boolean, True to select records that are not duplicates. Criteria =NewExample (). Createcriteria (); isNULL; is notNULL;    Equal to (value); n equal to (value); GreaterThan (value);    Greaterthanorequalto (value); LessThan (value);    Lessthanorequalto (value); In (Item,item,item,...);    Not in (Item,item,item,...); Like ("%" +value+ "%"); not-like ("%" +value+ "%"); Between (value1,value2); mybatis instance function in not between (value1,value2) Mapper:intCountbyexample (userexample example) Thorws SQLException: Count by condition. intDeletebyprimarykey (Integer ID) thorws SQLException: Delete by primary key. intDeletebyexample (userexample example) Thorws SQLException: Delete by condition. String/integer insert (user record) Thorws SQLException: Insert (return value is ID value) User selectbyprimarykey (integer ID) thorws SQLException    : Press primary key to query. List<?>Selectbyexample (userexample example) THORWS SQLException: Query List by Criteria<?>Selectbyexamplewithblogs (userexample example) THORWS SQLException: Query by criteria (including BLOB fields).    Only if the field type in the data table is binary is it generated. intUpdatebyprimarykey (User record) Thorws SQLException: Update by primary keyintupdatebyprimarykeyselective (User record) Thorws SQLException: Update A field with a value that is not NULL by the primary keyintupdatebyexample (User record, userexample example) THORWS SQLException: Update by conditionintupdatebyexampleselective (User record, userexample example) THORWS SQLException: Update A field with a value that is not NULL by condition Mybati Example function of mapper in S: ①selectbyprimarykey () User User= # #Mapper. Selectbyprimarykey (100); Equivalent to select *From user where ID= 100②selectbyexample () and Selectbyexamplewithblogs () userexample Example=Newuserexample (); Criteria Criteria=Example.createcriteria (); Criteria.andusernameequalto ("Joe");    Criteria.andusernameisnull (); Example.setorderbyclause ("Username Asc,email desc"); List<?>list =# #Mapper. Selectbyexample (example); Equivalent to: Select* FROM user where username = ' Joe ' and username areNULLORDER BY username Asc,email desc Note: The ibator generated file Userexample.java contains a static internal class Criteria, in Crit        There are many methods in Eria, mainly defining the query condition after the SQL statement where. ③insert () User User=NewUser (); User.setid (101); User.setusername ("Test"); User.setpassword ("123") User.setemail ("[Email protected]");    # #Mapper. Insert (user); Equivalent to: INSERT INTO user (Id,username,password,email) VALUES (101, ' Test ', ' 123 ', ' [email protected] '); ④updatebyprimarykey () and updatebyprimarykeyselective () user User=NewUser (); User.setid (101); User.setusername ("Joe"); User.setpassword ("Joe"); User.setemail ("[Email protected]");    # #Mapper. Updatebyprimarykey (user); Equivalent to: Update user set username= ' Joe ', password= ' Joe ', email= ' [email protected] 'where ID=101User User=NewUser (); User.setid (101); User.setpassword ("Joe");    # #Mapper. updatebyprimarykeyselective (user); Equivalent to: Update user set Password= ' Joe ' where id=101⑤updatebyexample () and updatebyexampleselective () userexample Example=Newuserexample (); Criteria Criteria=Example.createcriteria (); Criteria.andusernameequalto ("Joe"); User User=NewUser (); User.setpassword ("123");    # #Mapper. updatebyprimarykeyselective (User,example); Equivalent to: Update user set Password= ' 123 ' where username= ' Joe '⑥deletebyprimarykey () # #Mapper. Deletebyprimarykey (101); Equivalent to: Delete from user where id=101⑦deletebyexample () userexample Example=Newuserexample (); Criteria Criteria=Example.createcriteria (); Criteria.andusernameequalto ("Joe");    # #Mapper. Deletebyexample (example); Equivalent to: Delete from user where username= ' Joe '⑧countbyexample () userexample Example=Newuserexample (); Criteria Criteria=Example.createcriteria (); Criteria.andusernameequalto ("Joe"); intCount =# #Mapper. Countbyexample (example); Equivalent to: SELECT COUNT (*) from user where username= ' Joe '

Mapper interface files in MyBatis and instance functions of the example class and detailed

Related Article

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.