DimOemtagMapper.xml
1.直接返回一个值,
<select id="getMaxOemTagId" resultType="java.lang.Integer">
select max(oemtag_id) from DIM_OEMTAG</select>
2.返回一个字段和返回全部字段都一个写法
<mapper namespace="com.feinno.fdc.report.report.persistence.mapper.tag.DimOemtagMapper" >
<resultMap id="BaseResultMap" type="com.feinno.fdc.report.report.module.tag.DimOemtag" >
<id column="OEMTAG" property="oemtag" jdbcType="VARCHAR" />
<id column="CLIENT_TYPE_ID" property="clientTypeId" jdbcType="INTEGER" />
<result column="OEMTAG_ID" property="oemtagId" jdbcType="INTEGER" />
<result column="OEMTAG_NAME" property="oemtagName" jdbcType="VARCHAR" />
<result column="TAG_FLAG" property="tagFlag" jdbcType="INTEGER" />
<result column="TAG_FLAG_NAME" property="tagFlagName" jdbcType="VARCHAR" />
<result column="OEMTAG_PARENT_ID" property="oemtagParentId" jdbcType="INTEGER" />
<result column="OEMTAG_PARENT_NAME" property="oemtagParentName" jdbcType="VARCHAR" />
<result column="BD" property="bd" jdbcType="VARCHAR" />
<result column="EFF_DATE" property="effDate" jdbcType="TIMESTAMP" />
<result column="EXP_DATE" property="expDate" jdbcType="TIMESTAMP" />
<result column="UPD_DATE" property="updDate" jdbcType="TIMESTAMP" />
</resultMap>
<select id="getTagSuggestionByParentName"resultMap="BaseResultMap">
select distinct(OEMTAG_PARENT_NAME) from DIM_OEMTAG
<if test="oemTagParentName!= null" >
where OEMTAG_PARENT_NAME like ${oemTagParentName}
</if>
<if test="number!= null" >
limit ${number};
</if>
</select>
<select id="getTagSuggestionByOemTag" resultMap="BaseResultMap">
select * from DIM_OEMTAG
<if test="oemTag!= null" >
where OEMTAG like ${oemTag}
</if>
<if test="number!= null" >
limit ${number};
</if>
</select>
3.对于sql语句里面有大于小于号之类的特殊符号,需要用<![CDATA[ xxxxxx ]]>来解决,否则编译就通不过,
<select id="getLastweek" resultType="java.lang.String">
<![CDATA[
SELECT MAX(TIME_ID)
FROM D_TIME
WHERE TIME_TYPE= 4 AND
TIME_ID <
(select TIME_ID
from D_TIME
WHERE TIME_TYPE= 4 AND START_TIME < CURRENT_TIMESTAMP AND END_TIME > CURRENT_TIMESTAMP);
]]>
</select>