手动封装:

serviceImpl层

  1. Map<String, Object> params = new HashMap<String, Object>(2);params.put("bigCodeArray", bigCodeArray);params.put("agentId", agentId);
  1. List<String> numberList = usednumber400Dao.selectNumberInBigByStatus(params);
  2.  
  3. dao层:
  1. List<String> selectNumberInBigByStatus(Map<String, Object> params);mapper层:
  1. <select id="selectNumberInBigByStatus" parameterType="map" resultType="string"> SELECT number from usednumber400 WHERE agentID=#{agentId} and number IN <foreach collection="bigCodeArray" item="item" index="index" open="(" close=")" separator=","> #{item} </foreach>
  2.  
  3. </select>

推荐网址:http://iyiguo.net/blog/2012/09/27/mybatis-param-mapping-rules/

MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'voyagenum' not found. Available parameters are [0, 1, param1, param2]

MyBatisSystemException:嵌套异常是org.apache.ibatis.binding。BindingException:未找到参数“voyagenum”。可用参数为[0,1,param1, param2]

解析:Dao层向sql语句传递多个参数时

方法1:注解形式,注意添加注解@Param("mainfestid")

  1. public String selectUuidByM(@Param("mainfestid")String mainfestid, @Param("voyagenum")String voyagenum);

方法2:索引方式  #{index}从0开始

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

方法3:索引方式  param1 从1开始

  1. User getUserByNameAndPwd(String username, String password);
  2.  
  3. <select id="getUserByNameAndPwd" parameterType="String" resultMap="user">
  4. select * from d_user where user_name =#{param1} and user_password=#{param2}
  5. </select>

  

Dao层向sql语句传递多个参数的更多相关文章

  1. Dao层的sql语句

    2018-08-12     21:33:43 反思:在数据库执行的时候,sql语句是正确的,复制到方法中,执行出错   因为把限定条件改为?时,把左括号删掉了,sql语句报错 改正:一定要确保sql ...

  2. mybatis 中sql语句传递多个参数

    Available parameters are [2, 1, 0, param1, param2, param3] <select id="loginByTeacher"  ...

  3. 分享公司DAO层动态SQL的一些封装

    主题 公司在DAO层使用的框架是Spring Data JPA,这个框架很好用,基本不需要自己写SQL或者HQL就能完成大部分事情,但是偶尔有一些复杂的查询还是需要自己手写原生的Native SQL或 ...

  4. mybatis中sql语句传入多个参数方法

    1 使用map <select id="selectRole" parameterType="map" resultType="RoleMap& ...

  5. 执行sql语句异常...需要的参数与提供的值个数不匹配

    执行mysql语句时,出现以下错误时. 看错误提示,提示说你的sql语句只需要5个参数,而你提供了8个值value,你确定你确实需要8个参数,而你的sql语句却提示说只需要5个参数 这时,请仔细检查一 ...

  6. sql语句中给列参数取别名及相关注意事项

    1.使用双引号 select count(*) "总数" from table: 2.使用单引号 select count(*) '总数' from table: 3.直接加别名, ...

  7. 动态sql语句和动态传入参数个数

    1.可以将要传入的几个参数封装成一个实体类,然后将实体类作为一个参数传入到相应的方法中,这时候就需要这sqlMapper.xml文件中对传入的字段利用<if test=""& ...

  8. EF6.0 下sql语句自动生成的参数类型decimal(18,2)修改

    很多时候我们需要对插入到数据库的数据的精度做一个控制,例如sql server下保留6位小数使用numeric(10,6) .而到c#里对应的数据类型就是decimal ,但是使用EF6.0的crea ...

  9. Java高并发秒杀API之业务分析与DAO层

    根据慕课网上关于java高并发秒杀API的课程讲解用maven+ssm+redis实现的一个秒杀系统 参考了codingXiaxw's blog,很详细:http://codingxiaxw.cn/2 ...

随机推荐

  1. django-权限验证场景

    1.需要登录才能够访问的验证 from django.contrib.auth.decorators import login_required # 登录装饰器 # method_decorator ...

  2. python中的upper、lower、capitalize、title

    upper()字符串中字母由小写变为大写 lower()字符串中字母由大写变为小写 capitalize()字符串中字母首字母大写其余小写 title()字符串中字母每个单词的首字母大写其余小写 举个 ...

  3. python中的format

    format()格式化字符串,将占位符替换成内容,举个例子: 1 a = "hello {0} welcome to {1}" 2 a1 = a.format("dlrb ...

  4. RMI non-JRMP server at remote endpoint

    又是一个jmx问题 jmx明明端口占用了, 而且相关java进程也起来了, 为什么会不能通过jconsole访问jmx呢?总是:RMI non-JRMP server at remote endpoi ...

  5. djangobb之forum.topics

    看djangobb源代码时,看到view的show_forum(request, forum_id, full=True)时,对于topics = forum.topics.order_by('-st ...

  6. redis 做默认缓存

    配置: server.port= # REDIS (RedisProperties) # Redis\u6570\u636E\u5E93\u7D22\u5F15\uFF08\u9ED8\u8BA4\u ...

  7. jsp中文乱码

    <%@page pageEncoding="UTF-8"%> <meta http-equiv="Content-Type" content= ...

  8. Delphi Locate 详解1 转

    TDataSet控件以及它的继承控件,例如TSimpleDataSet/TClientDataSet等都可以使用Locate方法在结果数据集中查寻数据.程序首先必须使用SQL命令从后端数据库中取得数据 ...

  9. Linux:使用读写锁使线程同步

    基础与控制原语 读写锁 与互斥量类似,但读写锁允许更高的并行性.其特性为:写独占,读共享. 读写锁状态: 一把读写锁具备三种状态:     1. 读模式下加锁状态 (读锁)     2. 写模式下加锁 ...

  10. E_FAIL (0x80004005) MachineWrap

    下载VirtualBox-4.3.12-93733-Win.exe,下载地址:http://download.virtualbox.org/virtualbox/4.3.12/