Mybatis的parameterType傳入多個參數


如果查詢的條件有多個的時候,mybatis有三種傳入方式:

1.通過注解傳入

例如:

public interface Mapper(){

    public User login(@Param("username")String username,@Param("password") String password);    
    
}

@Param注解:將對應形參的值在mapper.xml中傳入參數時,指定傳入參數的名稱。指定在mapper.xml中形參的名字(也就是mapper.xml的配置文件中查詢語句的名字)

例如下面標紅的部分 

<select id="login"  resultType="user">
    select * from user where username=#{username} and password=#{password};
</select>

2.pojo的對象傳入

public interface UserMappe{
    public User login(User user);  
}
<select id="login" resultType="user">
       select* from user where username=#{username} and password= #{password};
</select>  

注意:占位符中當參數傳遞的是pojo的時候,括號中的內容是pojo的屬性

3.map傳入方式

public interface UserMappe{
    public User login(Map<String ,Object> map);  
}

  

<select id="login" resultType="user">
       select* from user where username=#{username} and password= #{password};
</select> 

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM