一、单个参数:

public List<XXBean> getXXBeanList(String xxCode);  

<select id="getXXXBeanList" parameterType="java.lang.String" resultType="XXBean">

  select t.* from tableName t where t.id= #{id}  

</select>  

其中方法名和ID一致,#{}中的参数名与方法中的参数名一直, 我这里采用的是XXXBean是采用的短名字,

select 后的字段列表要和bean中的属性名一致, 如果不一致的可以用 as 来补充。

二、多参数:

public List<XXXBean> getXXXBeanList(String xxId, String xxCode);  

<select id="getXXXBeanList" resultType="XXBean">

  select t.* from tableName where id = #{0} and name = #{1}  

</select>  

由于是多参数那么就不能使用parameterType, 改用#{index}是第几个就用第几个的索引,索引从0开始

三、Map封装多参数:

public List<XXXBean> getXXXBeanList(HashMap map);  

<select id="getXXXBeanList" parameterType="hashmap" resultType="XXBean">

  select 字段... from XXX where id=#{xxId} code = #{xxCode}  

</select>  

其中hashmap是mybatis自己配置好的直接使用就行。map中key的名字是那个就在#{}使用那个,map如何封装就不用了我说了吧。 

 四、List封装in:

public List<XXXBean> getXXXBeanList(List<String> list);  

<select id="getXXXBeanList" resultType="XXBean">
  select 字段... from XXX where id in
  <foreach item="item" index="index" collection="list" open="(" separator="," close=")">
    #{item}
  </foreach>
</select> foreach 最后的效果是select 字段... from XXX where id in ('1','2','3','4')

五、多参数传递之注解方式示:

例子:

public AddrInfo getAddrInfo(@Param("corpId")int corpId, @Param("addrId")int addrId);

xml配置这样写:

<select id="getAddrInfo"  resultMap="com.xxx.xxx.AddrInfo">
SELECT * FROM addr__info
    where addr_id=#{addrId} and corp_id=#{corpId}
</select> 以前在<select>语句中要带parameterType的,现在可以不要这样写。

六、selectList()只能传递一个参数,但实际所需参数既要包含String类型,又要包含List类型时的处理方法:

将参数放入Map,再取出Map中的List遍历。如下:

List<String> list_3 = new ArrayList<String>();
Map<String, Object> map2 = new HashMap<String, Object>();

list.add("1");
list.add("2");
map2.put("list", list); //网址id

map2.put("siteTag", "0");//网址类型
public List<SysWeb> getSysInfo(Map<String, Object> map2) {
  return getSqlSession().selectList("sysweb.getSysInfo", map2);
}
<select id="getSysInfo" parameterType="java.util.Map" resultType="SysWeb">
  select t.sysSiteId, t.siteName, t1.mzNum as siteTagNum, t1.mzName as siteTag, t.url, t.iconPath
from TD_WEB_SYSSITE t
left join TD_MZ_MZDY t1 on t1.mzNum = t.siteTag and t1.mzType = 10
WHERE t.siteTag = #{siteTag }
and t.sysSiteId not in
<foreach collection="list" item="item" index="index" open="(" close=")" separator=",">
#{item}
</foreach>
</select>
 
 
 
 
 
 
 
 
 
 
 

1.由于是多参数那么就不能使用parameterType, 改用#{index}是第几个就用第几个的索引,索引从0开始

<update id="modifyPwd">
UPDATE ams_user
SET login_pwd = #{0}, update_time =#{1,jdbcType=TIMESTAMP}
WHERE user_id = #{2,jdbcType=INTEGER}
</update>
  1. 通过注解的方式 
    调用方法:
Integer modifyPwd(@Param("userId")Integer userId,@Param("pwd") String pwd,@Param("upTime") Date updateTime);

xml中的写法:

<update id="modifyPwd">
UPDATE ams_user
SET login_pwd = #{pwd}, update_time = #{upTime,jdbcType=TIMESTAMP}
WHERE user_id = #{userId,jdbcType=INTEGER}
</update>

3.通过Map的方式传递多个参数 
map中key的名字就是在#{}中使用的那个

Integer modifyPwd(HashMap map);  

