Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error in mapper when using parameter name

Tags:

java

mybatis

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.

like image 490
mrkb80 Avatar asked Nov 15 '13 00:11

mrkb80


1 Answers

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.

like image 182
Larry.Z Avatar answered Oct 28 '22 14:10

Larry.Z