mybatis中的一些记录

10 篇文章 0 订阅
2 篇文章 0 订阅

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>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值