0

I have a update query in mapper interface using mybatis

 final String UPDATE ="update table_addresses "
                            + "set postCode= #{postCode}"
                            + "where id in"
                            + "<foreach item='item' index='index' 
                               collection='addressId' "
                            + "open='(' separator=',' close=')'>  #{item} 
                 </foreach>";
@Update(UPDATE)
public int updateInformation(@Param("postCode") String postCode , 
@Param("addressId") List<AddressID> addressId);

My AddressId class contains int type addressId:

AddressId {
private int addressId;
} 

Now the method where I am calling mapper Interface..I am sending a String postCode and object List addresses.

I am getting below error Caused by: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'item' not found. Available parameters are [param1, param2, postCode, addressId]..What Ia m doing wrong here.What is the correct syntax of foreach loop where I can pass addressId which conatins List.

2 Answers 2

0

For the complex sql statments. I prefer to use SelectBuilder/UpdateBuilder.

See the last part of this page mybatis-java-api

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

Comments

0

Try to wrap your whole SQL code in <script> tag like String SQL = "<script>(SQL goes here)</script>" if you use XML tags inside annotation defined query. Probably MyBatis doesn't see your #{item}, because it doesn't know about it (it treats all as SQL).

But, as Dean Xu sais, sql builder is better for more complicated queries.

Comments

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.