1. 程式人生 > >常用標籤與屬性

常用標籤與屬性

resultMap標籤  desc:使返回結果與vo類對應,可以用於接收物件集合與單個物件
<resultMap id="demoClass" type="cn.bohely.dolphin.domain.pack.DemoClass">
<result property="id" column="ID"/>
<result property="屬性" column="欄位"/>
</resultMap>
<select id="queryPackStockByCombIdAndStartEndDate" resultMap="demoClass"
>
  select...
</select>

sql標籤    desc:用與引入sql程式碼塊,一般用於展示所需要的欄位,體現複用性
<sql id="idName">id,name,age</sql>
呼叫:<include refid="idName"/>
if標籤與CONCAT使用    desc:if用於動態植入sql條件或要更新的內容,CONCAT用於連線字串,否則非法-> %#{name}% 
<if test="property != null">content</if>
<if test="name !=null">
and NAME like CONCAT
('%',#{name},'%')
</if>
set標籤使用  desc:用於更新中,set標記會把最後一個逗號給去掉。
<set>
UPDATE_TIME = now(),
<if test="status != null">STATUS = #{status,jdbcType=VARCHAR},</if>
</set>
foreach標籤使用      desc:用於動態植入多個值(集合)到sql語句中,常用在巢狀查詢in後
<resultMap id="combStrategyMap" type="cn.bohely.dolphin.domain.pack.PackCombStrategy">
<result property="combId" column="COMB_ID"/>
<result property="strategyId" column="STRATEGY_ID"/>
<association
property="strategy" column="STRATEGY_ID" select="getStrategyById" />

</resultMap>
<select id="queryCombStrategyByCombId" resultMap="combStrategyMap">
select
COMB_ID,
STRATEGY_ID
from D_PACK_COMB_STRATEGY
where COMB_ID in
<foreach collection="list" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</select>
<select id="getStrategyById" resultMap="strategyMap">
select * from D_STRATEGY where ID = #{strategyId} and STATUS = 'ON'
</select>
parameterType屬性   desc:用於指明傳入的物件引數
<update id="updateStraStatus" parameterType="cn.bohely.dolphin.domain.strategy.Strategy">
UPDATE D_STRATEGY
<set>
UPDATE_TIME = now(),
<if test="status != null">STATUS = #{status,jdbcType=VARCHAR},</if>
</set>
WHERE ID = #{id}
</update>
注意:一般新增和更新指明引數型別
STATUS = #{status,jdbcType=VARCHAR}