oracle增删改查

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN"     
 "http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd">

<mapper namespace="org.tedu.cloudnote.dao.UserDao">

<!-- 增:插入语句参数类型, id, parameterType是实体类--> 

<insert   id="save"

     parameterType="org.tedu.cloudnote.entity.User">

     insert into cn_user   (cn_user_id,cn_user_name, cn_user_password,cn_user_token,   cn_user_nick)  

           values (#{cn_user_id},#{cn_user_name},   #{cn_user_password},#{cn_user_token}, #{cn_user_nick})  

</insert>

 

<!--删: 只有id-->

<delete id="dynamicDeleteNotes">
      delete from cn_note
      where cn_note_id in
      <foreach collection="array" item="id"
        separator="," open="(" close=")">
         #{id}
      </foreach>
</delete>

 

 

<!--改 :-->

  <update id="updateStatus" parameterType="map">
    update cn_note
    set cn_note_status_id=#{statusId}
    where cn_note_id=#{noteId}
  </update>

<update id="dynamicUpdateNote"
      parameterType="org.tedu.cloudnote.entity.Note">
    update cn_note
  <set>
    <if test="cn_notebook_id!=null">
    cn_notebook_id=#{cn_notebook_id},
    </if>
    <if test="cn_note_status_id!=null">
    cn_note_status_id=#{cn_note_status_id},
    </if>

   </set>
       where cn_note_id=#{cn_note_id}
</update>

<!-- 查:select语句参数类型 parameterType 是基本数据类型 ,resultType是实体类--> 

 <select id="findByName"

    parameterType="string" 

     resultType="org.tedu.cloudnote.entity.User">

 select * from cn_user  where cn_user_name=#{name}  

</select>

例句:2
<select id="dynamicFindNotes"
     parameterType="map"
    resultType="org.tedu.cloudnote.entity.Note">
      select * from cn_note
  <where>
  <if test="title!=null">
     cn_note_title like #{title}
  </if>
  <if test="status!=null">
      and  cn_note_status_id=#{status}
  </if>
  <if test="beginDate!=null">
      and cn_note_create_time>#{beginDate}
  </if>
  <choose>
   <when test="endDate!=null">
     and cn_note_create_time&lt;#{endDate}
   </when>
   <otherwise>
      <if test="beginDate!=null">
      and cn_note_create_time&lt;#{beginDate}+3*24*3600*1000
      </if>
   </otherwise>
  </choose>
<!--
<if test="endDate!=null">
  and cn_note_create_time&lt;#{endDate}
</if>
 -->
</where>
</select>

 

</mapper>

==========dao :public List<Note> dynamicFindNotes(Map params);

 =========service

 public NoteResult loadSearchNotes( SearchNoteParams params) {

 Map<String,Object> mapParams =
   new HashMap<String, Object>();

if(!"".equals(params.getEndDate())
   && params.getEndDate() != null){
   Date end = Date.valueOf(
    params.getEndDate());
   mapParams.put("endDate", end.getTime());
  }

  //执行查询
  List<Note> list =
   dynamicDao.dynamicFindNotes(mapParams);
  NoteResult result = new NoteResult();
  result.setStatus(0);
  result.setMsg("搜索成功");
  result.setData(list);
  return result;
 } 

}

 

=======================批量删除,只留前十条数据。

delete from THIRD_PARTY_MERCHANT a where a.rowid in
(
select rowid from THIRD_PARTY_MERCHANT
minus
select rowid from THIRD_PARTY_MERCHANT where rownum <10
)

 

==============================================

<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > <mapper namespace="com.eaju.dao.ReceiveMerchantOrderDao"> <!-- 美标电视购物订单接入 -->    <insert id="insertMerchantOrderDao" parameterType="com.eaju.po.ReceiveMerchantOrderBean">         INSERT INTO THIRD_PARTY_MERCHANT(      id,     business_key,     merchant_type,     text_content,    operate_status,   create_time,   creator,   modify_time,   modifier,   yn,  order_type         )         VALUES(   THIRD_PARTY_MERCHANT_SEQUENCE.nextval,   #{businessKey},  #{merchantType},  #{textContent},  #{operateStatus},  sysdate,  #{creator},  sysdate,  #{modifier},  0,  #{orderType}         )    </insert>

posted @ 2016-11-21 14:14  21heshang  阅读(185)  评论(0编辑  收藏  举报