ibatis参数

原型参数
< select id = "select1" parameterClass = "java.lang.String" resultClass = "AppLog" >
    select
      ID as id,
      TYPE as type,
      DESCR as descr
    from APP_LOG
    where ID = #id#
</ select >
  
sqlMapper .queryForObject( "select0" , id);
Map类参数
< select id = "select2" parameterClass = "java.util.HashMap" resultClass = "AppLog" >
    select
      ID as id,
      TYPE as type,
      DESCR as descr
    from APP_LOG
    where ID = #id#
</ select >    
map.put("id", id);
AppLog log = (AppLog) sqlMapper.queryForObject("select0", map);
对象参数
   < select id = "select3" parameterClass = "AppLog" resultClass = "AppLog" >
    select
      ID as id,
      TYPE as type,
      DESCR as descr
    from APP_LOG
    where ID = #id#
</ select >
AppLog p= new AppLog();
p.setId(id);
AppLog log = (AppLog) sqlMapper .queryForObject( "select3" , p);

< select id = "select0" resultClass = "AppLog" >
    select
      ID as id,
      TYPE as type,
      DESCR as descr
    from APP_LOG
    where ID = #id#
</ select >
Map参数
map.put("id", id);
AppLog log = (AppLog) sqlMapper.queryForObject("select0", map);
String参数
AppLog log = (AppLog) sqlMapper.queryForObject("select0", id);
对象参数
AppLog p= new AppLog();
p.setId(id);
AppLog log = (AppLog) sqlMapper .queryForObject( "select0" , p);

 

动态字段、表
< select id = "selectd" resultClass = "java.util.HashMap" parameterClass = "java.util.HashMap" remapResults = "true" >
    select $fieldList$     
    from $ table $
    where ID = #id#
</ select >
Map p = new HashMap();
p.put( "id" , id);
p.put( "table" , "APP_LOG" );
p.put( "fieldList" , "ID,TYPE,DESCR" );
Map map = (Map) sqlMapper .queryForObject( "selectd" , p);
String id1 = (String) map.get( "ID" );
String type = (String) map.get( "TYPE" );
String descr = (String) map.get( "DESCR" );

 

参数映射方式

<parameterMap>字段映射方式
< parameterMap id = ”insert-product-param” class = ”com.domain.Product” >
    <parameter property=id/>
    <parameter property=”description”/>
</ parameterMap >
< insert id = ”insertProduct” parameterMap = ”insert-product-param” >
    insert into PRODUCT (PRD_ID, PRD_DESCRIPTION) values (?,?)
</ insert >
< parameterMap id = ”insert-product-param” class = ”com.domain.Product” >
    < parameter property = ”description” />
    < parameter property = id />
</ parameterMap >
< insert id = ”insertProduct” parameterMap = ”insert-product-param” >
    insert into PRODUCT (PRD_DESCRIPTION, PRD_ID) values (?,?)
</ insert >
parameterMap 中属性的顺序与 SQL 中参数的顺序对应

Inline Parameter Maps
< insert id = ”insertProduct” parameterClass = ”com.domain.Product” >
    insert into PRODUCT (PRD_ID, PRD_DESCRIPTION)
    values (#id#, #description#)
</ insert >
< insert id = ”insertProduct” parameterClass = ”com.domain.Product” >
    insert into PRODUCT (PRD_ID, PRD_DESCRIPTION)
    values (#id:NUMERIC:-999999#, #description:VARCHAR:NO_ENTRY#)
</ insert >
语法
#propertyName# - OR -
#propertyName:jdbcType# - OR -
#propertyName:jdbcType:nullValue#
高级语法
#propertyName,javaType=?,jdbcType=?,mode=?,nullValue=?,handler=?,numericScale=?#
<procedure id= callProcedure parameterClass= com.mydomain.MyParameter >
{call MyProcedure
(#parm1,jdbcType=INTEGER,mode=IN#, #parm2,jdbcType=INTEGER,mode=IN#,
#parm3,jdbcType=DECIMAL,mode=OUT,numericScale=2#)}
</procedure>

你可能感兴趣的:(sql,ibatis)