Error in mapper when using parameter name

mrkb80 picture mrkb80 · Nov 15, 2013 · Viewed 26.1k times · Source

I am using Spring 3.2.0 MVC with mybatis 3.2.3 and mybatis-spring 1.2.1 with ojdbc6 11.2.0.2.0

I have an XML mapper defined with 2 parameters of different types (date and integer). I reference them in the query as #{myid} and #{mydate} but I get an error from ibatis:

org.apache.ibatis.binding.BindingException: Parameter 'myid' not found. Available parameters are [1, 0, param1, param2]

If I reference the parameters as #{0} and #{1} everything works fine.

I have a another mapper with only a single parameter and I am able to reference the parameter as #{myDate} (the only difference is that I have the following in the XML:

<select id="getAllbyDate" parameterType="date" resultType="com.test.myTest">

My problem is that the query with multiple parameters does not allow me to specify the parameter name in the XML file. I am able to reference by name with a single parameter.

Answer

Larry.Z picture Larry.Z · Nov 15, 2013

In mapper Interface java file write the method like this

public List<com.test.myTest> getAllbyDate(@Param("date") Date date, @Param("myid") int myid) 

Then, modify xml file

<select id="getAllbyDate" parameterType="map" resultType="com.test.myTest"> 

Mybatis put all parameters with annotation @Param into map.