mybatis怎么同时读mysql和oracle
1个回答
2016-09-05 · 知道合伙人软件行家
关注
展开全部
mybatis 单个和批量插入mysql与oracle配置说明
1. mysql
[html] view plain copy
<?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="cn.mysql.Mapper.BlackListMapper">
<resultMap id="BlackListMap"
type="cn.mysql.entity.BlackListDO">
<result property="id" column="id" />
<result property="uuid" column="uuid" />
<result property="type" column="tupe" />
<result property="value" column="value" />
<result property="deleteFlag" column="delete_flag" />
<result property="gmtCreate" column="gmt_create" />
<result property="gmtModified" column="gmt_modified" />
</resultMap>
<insert id="insert" parameterType="cn.mysql.entity.BlackListDO">
insert into
black_list(uuid,type,value,delete_flag,gmt_create,gmt_modified)
values
(#{uuid:VARCHAR},#{type:VARCHAR},#{value:VARCHAR},
#{deleteFlag:INTEGER},#{gmtCreate:DATE},#{gmtModified:DATE})
</insert>
<insert id="insertBatch" parameterType="List">
insert into black_list
(uuid,type,value,delete_flag,gmt_create,gmt_modified) values
<foreach collection="list" item="item" index="index"
separator=",">
(#{item.uuid},#{item.type},#{item.value}
#{item.deleteFlag},#{item.gmtCreate},#{item.gmtModified})
</foreach>
</insert>
</mapper>
2. oracle
[html] view plain copy
<?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="cn.oracle.Mapper.BlackListMapper">
<resultMap id="BlackListMap"
type="cn.oracle.entity.BlackListDO">
<result property="id" column="id" />
<result property="uuid" column="uuid" />
<result property="type" column="tupe" />
<result property="value" column="value" />
<result property="deleteFlag" column="delete_flag" />
<result property="gmtCreate" column="gmt_create" />
<result property="gmtModified" column="gmt_modified" />
</resultMap>
<insert id="insert" parameterType="cn.oracle.entity.BlackListDO">
<selectKey resultType="Long" order="BEFORE" keyProperty="id">
select seq_black_list.nextval from dual
</selectKey>
insert into
black_list(id,uuid,type,value,delete_flag,gmt_create,gmt_modified)
values
(#{id:DECIMAL},#{uuid:VARCHAR},#{type:VARCHAR},#{value:VARCHAR},
#{deleteFlag:INTEGER},#{gmtCreate:DATE},#{gmtModified:DATE})
</insert>
<insert id="insertBatch">
<selectKey keyProperty="id" resultType="Long" order="BEFORE">
select seq_black_list.nextval as id from dual
</selectKey>
insert into black_list
(id,uuid,type,value,delete_flag,gmt_create,gmt_modified)
select seq_black_list.nextval, A.* FROM (
<foreach collection="list" item="item" index="index"
separator="union all">
select
#{item.uuid,jdbcType=VARCHAR},
#{item.type,jdbcType=VARCHAR},
#{item.value,jdbcType=VARCHAR},
#{item.deleteFlag,jdbcType=INTEGER},
#{item.gmtCreate,jdbcType=DATE},
#{item.gmtModified,jdbcType=DATE}
from
dual
</foreach>
) A
</insert>
</mapper>
模糊匹配查询
[html] view plain copy
<select id="queryByParams" resultMap="ResultMap" parameterType="Map">
select * from table_name
<where>
<if test="description!= null">
AND description like CONCAT(CONCAT('%', #{description}), '%')
</if>
</where>
</select>
1. mysql
[html] view plain copy
<?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="cn.mysql.Mapper.BlackListMapper">
<resultMap id="BlackListMap"
type="cn.mysql.entity.BlackListDO">
<result property="id" column="id" />
<result property="uuid" column="uuid" />
<result property="type" column="tupe" />
<result property="value" column="value" />
<result property="deleteFlag" column="delete_flag" />
<result property="gmtCreate" column="gmt_create" />
<result property="gmtModified" column="gmt_modified" />
</resultMap>
<insert id="insert" parameterType="cn.mysql.entity.BlackListDO">
insert into
black_list(uuid,type,value,delete_flag,gmt_create,gmt_modified)
values
(#{uuid:VARCHAR},#{type:VARCHAR},#{value:VARCHAR},
#{deleteFlag:INTEGER},#{gmtCreate:DATE},#{gmtModified:DATE})
</insert>
<insert id="insertBatch" parameterType="List">
insert into black_list
(uuid,type,value,delete_flag,gmt_create,gmt_modified) values
<foreach collection="list" item="item" index="index"
separator=",">
(#{item.uuid},#{item.type},#{item.value}
#{item.deleteFlag},#{item.gmtCreate},#{item.gmtModified})
</foreach>
</insert>
</mapper>
2. oracle
[html] view plain copy
<?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="cn.oracle.Mapper.BlackListMapper">
<resultMap id="BlackListMap"
type="cn.oracle.entity.BlackListDO">
<result property="id" column="id" />
<result property="uuid" column="uuid" />
<result property="type" column="tupe" />
<result property="value" column="value" />
<result property="deleteFlag" column="delete_flag" />
<result property="gmtCreate" column="gmt_create" />
<result property="gmtModified" column="gmt_modified" />
</resultMap>
<insert id="insert" parameterType="cn.oracle.entity.BlackListDO">
<selectKey resultType="Long" order="BEFORE" keyProperty="id">
select seq_black_list.nextval from dual
</selectKey>
insert into
black_list(id,uuid,type,value,delete_flag,gmt_create,gmt_modified)
values
(#{id:DECIMAL},#{uuid:VARCHAR},#{type:VARCHAR},#{value:VARCHAR},
#{deleteFlag:INTEGER},#{gmtCreate:DATE},#{gmtModified:DATE})
</insert>
<insert id="insertBatch">
<selectKey keyProperty="id" resultType="Long" order="BEFORE">
select seq_black_list.nextval as id from dual
</selectKey>
insert into black_list
(id,uuid,type,value,delete_flag,gmt_create,gmt_modified)
select seq_black_list.nextval, A.* FROM (
<foreach collection="list" item="item" index="index"
separator="union all">
select
#{item.uuid,jdbcType=VARCHAR},
#{item.type,jdbcType=VARCHAR},
#{item.value,jdbcType=VARCHAR},
#{item.deleteFlag,jdbcType=INTEGER},
#{item.gmtCreate,jdbcType=DATE},
#{item.gmtModified,jdbcType=DATE}
from
dual
</foreach>
) A
</insert>
</mapper>
模糊匹配查询
[html] view plain copy
<select id="queryByParams" resultMap="ResultMap" parameterType="Map">
select * from table_name
<where>
<if test="description!= null">
AND description like CONCAT(CONCAT('%', #{description}), '%')
</if>
</where>
</select>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询