目前ibatis只支持查询语句的动态拼接,暂不支持动态的拼接insert和update语句操作

Java code :    

  1.   // just a releation to the table stored in db   
  2.   public class Test {   
  3.       public String name;   
  4.       public Timestamp date;   
  5.       public int id;   
  6.   }   
  7.   public class TestInsert {   
  8.      // logger class you can replace it to System.out.println   
  9.      static Log logger = LogFactory.getLog(TestInsert.class);   
  10.     
  11.      public static void main(String[] args) {   
  12.          /* 
  13.           * Test test = new Test(); test.date = new  
  14.           * Timestamp(System.currentTimeMillis()); test.name = "fffff"; try {  
  15.           * long num = (Long) EntityManager.getSqlMapper().insertArgs(  
  16.           * "insertOperation", "fffff", new  
  17.           * Timestamp(System.currentTimeMillis())); logger.info("ID is " + num);  
  18.           * } catch (SQLException e) { e.printStackTrace(); }  
  19.           */  
  20.          // try the dynamic table dealation   
  21.          HashMap<String, Object> map = new HashMap<String, Object>();   
  22.          // set the query value    
  23.          map.put("ID""dizhuang");   
  24.          // set the col1 to be selected   
  25.          map.put("col1""*");   
  26.            // set the table name   
  27.          map.put("tablePrefix""testsocevent");   
  28.          // set the col name which you use   
  29.            map.put("col2""NAME");   
  30.          // map.put("ID", 1000);   
  31.          // map.put("id", "1005");   
  32.          try {   
  33.              // why args is error?   
  34.              Test test = (Test) EntityManager.getSqlMapper().queryForObject(   
  35.                  "getTest", map);   
  36.              logger.info("id : " + test.id);   
  37.              logger.info("time :" + test.date);   
  38.              logger.info("name : " + test.name);   
  39.          } catch (SQLException e) {   
  40.              logger.error(e.getMessage(), e);   
  41.              // e.printStackTrace();   
  42.          }   
  43.      }   
  44.  }   
  45.   // ibatis sql   
  46.   <select id="getTest" parameterClass="java.util.HashMap"  
  47.     resultClass="com.neusoft.soc.eventcenter.test.Test"  
  48.     remapResults="true">   
  49.     SELECT   
  50.         $col1$   
  51.     FROM   
  52.         $tablePrefix$   
  53.     WHERE   
  54.       $col2$ = #ID#   
  55.    </select>