Iterate list of Objects in Ibatis

匿名 (未验证) 提交于 2019-12-03 01:33:01

问题:

I have a list of object where I want to iterate and access a particular field in ibatis sql.

Ex.

public Class Student { String id; String name; }

I will pass as parameter a List of Student object(List(Student))
and do iteration accessing the id for each object bean. How do I do this?

回答1:

The foreach-tag is what you are looking for. Example:

See the user guide for more info, chapter "dynamic sql".

By the way, iBatis is no longer developed and is frozen, it is now called "MyBatis" and the whole developer team moved away from Apache to the new MyBatis home.



回答2:

A simple example.

Refer iBatis documentation for more info.

As Sylar pointed out, the java equivalent would be

iBatis allows you to variables item and index which you can use inside the loop.



回答3:

Try something like:

where id and name are fields of Student class and my parameterClass is List.

Worked for me.

The sql formed dynamically will look like:

select * from STUDENTS where ( id, name ) in ( (1,'a'), (2,'b') )


转载请标明出处:Iterate list of Objects in Ibatis
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!