最近用到blob类型的字段,在网上看了看,大部分都没成功。自己试验些时间,整理个可以运行的,以便将来用的时候不用在到网上搜来搜去的了!
闲话少说,只将关键代码贴出来
1.表
create table TBL_SYS_BULLIT (
TPI_ID VARCHAR2(10) not null,
TPI_TITLE VARCHAR2(200) not null,
TPI_CONTENT_URL BLOB )
2.实体BulletinVo.java
public class BulletinVo {
private String tpiId;
private String tpiTitle;
private byte[] tpiContentUrl;
public BulletinVo() {
}
public String getTpiId() {
return tpiId;
}
public void setTpiId(String tpiId) {
this.tpiId = tpiId;
}
public String getTpiTitle() {
return tpiTitle;
}
public void setTpiTitle(String tpiTitle) {
this.tpiTitle = tpiTitle;
}
public byte[] getTpiContentUrl() {
return tpiContentUrl;
}
public void setTpiContentUrl(byte[] tpiContentUrl) {
this.tpiContentUrl = tpiContentUrl;
}
}
3.sqlMapConfig.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMapConfig
PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
<sqlMapConfig>
<!-- 使用命名空间 用于区分重名问题 -->
<settings useStatementNamespaces="true" />
typeHandler jdbcType="BLOB" javaType="[B"
callback="org.springframework.orm.ibatis.support.BlobByteArrayTypeHandler" />
<typeHandler jdbcType="CLOB" javaType="java.lang.String"
callback="org.springframework.orm.ibatis.support.ClobStringTypeHandler" />
</sqlMapConfig>
4.applicationContext-dao.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<!-- Transaction manager -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- LobHandler for Oracle JDBC drivers -->
<!-- (refers to the NativeJdbcExtractor above to get access to native OracleConnections) -->
<bean id="nativeJdbcExtractor" class="org.springframework.jdbc.support.nativejdbc.C3P0NativeJdbcExtractor"
lazy-init="true" />
<bean id="oracleLobHandler" class="org.springframework.jdbc.support.lob.OracleLobHandler" lazy-init="true">
<property name="nativeJdbcExtractor">
<ref local="nativeJdbcExtractor" />
</property>
</bean>
<!-- Spring提供的iBatis的SqlMap配置-->
<bean id="sqlMapClient"
class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation" value="classpath:sqlMapConfig.xml"/>
<property name="dataSource" ref="dataSource"/>
[color=red]<property name="lobHandler">
<ref local="oracleLobHandler" />
</property>
</bean>
</beans>
5.bulletin.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap
PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="sysBullit">
<typeAlias alias="BulletinVo" type="包名.BulletinVo" />
<typeAlias alias="iCriteria" type="包名.IbatisCeteria" />
<select id="selectBulletin" parameterClass="iCriteria" resultClass="BulletinVo">
select
SysBullit.TPI_ID as tpiId,
SysBullit.TPI_TITLE as tpiTitle,
SysBullit.TPI_CONTENT_URL as tpiContentUrl
from TBL_SYS_BULLIT SysBullit
where 1=1
</select>
<update id="updateBulletin" parameterClass="BulletinVo">
update TBL_SYS_BULLIT
set
<isNotNull property="tpiId" prepend=",">TPI_ID = #tpiId# </isNotNull>
<isNotNull property="tpiTitle" prepend=",">TPI_TITLE = #tpiTitle# </isNotNull>
<isNotNull property="tpiContentUrl" prepend=",">TPI_CONTENT_URL = #tpiContentUrl:BLOB# </isNotNull>
where TBL_SYS_BULLIT.TPI_ID = #tpiId#
</update>
<insert id="insertBulletin" parameterClass="BulletinVo">
insert into TBL_SYS_BULLIT (
<isNotNull property="tpiId" prepend=",">TPI_ID</isNotNull>
<isNotNull property="tpiTitle" prepend=",">TPI_TITLE</isNotNull>
<isNotNull property="tpiContentUrl" prepend=",">TPI_CONTENT_URL </isNotNull>
)
values (
<isNotNull property="tpiId" prepend=",">#tpiId#</isNotNull>
<isNotNull property="tpiTitle" prepend=",">#tpiTitle#</isNotNull>
<isNotNull property="tpiApprDate" prepend=",">#tpiApprDate#</isNotNull>
<isNotNull property="tpiContentUrl" prepend=",">#tpiContentUrl:BLOB# </isNotNull>
)
</insert>
</sqlMap>
分享到:
相关推荐
框架包 由于一次上传要小于15M 所以只能上传两次......
简单易入手,使用mysql数据库进行数据管理
oracle ibatis 配置
ibatis spring springmvc 整合 integrate
ibatis spring struts1.2整合demo
spring ibatis 配置spring ibatis 配置spring ibatis 配置spring ibatis 配置
spring mvc+ibatis+oracle单表增删改(包都有)
最近想在最新的Spring5.0中集成ibatis(不是mybatis),发现已经不在支持SqlmapClientTemplate和SqlmapClientFactoryBean,于是搞了这个工具jar来进行支持如下配置 <bean id="sqlMapClient" class="org.spring...
axis2 ibatis spring简单资料
Struts2 ibatis Spring
ibatis与spring 框架整合
iBatis和Spring整合 iBatis和Spring整合
struts2 ibatis spring 实例,里面包含框架所有的jar包,以及权限管理的例子,可以供初学者参考
Spring与iBATIS的集成 iBATIS似乎已远离众说纷纭的OR框架之列,通常人们对非常流行的Hibernate情有独钟。但正如Spring A Developer's Notebook作者Bruce Tate 和Justin Gehtland所说的那样,与其他的OR框架相比...
这是一个三个框架的整合案例 完整的实例 虽然简单 但很实用
spring+ibatis+oracle分页缓存源码
ibatis spring dao spring ibatis集成
struts2 ibatis spring 集成开发
maven spring struts ibatis oracle框架整合,