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