ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brandon Goodin <brandon.goo...@gmail.com>
Subject Re: dynamic Sql and parameter together
Date Sun, 12 Feb 2006 03:46:59 GMT
You should likely be using iBatis dynamic SQL capabilites with the
dynamic tags in your <select>. You can learn about Dynamic SQL in the
manual.

Latest Open Office Manual:
http://svn.apache.org/repos/asf/ibatis/trunk/java/docs/iBATIS-SqlMaps-2.sxw

Brandon

On 2/11/06, wang lei <wl_95421@yahoo.com.cn> wrote:
>
>
> I just build a DAO,which supports ojb ,hibernate.
> Now i want to support Ibatis too.
> But when i build the parameters,i got a problem.
>
> Here is a sql statement in the xml.
>
> <select id="doSelectUser" parameterClass="java.util.Map"
> resultMap="userResult">
>     <![CDATA[
>      Select  USER_ID, USER_NAME, PHOTO, USER_MEMO from DEMO.USER_T
>      $Where$ $condition$
>     ]]>
>  </select>
>
> Here is t he java code.
>
>   Map t_Map = new HashMap();
>   t_Map.put("Where", "where");
>   t_Map.put("condition", new Integer(10));
>
>   List t_List = this.sqlMap.queryForList("doSelectUser", t_Map);
>
> Sure,the sql for "select" is
> Select  USER_ID, USER_NAME, PHOTO, USER_MEMO from DEMO.USER_T     where
> USER_ID>10
> the result is right.
>
> Now i change the red code to the following.
>   &nb sp; t_Map.put("condition", " USER_ID>#userId#");
>     t_Map.put("userId", new Integer(10));
>
> I want to get a sql
>
> Select  USER_ID, USER_NAME, PHOTO, USER_MEMO from DEMO.USER_T     where
> USER_ID>#userId#
>
> Then the ibatis can use parameter of "userId" int the parameter map to
> replace the "#userId#".
> Just like
> Select  USER_ID, USER_NAME, PHOTO, USER_MEMO from DEMO.USER_T     where
> USER_ID>10
>
> This method is useful to build a dynamic sql.
>
> Of course,i just get the fi rst sql.
> Who knows how to solve the problem.
>
>
>  ________________________________
> 无限容量雅虎相册,原图等大下载,超快速度,赶快抢注!
>
>
Mime
View raw message