手动封装:

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. C#取整函数Math.Round、Math.Ceiling和Math.Floor

    1.Math.Round:四舍六入五取偶 引用内容 Math.Round(0.0) //0Math.Round(0.1) //0Math.Round(0.2) //0Math.Round(0.3) / ...

  2. hive之窗口函数

    窗口函数 1.相关函数说明 COVER():指定分析函数工作的数据窗口大小,这个数据窗口大小可能会随着行的变而变化 CURRENT ROW:当前行 n PRECEDING:往前n行数据 n FOLLO ...

  3. Address already in use: JVM_Bind 端口被占用的几个解决办法

    运行Tomcat时若出现Address already in use: JVM_Bind 端口被占用,一般使用下面几个办法可以解决: 假设端口为1099 1.启动cmd, 执行命令netstat -a ...

  4. HTML5 Canvas 小例子 旋转的时钟

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  5. leetcode 题解 word search。递归可以更简洁。

    先写上我的代码: 我总是不知道何时把任务交给下一个递归.以致于,写出的代码很臃肿! 放上别人递归的简洁代码: bool exist(char** board, int m, int n, char* ...

  6. jquery接触初级-----ajax 之:jquery_ajax 方法

    1. $.get() 方法: 格式:$.get( url,[,data],[,callback],[,type] ); data:  采用键值对的方式存储于对象中; callback: 载入成功时(当 ...

  7. Slava and tanks 877C

    C. Slava and tanks time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  8. Haskell语言学习笔记(78)fix

    fix 函数 fix 是一个在 Data.Function 模块中定义的函数,它是对于递归的封装,可以用于定义不动点函数. fix :: (a -> a) -> a fix f = let ...

  9. LeetCode OJ 145. Binary Tree Postorder Traversal

    Given a binary tree, return the postorder traversal of its nodes' values. For example:Given binary t ...

  10. 知识点4: 配置echarts折线图和饼图

    折线图 效果图 html <template> <div id="v11-charts3"></div> </template> j ...