首页 > 其他 > 详细

Mybatis传递多个参数

时间:2018-09-07 17:48:17      阅读:151      评论:0      收藏:0      [点我收藏+]

一、使用索引 #{index}

DAO层函数方法

Public User selectUser(String name, String area);

Mapper.xml中SQL

<select id="selectUser" resultMap="BaseResultMap">
    select  
        *  
    from 
        user_user_t
    where 
        user_name = #{0} and user_area=#{1}
</select>

二、使用Map

DAO层函数方法

Public User selectUser(Map<String, Object> map);

Mapper.xml中SQL

<select id="selectUser" resultMap="BaseResultMap">
    select  
        *  
    from 
        user_user_t
    where 
    user_name = #{username, jdbcType=VARCHAR} 
    and user_area = #{userarea, jdbcType=VARCHAR}
</select>

Service层函数调用

public User selectUser() {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("username", "zhangsan");
    map.put("userarea", "beijing");
    User user = mapper.selectUser(map);  
}

三、使用注解

DAO层函数

public User selectUser(@Param("userName")String username, @Param("userArea")String userarea);

Mapper.xml中SQL

<select id="selectUser" resultMap="BaseResultMap">
    select  
        *  
    from 
        user_user_t
    where 1 = 1 
    and user_name = #{userName} 
    and user_area=#{userArea}
</select>

Mybatis传递多个参数

原文:https://www.cnblogs.com/zhaohuichn/p/9606115.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!