手动封装:

serviceImpl层

Map<String, Object> params = new HashMap<String, Object>(2);params.put("bigCodeArray", bigCodeArray);params.put("agentId", agentId);
List<String> numberList = usednumber400Dao.selectNumberInBigByStatus(params);

dao层:
List<String> selectNumberInBigByStatus(Map<String, Object> params);mapper层:
<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>

</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")

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

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

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开始

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

User getUserByNameAndPwd(String username, String password);

<select id="getUserByNameAndPwd" parameterType="String" resultMap="user">
select * from d_user where user_name =#{param1} and user_password=#{param2}
</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. 自写UiAutomator 调试类

    package sms_test; import java.lang.*; import java.util.ArrayList; import java.util.Collection; impor ...

  2. TIDB-cenos7开发环境搭建

    1.安装centos7,注意要安装桌面,如果最小化安装,无法使用IDE了 关闭防火墙或者打开4000端口 systemctl stop firewalld.service #停止firewall sy ...

  3. 高级php面试题转载

    在网上看到一些高级php 的面试题目.. 最近接连面试了几家公司,有些重要问题记录一下,督促自己学习提高,同时希望给朋友们一些帮助.内容很多,一点点完善,一步步学习..有些是面试被问,有些是招聘要求, ...

  4. centos7管理用户权限

    1.Centos创建用户并授权: https://blog.csdn.net/bug4pie/article/details/79761443 https://www.jb51.net/article ...

  5. Android开发之SurfaceView

    SurfaceView介绍 通常情况程序的View和用户响应都是在同一个线程中处理的,这也是为什么处理长时间事件(例如访问网络)需要放到另外的线程中去(防止阻塞当前UI线程的操作和绘制).但是在其他线 ...

  6. 如何在notepad++实现代码自动化排版(调用Astyle)

    我先介绍这个怎么在notepad++中调用原版的astyle的方法. 在notepad++:运行或是F5, 在输入框中选择astyle.exe所在的目录,什么你没有astyle,下载地址https:/ ...

  7. Activity服务类-9 TaskService服务类

    一共72个接口 1.创建任务(2个方法)//创建与任何流程实例无关的新任务.Task newTask();//使用用户定义的任务id创建一个新任务.Task newTask(String taskId ...

  8. svn2

    ubuntu下安装subversion客户端: sudo apt-get install subversion subversion-tools 详细请看 http://www.subversion. ...

  9. iframe+form表单提交数据

    <h6>基于iframe+Form表单</h6> <iframe id="iframe" name="ifra" onclick= ...

  10. ORM 的基本操作

    https://www.cnblogs.com/sss4/p/7070942.html