The parameters of Mybatis in-depth

parameterType configuration parameter 

Used to specify the type of the incoming parameter. If an object of a class is passed in, the type is written as the fully qualified name of the class.

The value of this attribute can be a basic type , a reference type (for example: String type), or an entity class type (POJO class). At the same time, you can also use the packaging class of the entity class.

 Mybaits has registered aliases for commonly used data types when loading, so we don't need to write the package name when using it, but our entity class does not register aliases, so we must write the fully qualified class name.

The official documents of mybatis can also be viewed:

Alias Type of mapping
_byte byte
_long long
_short short
_int int
_integer int
_double double
_float float
_boolean boolean
string String
byte Byte
long Long
short Short
int Integer
inegit Integer
double Double
float Float
boolean Boolean
date Date
decimal BigDecimal
bigdecimal BigDecimal

Wrap the object as a parameter 

Requirement: Query user information based on the user name, and put the query conditions in the user attribute of QueryVo. 

as follows:

public class QueryVo implements Serializable { 
 private User user; 
 public User getUser() {
   return user; 
 } 
 public void setUser(User user) {  
     this.user = user;  
    }
} 

In the interface:

public interface IUserDao {   
  List<User> findByVo(QueryVo vo);
} 
<selectid="findByVo"resultType="com.YCy.domain.User"parameterType="com.Ycy.domain.QueryVo">  
    select * from user where username like #{user.username}; 
</select> 

ognl expression:   
       It is an expression language provided by apache. The
       full name is: Object Graphic Navigation Language  
       .   
       It obtains data according to a certain grammatical format.  
       The syntax format is to use #{ object.object }'s way 
      #{user.username} It will first find the user object, then find the username attribute in the user object, and call the getUsername() method to get the value out. But we have specified the entity class name on the parameterType attribute, so you can omit user. and write username directly.

If it is a general attribute directly, such as a username attribute in the User class, we pass User as an object as a parameter, and we use it directly, #{username},

Because parameterType already provides the class to which the attribute belongs, there is no need to use the object name


 

Guess you like

Origin blog.csdn.net/weixin_43725517/article/details/108918856