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

Source: Internet
Author: User

    1. # #Example Example = new # #Example ();
    2. Example.setorderbyclause ("field name ASC");    //in ascending order, desc in descending order.
    3. Example.setdistinct (false)//Remove Duplicates, Boolean, True to select records that are not duplicates.
    4. Criteria = new Example (). Createcriteria ();
    5. is null;is not null;
    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,...);
    10. Like ("%" +value+"%") and not-like ("%" +value+"%");
    11. Between (value1,value2); not between (Value1,value2)
    12. Example functions for mapper in MyBatis:
    13. int Countbyexample (userexample example) Thorws SQLException: counts by condition.
    14. int Deletebyprimarykey (Integer id) thorws SQLException: Delete by primary key.
    15. int Deletebyexample (userexample example) Thorws SQLException: Delete by condition.
    16. String/integer Insert (User record) Thorws SQLException: Insert (return value is ID value)
    17. User Selectbyprimarykey (Integer ID) thorws SQLException: Queries by primary key.
    18. List<?>selectbyexample (userexample example) THORWS SQLException: Query by condition
    19. List<?>selectbyexamplewithblogs (userexample example) Thorws SQLException: Press
    20. Conditional queries (including BLOB fields). Only if the field type in the data table is binary is it generated.
    21. int Updatebyprimarykey (User record) Thorws SQLException: Update by primary key
    22. int updatebyprimarykeyselective (User record) Thorws SQLException: Update by primary key
    23. a field with a value other than null
    24. int Updatebyexample (User record, userexample example) Thorws SQLException:
    25. Update by condition
    26. int updatebyexampleselective (User record, userexample example) THORWS
    27. SQLException: Updating a field with a value that is not NULL by condition
    28. The example functions of Mapper in MyBatis are detailed:
    29. ①selectbyprimarykey ()
    30. User user = # #Mapper. Selectbyprimarykey (100); equivalent to select * from user where
    31. id =
    32. ②selectbyexample () and Selectbyexamplewithblogs ()
    33. userexample example = new Userexample ();
    34. Criteria = Example.createcriteria ();
    35. Criteria.andusernameequalto ("Joe");
    36. Criteria.andusernameisnull ();
    37. Example.setorderbyclause ("username asc,email desc");
    38. list<?>list = # #Mapper. Selectbyexample (example);
    39. Equivalent to: SELECT * from user where username = ' Joe ' and username are null order
    40. by username Asc,email desc
    41. Note: The ibator generated file Userexample.java contains a static internal class Criteria,
    42. There are a number of methods in the criteria, primarily defining the query criteria after the SQL statement where.
    43. ③insert ()
    44. User user = new user ();
    45. User.setid (101);
    46. User.setusername ("test");
    47. User.setpassword ("123")
    48. User.setemail ("[email protected]");
    49. # #Mapper. Insert (user);
    50. Equivalent to: INSERT INTO user (Id,username,password,email) values
    51. (101,' test ',' 123 ',' [email protected] ');
    52. ④updatebyprimarykey () and updatebyprimarykeyselective ()
    53. User user =new user ();
    54. User.setid (101);
    55. User.setusername ("Joe");
    56. User.setpassword ("Joe");
    57. User.setemail ("[email protected]");
    58. # #Mapper. Updatebyprimarykey (user);
    59. Equivalent: Update user set username=' Joe ', password=' Joe ', email=' [email protected] '
    60. where id=101
    61. User user = new user ();
    62. User.setid (101);
    63. User.setpassword ("Joe");
    64. # #Mapper. updatebyprimarykeyselective (user);
    65. Equivalent: Update user set password=' Joe ' where id=101
    66. ⑤updatebyexample () and updatebyexampleselective ()
    67. userexample example = new Userexample ();
    68. Criteria = Example.createcriteria ();
    69. Criteria.andusernameequalto ("Joe");
    70. User user = new user ();
    71. User.setpassword ("123");
    72. # #Mapper. updatebyprimarykeyselective (User,example);
    73. Equivalent: Update user set password=' 123 ' where username=' Joe '
    74. ⑥deletebyprimarykey ()
    75. # #Mapper. Deletebyprimarykey (101); Equivalent to: Delete from user where id=101
    76. ⑦deletebyexample ()
    77. userexample example = new Userexample ();
    78. Criteria = Example.createcriteria ();
    79. Criteria.andusernameequalto ("Joe");
    80. # #Mapper. Deletebyexample (example);
    81. Equivalent to: Delete from user where username=' Joe '
    82. ⑧countbyexample ()
    83. userexample example = new Userexample ();
    84. Criteria = Example.createcriteria ();
    85. Criteria.andusernameequalto ("Joe");
    86. int count = # #Mapper. Countbyexample (example);
    87. Equivalent to: SELECT COUNT (*) from user where username=' Joe '

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

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.