mybatis oracle 批量插入返回主键

mybatis 单个和批量插入MySQLOracle配置说明

1. mysql

[html]  view plain  copy
  1. <?xml version="1.0" encoding="UTF-8" ?>  
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">  
  3. <mapper namespace="cn.mysql.Mapper.BlackListMapper">  
  4.   
  5.     <resultMap id="BlackListMap"  
  6.         type="cn.mysql.entity.BlackListDO">  
  7.         <result property="id" column="id" />  
  8.         <result property="uuid" column="uuid" />  
  9.         <result property="type" column="tupe" />  
  10.         <result property="value" column="value" />  
  11.         <result property="deleteFlag" column="delete_flag" />  
  12.         <result property="gmtCreate" column="gmt_create" />  
  13.         <result property="gmtModified" column="gmt_modified" />  
  14.     </resultMap>  
  15.   
  16.     <insert id="insert" parameterType="cn.mysql.entity.BlackListDO">  
  17.         insert into  
  18.         black_list(uuid,type,value,delete_flag,gmt_create,gmt_modified)  
  19.         values  
  20.         (#{uuid:VARCHAR},#{type:VARCHAR},#{value:VARCHAR},  
  21.         #{deleteFlag:INTEGER},#{gmtCreate:DATE},#{gmtModified:DATE})  
  22.     </insert>  
  23.   
  24.     <insert id="insertBatch" parameterType="List">  
  25.         insert into black_list  
  26.         (uuid,type,value,delete_flag,gmt_create,gmt_modified) values  
  27.         <foreach collection="list" item="item" index="index"  
  28.             separator=",">  
  29.             (#{item.uuid},#{item.type},#{item.value}  
  30.             #{item.deleteFlag},#{item.gmtCreate},#{item.gmtModified})  
  31.         </foreach>  
  32.     </insert>  
  33.   
  34. </mapper>  

2. oracle

[html]  view plain  copy
  1. <?xml version="1.0" encoding="UTF-8" ?>  
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">  
  3. <mapper namespace="cn.oracle.Mapper.BlackListMapper">  
  4.   
  5.     <resultMap id="BlackListMap"  
  6.         type="cn.oracle.entity.BlackListDO">  
  7.         <result property="id" column="id" />  
  8.         <result property="uuid" column="uuid" />  
  9.         <result property="type" column="tupe" />  
  10.         <result property="value" column="value" />  
  11.         <result property="deleteFlag" column="delete_flag" />  
  12.         <result property="gmtCreate" column="gmt_create" />  
  13.         <result property="gmtModified" column="gmt_modified" />  
  14.     </resultMap>  
  15.   
  16.     <insert id="insert" parameterType="cn.oracle.entity.BlackListDO">  
  17.         <selectKey resultType="Long" order="BEFORE" keyProperty="id">  
  18.             select seq_black_list.nextval from dual  
  19.         </selectKey>  
  20.         insert into  
  21.         black_list(id,uuid,type,value,delete_flag,gmt_create,gmt_modified)  
  22.         values  
  23.         (#{id:DECIMAL},#{uuid:VARCHAR},#{type:VARCHAR},#{value:VARCHAR},  
  24.         #{deleteFlag:INTEGER},#{gmtCreate:DATE},#{gmtModified:DATE})  
  25.     </insert>  
  26.   
  27.     <insert id="insertBatch">  
  28.         <selectKey keyProperty="id" resultType="Long" order="BEFORE">  
  29.             select seq_black_list.nextval as id from dual  
  30.         </selectKey>  
  31.         insert into black_list  
  32.         (id,uuid,type,value,delete_flag,gmt_create,gmt_modified)  
  33.         select seq_black_list.nextval, A.* FROM (  
  34.         <foreach collection="list" item="item" index="index"  
  35.             separator="union all">  
  36.             select  
  37.             #{item.uuid,jdbcType=VARCHAR},  
  38.             #{item.type,jdbcType=VARCHAR},  
  39.             #{item.value,jdbcType=VARCHAR},  
  40.             #{item.deleteFlag,jdbcType=INTEGER},  
  41.             #{item.gmtCreate,jdbcType=DATE},  
  42.             #{item.gmtModified,jdbcType=DATE}  
  43.             from  
  44.             dual  
  45.         </foreach>  
  46.         ) A  
  47.     </insert>  
  48.   
  49. </mapper>  

模糊匹配查询

[html]  view plain  copy
  1. <select id="queryByParams" resultMap="ResultMap" parameterType="Map">  
  2.     select * from table_name  
  3.     <where>  
  4.         <if test="description!= null">  
  5.            AND description like CONCAT(CONCAT('%', #{description}), '%')   
  6.         </if>  
  7.     </where>  
  8. </select>  

猜你喜欢

转载自blog.csdn.net/sdzhangshulong/article/details/75370838
今日推荐