Is there any way to select/update/delete dynamically using Ibatis/MyBatis?
When I say "dynamically" it means I don't want to create any POJO/DataMapper at all.
Any URL example would be welcomed.
Is there any way to select/update/delete dynamically using Ibatis/MyBatis?
When I say "dynamically" it means I don't want to create any POJO/DataMapper at all.
Any URL example would be welcomed.
Yes, just set the
resultType
attribute tomap
and the table data will be placed into a HashMap of column names to values. If the query returns more than 1 row, the mapped rows will be put into a List. If you want to select a single column, you can get just that value (as String, int, etc) or as a list.This applies to MyBatis 3; I think you can do something similar in iBatis 2.
The following approach can be useful. Say, you have some generic select interface, like:
According to some external type (say, single column or date range or range whatsoever) you can define the following query in the template
Common.xml
:What you receive from mybatis is the java.util.Map. Then you can you use it some kind like:
where the SetParameter can be represented as the following:
Moreover, you can define some WhereStmt like:
Finally, in mybatis generic
Common.xml
you can use it like:And combine sql statements as the template, say:
Yes, it should be possible to build the mapping in runtime through an API, and to use Maps instead of entity classes.