<update id="modifyPwd" parameterType="hashmap">
UPDATE ams_user
SET login_pwd = #{pwd}, update_time = #{upTime,jdbcType=TIMESTAMP}
WHERE user_id =#{userId,jdbcType=INTEGER}
</update>
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/shi1451042748/article/details/51786207

MyBatis传入多个参数 ,List集合的更多相关文章

  1. 小峰mybatis(2)mybatis传入多个参数等..

    一.mybatis传入多个参数: 前面讲传入多个参数都是使用map,hashmap:key value的形式:-- 项目中开发都建议使用map传参: 比如现在通过两个参数,name和age来查询: 通 ...

  2. (转)MyBatis传入多个参数的问题

    背景:记录mybaitis的使用方法,博闻强记,后面尽量记忆使用. MyBatis传入多个参数的问题 MyBatis传入多个参数的问题 详细记录mybatis在传递多个参数时候的使用方法 关于Myba ...

  3. mybatis传入多个参数

    一.单个参数: public List<XXBean> getXXBeanList(String xxCode); <select id="getXXXBeanList&q ...

  4. Mybatis 传入多个参数查询数据 (3种方法)

    第一种方案 DAO层的函数方法 public User selectUser(String name,String area); 对应的Mapper.xml <select id="s ...

  5. MyBatis传入多个参数的问题

    一.单个参数: public List<XXBean> getXXBeanList(String xxCode); <select id="getXXXBeanList&q ...

  6. [转]MyBatis传入多个参数的问题 - mingyue1818

    原文  http://www.cnblogs.com/mingyue1818/p/3714162.html 一.单个参数: public List<XXBean> getXXBeanLis ...

  7. (转载)MyBatis传入多个参数的问题

    原文地址:https://www.cnblogs.com/mingyue1818/p/3714162.html 一.单个参数: public List<XXBean> getXXBeanL ...

  8. mybatis 传入多个参数

    一.单个参数: public List<XXBean> getXXBeanList(@param("id")String id); <select id=&quo ...

  9. MyBatis传入多个参数的问题(转)

    一.单个参数: public List<XXBean> getXXBeanList(String xxCode); <select id="getXXXBeanList&q ...

随机推荐

  1. Linux 比较重要且难掌握命令 集合

    1. find find path –option [-print] [-exec command] {} \; find . -maxdepth 1 -name aa find . -maxdept ...

  2. asp.net c#采集需要登录页面的实现原理及代码

    当我们采集页面的时候,如果被采集的网站需要登录才能采集,原理搞清楚了,就好办了,我们所要做的仅仅是在采集的时候(或者说HttpWebRequest提交数据的时候),将Cookie信息放入Http请求头 ...

  3. react手记(componentWillMount,componentDidMount等)

    生命周期componentWillMount 组件出现前 就是dom还没有渲染到html文档里面componentDidMount 组件渲染完成 已经出现在dom文档里可以再各个周期实现特定的操作 生 ...

  4. PID file found but no matching process was found. Stop aborted

    一般脚本部署时不会遇到这种情况,有时候自个手动处理会出现”PID file found but no matching process was found. Stop aborted”,根据意思就可以 ...

  5. eval()和exec()函数的区别

    (1)eval(str [,globals [,locals ])函数将字符串str当成有效Python表达式来求值,并返回计算结果.(2)exec()函数将字符串str当成有效的Python表达式来 ...

  6. WordArray (An array of 32-bit words.

    CryptoJS中WordArray - qiqi715 - 博客园 http://www.cnblogs.com/qiqi715/p/9623421.html

  7. Avoiding Full Table Scans

    w MySQL :: MySQL 5.7 Reference Manual :: 9.2.1.19 Avoiding Full Table Scanshttps://dev.mysql.com/doc ...

  8. PHP-Heredoc用法:<<<EOFEOF;

    Heredoc,用来输出大段的HTML和JavaScript <<<EOF后面不能有空格. EOF;末尾的结束符必须靠边,并且前面不能有空格和缩进符. 例如: $mazey=< ...

  9. mustache模板技术(转)

    项目首页:http://mustache.github.com/  项目文档:http://mustache.github.com/mustache.5.html  Demo:  http://mus ...

  10. SpringBoot处理url中的参数的注解

    1.介绍几种如何处理url中的参数的注解 @PathVaribale  获取url中的数据 @RequestParam  获取请求参数的值 @GetMapping  组合注解,是 @RequestMa ...