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

Source: Internet
Author: User

1# #Example Example =New# #Example (); 2Example.setorderbyclause ("Field name ASC");//in ascending order, DESC is in descending order. 3Example.setdistinct (false)//Remove Duplicates, Boolean, True to select records that are not duplicates. 4Criteria =NewExample (). Createcriteria (); 5IsNULL; is notNULL; 6 equal to (value); n equal to (value); 7 GreaterThan (value);    Greaterthanorequalto (value); 8 LessThan (value);    Lessthanorequalto (value); 9 In (Item,item,item,...);    Not in (Item,item,item,...); TenLike ("%" +value+ "%") and not-like ("%" +value+ "%");  One between (value1,value2); not between (Value1,value2) A      -       -      the example functions for mapper in MyBatis: - 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: Queries by primary key.  +List<?>Selectbyexample (userexample example) THORWS SQLException: query by Condition AList<?>Selectbyexamplewithblogs (userexample example) Thorws SQLException: Press at      - conditional queries (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 key - intupdatebyprimarykeyselective (User record) Thorws SQLException: Update by primary key -      - a field with a value other than null in intupdatebyexample (User record, userexample example) Thorws SQLException: -      to Update by Condition + intupdatebyexampleselective (User record, userexample example) Thorws -      the SQLException: Updating a field with a value that is not NULL by condition *      $ The example functions of Mapper in MyBatis are detailed:Panax Notoginseng ①selectbyprimarykey () -      theUser user = # #Mapper. Selectbyprimarykey (100); Equivalent to select *From user where +      AID = 100 the      + ②selectbyexample () and Selectbyexamplewithblogs () -      $userexample example =Newuserexample ();  $Criteria =Example.createcriteria ();  -Criteria.andusernameequalto ("Joe");  - Criteria.andusernameisnull ();  theExample.setorderbyclause ("Username asc,email desc");  -List<?>list =# #Mapper. Selectbyexample (example); WuyiEquivalent to: SELECT * from user where username = ' Joe ' and username areNULLOrder the      - by username Asc,email desc Wu      - Note: The ibator generated file Userexample.java contains a static internal class Criteria, About      $ There are a number of methods in the criteria, primarily defining the query criteria after the SQL statement where.  -      - ③insert () -      AUser User =NewUser ();  +User.setid (101);  theUser.setusername ("Test");  -User.setpassword ("123")     $User.setemail ("[Email protected]");  the # #Mapper. Insert (user);  the equivalent to: INSERT INTO user (Id,username,password,email) values the      the(101, ' Test ', ' 123 ', ' [email protected] ');  -      in ④updatebyprimarykey () and updatebyprimarykeyselective () the      theUser User =NewUser ();  AboutUser.setid (101);  theUser.setusername ("Joe");  theUser.setpassword ("Joe");  theUser.setemail ("[Email protected]");  + # #Mapper. Updatebyprimarykey (user);  -Equivalent: Update user set username= ' Joe ', password= ' Joe ', email= ' [email protected] ' the     Bayiwhere id=101 the      theUser User =NewUser ();  -User.setid (101);  -User.setpassword ("Joe");  the # #Mapper. updatebyprimarykeyselective (user);  theEquivalent: Update user set password= ' Joe ' where id=101 the      the ⑤updatebyexample () and updatebyexampleselective () -      theuserexample example =Newuserexample ();  theCriteria =Example.createcriteria ();  theCriteria.andusernameequalto ("Joe"); 94User User =NewUser ();  theUser.setpassword ("123");  the # #Mapper. updatebyprimarykeyselective (User,example);  theEquivalent: Update user set password= ' 123 ' where username= ' Joe '98      About ⑥deletebyprimarykey () -     101# #Mapper. Deletebyprimarykey (101); Equivalent to: Delete from user where id=101102     103 ⑦deletebyexample ()104      theuserexample example =Newuserexample (); 106Criteria =Example.createcriteria (); 107Criteria.andusernameequalto ("Joe"); 108 # #Mapper. Deletebyexample (example); 109Equivalent to: Delete from user where username= ' Joe ' the     111 ⑧countbyexample () the     113userexample example =Newuserexample ();  theCriteria =Example.createcriteria ();  theCriteria.andusernameequalto ("Joe");  the intCount =# #Mapper. Countbyexample (example); 117Equivalent 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.