Method parsing in Mapper interface
Functions and methods in the Mapper interface
Method |
function Description |
int Countbyexample (userexample example) Thorws SQLException |
Count by criteria |
int Deletebyprimarykey (Integer id) thorws SQLException |
Delete by primary key |
int Deletebyexample (userexample example) Thorws SQLException |
Query by criteria |
String/integer Insert (User record) Thorws SQLException |
Insert data (return value is ID) |
User Selectbyprimarykey (Integer ID) thorws SQLException |
Query by PRIMARY key |
Listselectbyexample (userexample example) Thorws SQLException |
Query by criteria |
Listselectbyexamplewithblogs (userexample example) Thorws SQLException |
Query by criteria (including BLOB fields). Only if the field type in the data table is binary is it generated. |
int Updatebyprimarykey (User record) Thorws SQLException |
Press the primary key to update |
int updatebyprimarykeyselective (User record) Thorws SQLException |
Update a field with a value that is not NULL by the primary key |
int Updatebyexample (User record, userexample example) Thorws SQLException |
Update by condition |
int updatebyexampleselective (User record, userexample example) Thorws SQLException |
Update a field with a value that is not NULL by condition |
Second, example case analysis
MyBatis in reverse engineering will generate instances and instances corresponding to the example,example used to add conditions, quite where the later part
xxxexample example = new Xxxexample ();
criteria = new Example (). Createcriteria ();
Method |
Description |
Example.setorderbyclause ("Field name ASC"); |
Add ascending sort condition, desc is descending |
Example.setdistinct (False) |
Remove Duplicates, Boolean, True to select records that are not duplicates. |
Criteria.andxxxisnull |
Add a field XXX null condition |
Criteria.andxxxisnotnull |
Add field XXX non-null condition |
Criteria.andxxxequalto (value) |
Add xxx field equals value condition |
Criteria.andxxxnotequalto (value) |
Adding the XXX field is not equal to the value condition |
Criteria.andxxxgreaterthan (value) |
Add the XXX field is greater than the value condition |
Criteria.andxxxgreaterthanorequalto (value) |
Add the XXX field is greater than or equal to the value condition |
Criteria.andxxxlessthan (value) |
Adding the xxx field is less than the value condition |
Criteria.andxxxlessthanorequalto (value) |
Add the xxx field is less than or equal to the value condition |
Criteria.andxxxin (list<? >) |
Add xxx field value in List<? > Conditions |
Criteria.andxxxnotin (list<? >) |
Add XXX field value not list<? > Conditions |
Criteria.andxxxlike ("%" +value+ "%") |
Add a fuzzy query condition with a value of XXX field |
Criteria.andxxxnotlike ("%" +value+ "%") |
Add a fuzzy query condition with the XXX field value not being value |
Criteria.andxxxbetween (value1,value2) |
Add the XXX field values between value1 and value2 conditions |
Criteria.andxxxnotbetween (value1,value2) |
Adding the XXX field value is not a condition between value1 and value2 |
Example:
Trafficsituation is a class
New Example (trafficsituation. Class); Example.createcriteria (). Andequalto ("name", name). Andlessthan ("Addtime", date); List<TrafficSituation> trafficsituationlist = trafficsituationmapper.selectbyexample (example);
MyBatis Mapper Interface and example instance functions and explanations