码迷,mamicode.com
首页 > 其他好文 > 详细

Mybatis的parameterType传入多个参数

时间:2017-10-15 19:38:21      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:res   ace   strong   文件   line   sele   语句   map   string   

如果查询的条件有多个的时候,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> 

  

 

Mybatis的parameterType传入多个参数

标签:res   ace   strong   文件   line   sele   语句   map   string   

原文地址:http://www.cnblogs.com/misshello/p/7672723.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!