13

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.

1 Answer 1

27

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Could it be parameter name specified in XML (not with @Param annotation in code)?
Should only work with @org.apache.ibatis.annotations.Param and not with @org.springframework.data.repository.query.Param.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.