Development steps:
1) configuration in the mapping file Usermapper,xml
2) Add method in interface Usermapper
3) Testing
Input mappings:
Requirement one.: Input wrapper type USERQUERYVO defines the customer class customer inherits the user class
Userqueryvo
<span style= "Font-family:courier new;font-size:14px;" >public class Userqueryvo {private customer customer;public void Setcustomer (Customer customer) {This.customer = Custo Mer;} Public Customer GetCustomer () {return customer;}} </span>
The customer class inherits the user class
<span style= "Font-family:courier new;font-size:14px;" >public class Customer extends user{}</span>
Configuration in the Usermapper.xml
<span style= "Font-family:courier new;font-size:14px;" ><!--Packaging type--><select id= "findalluserslist" parametertype= "Cn.itcast.domain.UserQueryVo" resulttype= " Cn.itcast.domain.Customer ">select * from user where User.sex=#{customer.sex} and user.username like"%${ customer.username}% "</select></span>
the type of input here is the type of the customer that the wrapper type outputs
Defining methods in the Usermapper interface
<span style= "Font-family:courier new;font-size:14px;" >public list<customer> findalluserslist (userqueryvo userqueryvo);</span>
Output Mappings:
Requirements: Isolate the total number of records in the database user table
Configuration in the Usermapper.xml
<span style= "Font-family:courier new;font-size:14px;" ><select id= "Findusercount" resulttype= "int" >select count (*) from user</select></span>
input type no output type is int
Defining methods in the Usermapper interface
<span style= "Font-family:courier new;font-size:14px;" >public int Findusercount ();</span>
Requirement: If an alias is used in a query statement!
<!--output type--><resultmap type= "user" id= "userId" ><id column= "id_" property= "id"/><result column= " Username_ "property=" username "/></resultmap><select id=" Finduserresulttype "parametertype=" int " resultmap= "userId" >select ID id_,username username_ from user where ID =#{id}</select>
The input type is an int output type is a referenced alias type this time using Resultmap
Defining methods in the Usermapper interface
Public User finduserresulttype (int id);
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
MyBatis input mapping and output mapping