手动封装:
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>