- # #Example Example = new # #Example ();
- Example.setorderbyclause ("field name ASC"); //in ascending order, desc in descending order.
- Example.setdistinct (false)//Remove Duplicates, Boolean, True to select records that are not duplicates.
- Criteria = new Example (). Createcriteria ();
- is null;is not null;
- 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+"%") and not-like ("%" +value+"%");
- Between (value1,value2); not between (Value1,value2)
- Example functions for mapper in MyBatis:
- int Countbyexample (userexample example) Thorws SQLException: counts by condition.
- int Deletebyprimarykey (Integer id) thorws SQLException: Delete by primary key.
- int Deletebyexample (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
- List<?>selectbyexamplewithblogs (userexample example) Thorws SQLException: Press
- Conditional queries (including BLOB fields). Only if the field type in the data table is binary is it generated.
- int Updatebyprimarykey (User record) Thorws SQLException: Update by primary key
- int updatebyprimarykeyselective (User record) Thorws SQLException: Update by primary key
- a field with a value other than null
- int Updatebyexample (User record, userexample example) Thorws SQLException:
- Update by condition
- int updatebyexampleselective (User record, userexample example) THORWS
- SQLException: Updating a field with a value that is not NULL by condition
- The example functions of Mapper in MyBatis are detailed:
- ①selectbyprimarykey ()
- User user = # #Mapper. Selectbyprimarykey (100); equivalent to select * from user where
- id =
- ②selectbyexample () and Selectbyexamplewithblogs ()
- userexample example = new Userexample ();
- 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 are null order
- by username Asc,email desc
- Note: The ibator generated file Userexample.java contains a static internal class Criteria,
- There are a number of methods in the criteria, primarily defining the query criteria after the SQL statement where.
- ③insert ()
- User user = new user ();
- 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 =new user ();
- User.setid (101);
- User.setusername ("Joe");
- User.setpassword ("Joe");
- User.setemail ("[email protected]");
- # #Mapper. Updatebyprimarykey (user);
- Equivalent: Update user set username=' Joe ', password=' Joe ', email=' [email protected] '
- where id=101
- User user = new user ();
- User.setid (101);
- User.setpassword ("Joe");
- # #Mapper. updatebyprimarykeyselective (user);
- Equivalent: Update user set password=' Joe ' where id=101
- ⑤updatebyexample () and updatebyexampleselective ()
- userexample example = new Userexample ();
- Criteria = Example.createcriteria ();
- Criteria.andusernameequalto ("Joe");
- User user = new user ();
- User.setpassword ("123");
- # #Mapper. updatebyprimarykeyselective (User,example);
- Equivalent: Update user set password=' 123 ' where username=' Joe '
- ⑥deletebyprimarykey ()
- # #Mapper. Deletebyprimarykey (101); Equivalent to: Delete from user where id=101
- ⑦deletebyexample ()
- userexample example = new Userexample ();
- Criteria = Example.createcriteria ();
- Criteria.andusernameequalto ("Joe");
- # #Mapper. Deletebyexample (example);
- Equivalent to: Delete from user where username=' Joe '
- ⑧countbyexample ()
- userexample example = new Userexample ();
- Criteria = Example.createcriteria ();
- Criteria.andusernameequalto ("Joe");
- int count = # #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