mybatis保存CLOB类型到oracle数据库实例

https://blog.csdn.net/zengdeqing2012/article/details/78864922

<?xml version="1.0" encoding="UTF-8"?>
mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.wlw.mgt.dao.WmsInPoolMapper">
  <resultMap id="BaseResultMap" type="cn.wlw.mgt.entity.WmsInPool">
    <id column="POOL_PK_NO" jdbcType="DECIMAL" property="poolPkNo" />
    <result column="BIG_DATA" property="bigData" jdbcType="CLOB" javaType = "java.lang.String"/>
    <result column="CREATE_TIME" jdbcType="TIMESTAMP" property="createTime" />
    <result column="UPDATE_TIME" jdbcType="TIMESTAMP" property="updateTime" />
  </resultMap>

  <sql id="Base_Column_List">
    POOL_PK_NO,BIG_DATA,CREATE_TIME,UPDATE_TIME
  </sql>

  <select id="selectByPrimaryKey" parameterType="java.math.BigDecimal" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from WMS_IN_POOL
    where POOL_PK_NO = #{poolPkNo,jdbcType=DECIMAL}
  </select>

  <delete id="deleteByPrimaryKey" parameterType="java.math.BigDecimal">
    delete from WMS_IN_POOL
    where POOL_PK_NO = #{poolPkNo,jdbcType=DECIMAL}
  </delete>

  <insert id="insert" parameterType="cn.wlw.mgt.entity.WmsInPool">
    <selectKey resultType="Decimal" keyProperty="poolPkNo" order="BEFORE">
        SELECT nvl(max(POOL_PK_NO),0)+1 from WMS_IN_POOL
    </selectKey>
    insert into WMS_IN_POOL (POOL_PK_NO,BIG_DATA,CREATE_TIME,UPDATE_TIME)
    values (
      #{poolPkNo,jdbcType=DECIMAL},#{bigData,jdbcType=CLOB},  
      #{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP}
    )
  </insert>

  <insert id="insertSelective" parameterType="cn.wlw.mgt.entity.WmsInPool">
    insert into WMS_IN_POOL
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="poolPkNo != null">
        POOL_PK_NO,
      </if>
      <if test="bigData != null">
        BIG_DATA,
      </if>
      <if test="createTime != null">
        CREATE_TIME,
      </if>
      <if test="updateTime != null">
        UPDATE_TIME,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="poolPkNo != null">
        #{poolPkNo,jdbcType=DECIMAL},
      </if>
      <if test="bigData != null">
        #{bigData,jdbcType=CLOB},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateTime != null">
        #{updateTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>

  <update id="updateByPrimaryKeySelective" parameterType="cn.wlw.mgt.entity.WmsInPool">
    update WMS_IN_POOL
    <set>
      <if test="bigData != null">
        BIG_DATA = #{bigData,jdbcType=CLOB},
      </if>
      <if test="createDate != null">
        UPDATE_TIME = #{updateTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where POOL_PK_NO = #{poolPkNo,jdbcType=DECIMAL}
  </update>

  <update id="updateByPrimaryKey" parameterType="cn.wlw.mgt.entity.WmsInPool">
    update WMS_IN_POOL
    set BIG_DATA = #{bigDdata,jdbcType=CLOB},
      UPDATE_TIME = #{updateTime,jdbcType=TIMESTAMP}
    where POOL_PK_NO = #{poolPkNo,jdbcType=DECIMAL}
  </update>

  <insert id="batchInsertWmsInPool" parameterType="cn.wlw.mgt.entity.WmsInPool">
        insert into WMS_IN_POOL(
        POOL_PK_NO,BIG_DATA,CREATE_TIME,UPDATE_TIME) 
        select SEQ_POOL_PK_NO.NEXTVAL, A.* from(
        <foreach collection="wmsInPools" item="item" index="index" separator="UNION ALL">
            SELECT
            #{item.bigData,jdbcType=CLOB},
            #{item.createTime,jdbcType=TIMESTAMP},
            #{item.updateTime,jdbcType=TIMESTAMP} 
            from dual
        </foreach>
        ) A
  </insert>

</mapper>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
MyBatis是一种持久层框架,通过它可以将Java对象映射到数据库表中,从而实现数据的持久化。在MyBatis中,保存数据到数据库通常包括以下几个步骤: 1. 配置数据源:在MyBatis中,需要配置数据源,即数据库连接池,可以使用JDBC连接池或第三方数据源,比如Druid、Hikari等。 2. 编写Mapper接口:在MyBatis中,通常使用Mapper接口来定义对数据库的操作,需要编写Mapper接口及其对应的XML文件,包括SQL语句和参数映射等。 3. 创建SqlSession:在MyBatis中,需要创建SqlSession对象,用于执行SQL语句和管理事务等,可以通过SqlSessionFactory创建SqlSession。 4. 执行SQL语句:在MyBatis中,可以通过SqlSession执行SQL语句,包括插入、更新、删除和查询等操作。 5. 提交事务:在MyBatis中,需要手动提交事务,可以调用SqlSession的commit方法来提交事务,也可以在配置文件中设置自动提交事务。 具体保存数据到数据库的过程,可以通过以下示例代码进行说明: ``` // 1. 配置数据源 DataSource dataSource = ...; // 2. 编写Mapper接口 public interface UserMapper { void insertUser(User user); void updateUser(User user); void deleteUser(int id); } // 3. 创建SqlSession SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream); SqlSession sqlSession = sqlSessionFactory.openSession(); // 4. 执行SQL语句 UserMapper userMapper = sqlSession.getMapper(UserMapper.class); User user = new User(); user.setId(1); user.setName("Tom"); user.setAge(20); userMapper.insertUser(user); // 5. 提交事务 sqlSession.commit(); ``` 在上面的示例中,首先通过数据源配置了数据库连接池,然后定义了一个UserMapper接口,其中包括了插入、更新和删除等操作。接着创建了SqlSession对象,通过getMapper方法获取了UserMapper的实现类,并调用insertUser方法向数据库中插入了一条用户记录。最后通过commit方法提交事务。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值