ibatis存取clob字段解决方案

本解决方案适用于以webwork+ibatis+spring基础架构的系统中

    首先定义要持久化的类

 

public class WeeklyWork extends WeeklyWorkModel {

	/**
	 * 上周工作情况
	 */
	public String workLastWeek;

	/**
	 * 下周工作计划
	 */
	public String workNextWeek;

	/**
	 * 需要的支撑
	 */
	public String needSupport;
	
	public String getNeedSupport() {
		return needSupport;
	}
	public void setNeedSupport(String needSupport) {
		this.needSupport = needSupport;
	}
	public String getWorkLastWeek() {
		return workLastWeek;
	}
	public void setWorkLastWeek(String workLastWeek) {
		this.workLastWeek = workLastWeek;
	}
	public String getWorkNextWeek() {
		return workNextWeek;
	}
	public void setWorkNextWeek(String workNextWeek) {
		this.workNextWeek = workNextWeek;
	}
}

 其中workLastWeek,workNextWeek和needSupport在数据库中与之对应的字段B1,B2,B3均为clob类型,

 

然后再ibatis的映射文件中定义要持久化类的返回类型的映射

 

 

<typeAlias alias="WeeklyWork" type="com.broadtext.extend.jdfgs.weeklywork.domain.WeeklyWork"/>
	
	<resultMap class="WeeklyWork" id="WeeklyWorkResult">
	    <result column="B1" property="workLastWeek" jdbcType="CLOB"/>
	    <result column="B2" property="workNextWeek" jdbcType="CLOB"/>
	    <result column="B3" property="needSupport" jdbcType="CLOB"/>
	</resultMap>

 接下来想只要写好存取的SQL就大功告成了

 

<insert id="insertWeeklyWork" parameterClass="com.broadtext.extend.jdfgs.weeklywork.domain.WeeklyWork">
	 	insert into $tableName$(
	 		B1,

			B2,

			B3
	 	)values(	 		
	 		
	 		<isNotNull property="workLastWeek">
				#workLastWeek,javaType=java.lang.String,jdbcType=CLOB#,
			</isNotNull>
			<isNull property="workLastWeek">null,</isNull>
	 		
	 		<isNotNull property="workNextWeek">
				#workNextWeek,javaType=java.lang.String,jdbcType=CLOB#,
			</isNotNull>
			<isNull property="workNextWeek">null,</isNull>

	 		<isNotNull property="needSupport">
				#needSupport,javaType=java.lang.String,jdbcType=CLOB#
			</isNotNull>
			<isNull property="needSupport">null</isNull>
	 	)
	 </insert>

	 <select id="findWeeklyWorkById" parameterClass="java.util.Map" resultMap="WeeklyWorkResult">
	 	select 
			B1  as  B1,
			B2  as  B2,
			B3  as  B3,			
		from $tableName$		
	 </select>

 后台的java代码跟正常的ibatis存取对象一样这里不再复述

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值