mybatis parametertype 多个参数

一、单个参数:

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 来补充。

二、多参数:

方案1

public List<XXXBean> getXXXBeanList(String xxId, String xxCode);  <select id="getXXXBeanList" resultType="XXBean">不需要写parameterType参数select t.* from tableName where id = #{0} and name = #{1}  </select>  由于是多参数那么就不能使用parameterType, 改用#{index}是第几个就用第几个的索引,索引从0开始

方案2(推荐)基于注解

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. 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.iconPathfrom TD_WEB_SYSSITE tleft join TD_MZ_MZDY t1 on t1.mzNum = t.siteTag and t1.mzType = 10WHERE t.siteTag = #{siteTag } and t.sysSiteId not in <foreach collection="list" item="item" index="index" open="(" close=")" separator=",">#{item}</foreach></select>

mybatis parametertype 多个参数相关推荐

  1. SSM之一点一滴:mybatis parameterType传入类型 resultType返回类型

    一.parameterType参数传入类型 概述: parameterType传入参数类型可以为int,String,Integer,Date,java实体类,map等,下面的用法中采用的是param ...

  2. MyBatis注解模式取参数方法

    2019独角兽企业重金招聘Python工程师标准>>> @Select("select count(*) from (select id from patrol_host ...

  3. MyBatis多个接口参数报错:Available parameters are [0, 1, param1, param2], 及解决方法

    MyBatis多个接口参数报错:Available parameters are [0, 1, param1, param2], 及解决方法 参考文章: (1)MyBatis多个接口参数报错:Avai ...

  4. Mybatis (ParameterType) 如何传递多个不同类型的参数

    问题 当在写查询语句的时候需要传入多个参数的时候该怎么办呢? 方法一:不需要写parameterType参数 //传参 public List<XXXBean> getXXXBeanLis ...

  5. Mybatis传递多个参数的4种方式

    现在大多项目都是使用Mybatis了,但也有些公司使用Hibernate.使用Mybatis最大的特性就是sql需要自己写,而写sql就需要传递多个参数.面对各种复杂的业务场景,传递参数也是一种学问. ...

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

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

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

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

  8. mybatis传递多个参数_Mybatis传递多个参数的4种方式(干货)

    现在大多项目都是使用Mybatis了,但也有些公司使用Hibernate.使用Mybatis最大的特性就是sql需要自己写,而写sql就需要传递多个参数.面对各种复杂的业务场景,传递参数也是一种学问. ...

  9. MyBatis 传递多个参数

    2019独角兽企业重金招聘Python工程师标准>>> 在MyBatis中可以用以下的方式来传递多个参数 1. 用java.util.Map来传递, Code 如下: public ...

最新文章

  1. iOS自动签名打包(xcodebuild)----常用
  2. echarts.js 做图表的插件
  3. PHP解决方案@时间戳与时间日期
  4. android tv如何适配不同的平台
  5. linq之join子句
  6. android开发期间使用真机调试但系统无法识别出真机
  7. css水平垂直居中(绝对定位居中)
  8. AMD OpenCL 大学课程
  9. ubuntu rpm安装_为什么说Ubuntu是一个值得尊敬的Linux发行版
  10. npm如何设置淘宝镜像
  11. python123第五章_python 3.5学习笔记(第五章)
  12. 江西冶金职业技术学院计算机,计算机基础知识江西冶金职业技术学院.ppt
  13. camera (19)---Android 相机开发的基本流程
  14. check oracle 为空值_索引(index)-Oracle高级知识(3)-数据库(23)
  15. 对外汉语偏误语料库_哇,9大对外汉语必备语料库,每个都很有“性格”!!...
  16. java中ftl什么文件_.ftl文件 是什么文件 freemarker
  17. C#箴言:定义常量的两种方法
  18. Exp3 免杀原理与实践 20164323段钊阳
  19. 边缘风行视频采集软件V1.0
  20. 6、Shiro之自定义realm

热门文章

  1. Comet 反Ajax: 基于jQuery与PHP实现Ajax长轮询(LongPoll)
  2. CSS3: 常用动画特效及4个最流行的动画库
  3. Moodle: 查询任意数据库
  4. ubuntu下中文输入法的安装--fcitx
  5. Magento获取产品自定义属性及对应的值
  6. ROS小白——knict相机标定(2)
  7. 【matplotlib】绘制动态图像
  8. 演练 玩游戏支付游戏币
  9. 视图请求限定装饰器-101.课时101.【Django视图高级】限制请求method装饰器(Av61533158,P101)
  10. dj鲜生-26-登陆时-记住用户名的操作