ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wang lei <wl_95...@yahoo.com.cn>
Subject dynamic Sql and parameter together
Date Sun, 12 Feb 2006 02:53:15 GMT

 
  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 the 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.
      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 first sql.
  Who knows how to solve the problem.

   

		
---------------------------------
无限容量雅虎相册,原图等大下载,超快速度,赶快抢注! 
Mime
View raw message