一、单个参数:

public List<XXBean> getXXBeanList(@param("id")String id);  

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

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

</select>  

其中方法名和ID一致,#{}中的参数名与方法中的参数名一致, 这里采用的是@Param这个参数,实际上@Param这个最后会被Mabatis封装为map类型的。

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开始
public List<XXXBean> getXXXBeanList(@Param("id")String id, @Param("code")String code);  

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

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

</select>  

由于是多参数那么就不能使用parameterType, 这里用@Param来指定哪一个

三、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')

五、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");
  1.  
    map.put("list", list); //网址id
  2.  
     
  3.  
    map.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>
 

mybatis 传入多个参数的更多相关文章

  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(String xxCode); <select id="getXXXBeanList&q ...

  9. MyBatis传入多个参数 ,List集合

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

随机推荐

  1. 修复bug及修复过程

    1.本地存储数据显示不出问题 问题细节: 本地使用如下语句存储成绩,"ScoreDisplay"为键,值为this.score.toString(),但是在cocos creato ...

  2. HTML里用如何包含引用另一个html文件 .

    给大家整理了3个方法,一个是HTML的iframe标签,别两个是JS引用.比如要在arr.html文件里引用index.html文件,方法如下. HTML引用方法: <iframe name=& ...

  3. keybd_event 被 SendInput 替代

    keybd_event   函数功能:该函数合成一次击键事件.系统可使用这种合成的击键事件来产生WM_KEYUP或WM_KEYDOWN消息,键盘驱动程序的中断处理程序调用keybd_event函数.在 ...

  4. 阿里开源项目 druid 相关资料汇总

    项目发起人访谈:http://www.iteye.com/magazines/90 github主页:https://github.com/alibaba/druid druid 项目,我想我能用很短 ...

  5. ds18b20采集温度并上报服务器

    交叉编译器:arm-linux-gcc-4.5.4 Linux内核版本:Linux-3.0 主机操作系统:Centos 6.5 开发板:FL2440 温度传感器:ds18b20 注:此程序的客户端是在 ...

  6. Tomcat增加虚拟内存(转)

    程序要遍历读取xml并写入数据库,需要占用大量内存 如果数据量大则报错 Exception in thread "Timer-0" java.lang.OutOfMemoryErr ...

  7. 动态库DLL中类的使用

    一.DLL中类的导出 在类名称前添加 _declspec(dllexport)定义,比如: class _declspec(dllexport) CMath{ .... }; 通常使用预编译开关切换类 ...

  8. .Net学习资料

    1.博客系列文章 (1)设计模式 吕震宇 设计模式 张逸:晴窗笔记 Design & Pattern 梦幻Dot Net  .Net设计模式 李会军          .NET设计模式系列文章 ...

  9. 阿里云Logtail 快速诊断工具

    当日志采集发生异常时,您可以通过Logtail自助检测工具查看客户端是否存在异常情况,根据工具提示快速定位并解决问题.   说明 本工具目前仅支持Linux系统的服务器. 准备工作 下载检测工具脚本. ...

  10. 【Windows】cmd条件判断

    1.判断驱动器.文件或文件夹是否存在,用 if exist 语句: 2.判断某两个字符串是否相等,用 if "字符串1"=="字符串2" 语句: 3.判断某两个 ...