MyBatis Mapper Interface and example instance functions and explanations

Source: Internet
Author: User

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

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.