ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Larry Meadors <larry.mead...@gmail.com>
Subject Re: Parameterized mapped-statement in iBatis
Date Fri, 24 Jun 2005 12:00:16 GMT
Yes, if your tables all have an id field and a description fields, you
could use $tableName$ in the from part of your SQL:

<select id="getNameValueList">
  description as name, 
  id as value
from $tableName$

Be careful doing this, because it is open to SQL injection attacks.

If you wanted, you could even do this (if your tables did not have all
the same id/description fields):

<select id="getNameValueList">
  $descriptionField$ as name, 
  $idField$ as value
from $tableName$

That would let you grab any two fields (or rather field expressions)
from any table.

Nice trick.


On 6/24/05, XU Qiang <q.xu@cofinoga.fr> wrote:
> Hi, 
> In Rick Reumann's site
> http://reumann.net/struts/ibatisLesson1/step5.do , he
> describes a common use case for a query of list  (value , label)  from a set
> of different tables. The sample map uses a list of very similar
> mapped-statement to populate a result-map. The reuse here is only the
> result-map. Is there someway to not list the queries but just parameterize
> mapped-statement with table name as parameter ? I am new in using ibatis, so
> any suggestion and pointer is valuable. 
> Thank you 
> Qiang

View raw message