1. Single Basic type parameters (String,int, etc.)
A single primitive type parameter that parametertype the value of the corresponding statement to the same type as the parameter. Then use "#{parameter name}" to get
Java code
Parameter username of type string
public User finduser (String usernumber) { return (User) Sqlsessiontemplate.selectone ("Finduserbyusernumber", Usernumber); }
XML code
Corresponds to Paramtertype= "string"
<id= "Finduserbyusernumber" parametertype= "string" Resulttype= "user"> select * from User where usernumber = #{usernumber} </ Select >
2.Java Entity type parameters
Java entity type parameter: Sets the value of the ParameterType to the corresponding Java entity class, and then uses the property name of the #{class} to get
Java code
User entity class
publicvoid updateUser (user user) { sqlsessiontemplate.update ("UpdateUser", user); }
XML code
Point the ParameterType type to the specific address of the corresponding class (package name + class name), or to the alias (in the Mybatis.xml) file in Typealias
<id= "UpdateUser" parametertype= "User"> update user set Username=#{username},loginname=#{loginname},loginpassword=#{loginpassword},sex=#{sex}, Birthday=#{birthday} where Usernumber=#{usernumber} </update>
3. Multiple basic type parameters
In a specific business relationship, it is often necessary to pass multiple parameters, such as: Login-----> Username + password
public User Finduser (String loginname, String Loginpassword { // TODO Auto-gene Rated method stub map<string,string> map=new hashmap<string, S Tring> (); Map.put ( "LoginName" , LoginName); Map.put ( "Loginpassword" , Loginpassword); return (User) sqlsessiontemplate.selectone ("Loginuser"
<id= "Loginuser" parametertype= "Map" resulttype = "User"> select * from User where loginname=#{loginname} and Loginpassword=#{loginpassword } </Select>
One way to take advantage of Map knowledge multi-parameter transfer, there are other ways to achieve
MyBatis SQL statement mapping File (iii)----parameter passing