Mybatis:parameter ' IDs ' not found. Available parameters are [TemplateID, param1, param2, ValueList]

Source: Internet
Author: User

mybatis:parameter ' IDs ' not found. Available parameters are [TemplateID, param1, param2, ValueList]


A very interesting question was found tonight:

Mybatis:parameter ' IDs ' not found. Available parameters are [TemplateID, param1, param2, ValueList]

Could not find this IDs this set variable,

<!--public list<employee> Getempsbyconditionforeach (list<integer>  emp);-->
	<select Id= "Getempsbyconditionforeach" resulttype= "Com.cn.zhu.bean.Employee"
	>
	    select * from  tbl_employee where ID in
	   <!-- 
	     Collection specifies that the parameters of the collection list type to be traversed are
	         specially handled in the map, and the map key is called the list
	      item to assign the currently traversed element to the specified variable
	      #{variable name} You can take out the value of a variable, which is the current traversal
	      separator The delimiter between each element
	      open traversal out all results stitching a start character
	      close: traverse out all result stitching an ending character Index
	      : Indexes  are indexed when traversing the list, the item is the  current value
	                 traversing the map when index represents the map's key    item is the map's value
	    -- >
	    <foreach collection= "IDs" item= "item_id" separator= "," open= "(" close= ")"
	    >
	      #{item_id} "
	    </foreach>
	    
	</select>
Console error

### Error querying database. Cause:org.apache.ibatis.binding.BindingException:Parameter ' IDs ' not found. Available parameters are [List, collection]


I can't find the value of IDs, so the problem is.

In fact

collection specifies the collection to traverse
The parameters of the list type are specially handled in the map, and the map key is called list


change to::

<!--public list<employee> Getempsbyconditionforeach (list<integer>  emp);-->
	<select Id= "Getempsbyconditionforeach" resulttype= "Com.cn.zhu.bean.Employee"
	>
	    select * from  tbl_employee where ID in
	   <!-- 
	     Collection specifies that the parameters of the collection list type to be traversed are
	         specially handled in the map, and the map key is called the list
	      item to assign the currently traversed element to the specified variable
	      #{variable name} You can take out the value of a variable, which is the current traversal
	      separator The delimiter between each element
	      open traversal out all results stitching a start character
	      close: traverse out all result stitching an ending character Index
	      : Indexes  are indexed when traversing the list, the item is the  current value
	                 traversing the map when index represents the map's key    item is the map's value
	    -- >
	    <foreach collection= "list" item= "item_id" separator= "," open= "(" close= ")"
	    >
	      #{item_id} "
	    </foreach>
	    
	</select>

to solve the collection= "list" Problem




Test class

@Test public
	void  Testdynamicsql () throws  ioexception{
		sqlsessionfactory sqlsessionfactory= Getsqlsessionfactory ();
		Sqlsession opensession=sqlsessionfactory.opensession ();
		try {
			employeemapperdynamicsql   mapper=	opensession.getmapper (employeemapperdynamicsql.class);	
			
			list<employee> list11 = Mapper.getempsbyconditionforeach (Arrays.aslist (1,2,3,4));
			for (Employee emp:list11) {
				System.out.println (EMP);
			}
		catch (Exception e) {
			//Todo:handle EXCEP tion
			opensession.close ();
			E.printstacktrace ();
		}

	

So, why do you change that way?

collection specifies that the parameters of the collection list type to be traversed
	         will be specially handled in the map, the map key is called list

The fundamental reason is that they simply do not understand the collection in foreach should put something, the wrong understanding of the java.util.List, in fact, this type should be the same as our @param binding parameter name


<!--public void Addemps (@Param ("Emps") list<employee> emps);  -->
if preceded by an alias, then collection will use alias Emps,,,, otherwise the default list

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.