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}