1。Spring配置
<?
xml version="1.0" encoding="ISO-8859-1"
?>
<! DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd" >
< beans >
< description > Dragon Framework </ description >
<!-- Message source -->
< bean id ="messageSource" class ="org.springframework.context.support.ResourceBundleMessageSource" >
< property name ="basenames" >
< list >
< value > webResources </ value >
< value > appResources </ value >
</ list >
</ property >
</ bean >
<!-- Data source // -->
<!-- Oracle -->
< bean id ="dataSource" class ="org.springframework.jndi.JndiObjectFactoryBean" >
< property name ="jndiName" value ="java:comp/env/jdbc/dragon" />
</ bean >
<!--
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName">
<value>oracle.jdbc.driver.OracleDriver</value>
</property>
<property name="url">
<value>jdbc:oracle:thin:@172.16.184.2:1521:oradb</value>
</property>
<property name="username">
<value>fushun</value>
</property>
<property name="password">
<value>111111</value>
</property>
</bean>
-->
<!-- Blob field hander for Oracle9i or Oracle10g -->
< bean id ="nativeJdbcExtractor" class ="org.springframework.jdbc.support.nativejdbc.CommonsDbcpNativeJdbcExtractor"
lazy-init ="true" />
< bean id ="lobHandler" class ="org.springframework.jdbc.support.lob.OracleLobHandler" lazy-init ="true" >
< property name ="nativeJdbcExtractor" ref ="nativeJdbcExtractor" />
</ bean >
<!-- Hibernate Session Factory -->
< bean id ="sessionFactory" class ="org.springframework.orm.hibernate3.LocalSessionFactoryBean" >
< property name ="dataSource" ref ="dataSource" />
< property name ="lobHandler" ref ="lobHandler" />
< property name ="mappingDirectoryLocations" >
< list >
< value > classpath:/com/longtop/po </ value >
</ list >
</ property >
< property name ="hibernateProperties" >
< props >
< prop key ="hibernate.dialect" > org.hibernate.dialect.OracleDialect </ prop >
< prop key ="hibernate.show_sql" > true </ prop >
< prop key ="hibernate.cglib.use_reflection_optimizer" > true </ prop >
</ props >
</ property >
</ bean >
<!-- IBatis Sql Map Client Factory -->
< bean id ="sqlMapClient" class ="org.springframework.orm.ibatis.SqlMapClientFactoryBean" >
< property name ="configLocation" value ="WEB-INF/sql-map-config.xml" />
< property name ="dataSource" ref ="dataSource" />
</ bean >
< bean id ="jdbcTemplate" class ="org.springframework.jdbc.core.JdbcTemplate" >
< property name ="dataSource" ref ="dataSource" ></ property >
</ bean >
< bean id ="sqlMapClientTemplate" class ="org.springframework.orm.ibatis.SqlMapClientTemplate" >
< property name ="sqlMapClient" ref ="sqlMapClient" ></ property >
</ bean >
< bean id ="hibernateTemplate" class ="org.springframework.orm.hibernate3.HibernateTemplate" >
< property name ="sessionFactory" ref ="sessionFactory" />
</ bean >
<!-- Hibernate Transaction manager -->
< bean id ="hibernateTransactionManager" class ="org.springframework.orm.hibernate3.HibernateTransactionManager" >
< property name ="sessionFactory" ref ="sessionFactory" />
</ bean >
< bean id ="jdbcTransactionManager" class ="org.springframework.jdbc.datasource.DataSourceTransactionManager" >
< property name ="dataSource" ref ="dataSource" />
</ bean >
</ beans >
<! DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd" >
< beans >
< description > Dragon Framework </ description >
<!-- Message source -->
< bean id ="messageSource" class ="org.springframework.context.support.ResourceBundleMessageSource" >
< property name ="basenames" >
< list >
< value > webResources </ value >
< value > appResources </ value >
</ list >
</ property >
</ bean >
<!-- Data source // -->
<!-- Oracle -->
< bean id ="dataSource" class ="org.springframework.jndi.JndiObjectFactoryBean" >
< property name ="jndiName" value ="java:comp/env/jdbc/dragon" />
</ bean >
<!--
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName">
<value>oracle.jdbc.driver.OracleDriver</value>
</property>
<property name="url">
<value>jdbc:oracle:thin:@172.16.184.2:1521:oradb</value>
</property>
<property name="username">
<value>fushun</value>
</property>
<property name="password">
<value>111111</value>
</property>
</bean>
-->
<!-- Blob field hander for Oracle9i or Oracle10g -->
< bean id ="nativeJdbcExtractor" class ="org.springframework.jdbc.support.nativejdbc.CommonsDbcpNativeJdbcExtractor"
lazy-init ="true" />
< bean id ="lobHandler" class ="org.springframework.jdbc.support.lob.OracleLobHandler" lazy-init ="true" >
< property name ="nativeJdbcExtractor" ref ="nativeJdbcExtractor" />
</ bean >
<!-- Hibernate Session Factory -->
< bean id ="sessionFactory" class ="org.springframework.orm.hibernate3.LocalSessionFactoryBean" >
< property name ="dataSource" ref ="dataSource" />
< property name ="lobHandler" ref ="lobHandler" />
< property name ="mappingDirectoryLocations" >
< list >
< value > classpath:/com/longtop/po </ value >
</ list >
</ property >
< property name ="hibernateProperties" >
< props >
< prop key ="hibernate.dialect" > org.hibernate.dialect.OracleDialect </ prop >
< prop key ="hibernate.show_sql" > true </ prop >
< prop key ="hibernate.cglib.use_reflection_optimizer" > true </ prop >
</ props >
</ property >
</ bean >
<!-- IBatis Sql Map Client Factory -->
< bean id ="sqlMapClient" class ="org.springframework.orm.ibatis.SqlMapClientFactoryBean" >
< property name ="configLocation" value ="WEB-INF/sql-map-config.xml" />
< property name ="dataSource" ref ="dataSource" />
</ bean >
< bean id ="jdbcTemplate" class ="org.springframework.jdbc.core.JdbcTemplate" >
< property name ="dataSource" ref ="dataSource" ></ property >
</ bean >
< bean id ="sqlMapClientTemplate" class ="org.springframework.orm.ibatis.SqlMapClientTemplate" >
< property name ="sqlMapClient" ref ="sqlMapClient" ></ property >
</ bean >
< bean id ="hibernateTemplate" class ="org.springframework.orm.hibernate3.HibernateTemplate" >
< property name ="sessionFactory" ref ="sessionFactory" />
</ bean >
<!-- Hibernate Transaction manager -->
< bean id ="hibernateTransactionManager" class ="org.springframework.orm.hibernate3.HibernateTransactionManager" >
< property name ="sessionFactory" ref ="sessionFactory" />
</ bean >
< bean id ="jdbcTransactionManager" class ="org.springframework.jdbc.datasource.DataSourceTransactionManager" >
< property name ="dataSource" ref ="dataSource" />
</ bean >
</ beans >
2。持久对象(PO)
持久对象中的BLOB对象类型为byte[]类型
3。获取页面传过来的文件
SysUserPO user
=
new
SysUserPO();
// 1.获取Flower对象
Flower flower = (Flower)SpringHelper.getBean( " flower " );
// 2.解析request
flower.parseRequest(request);
// 3.获取上传的文件
FlowerRequest flowerRequest = flower.getFlowerRequest();
ArrayList flowerFileList = flower.getFlowerFileList();
if (flowerFileList.size() > 0 ) ... {
//将数字签名文件射入user对象
for(Iterator iter = flowerFileList.iterator(); iter.hasNext();) ...{
FlowerFile file = (FlowerFile)iter.next();
if(!file.getName().equals(""))
...{
InputStream in = file.getInputStream();
byte[] data = new byte[in.available()];
in.read(data);
user.setEFileContent(data);
user.setEFileName(System.currentTimeMillis()+"."+file.getPostfix());
}
}
}
// 1.获取Flower对象
Flower flower = (Flower)SpringHelper.getBean( " flower " );
// 2.解析request
flower.parseRequest(request);
// 3.获取上传的文件
FlowerRequest flowerRequest = flower.getFlowerRequest();
ArrayList flowerFileList = flower.getFlowerFileList();
if (flowerFileList.size() > 0 ) ... {
//将数字签名文件射入user对象
for(Iterator iter = flowerFileList.iterator(); iter.hasNext();) ...{
FlowerFile file = (FlowerFile)iter.next();
if(!file.getName().equals(""))
...{
InputStream in = file.getInputStream();
byte[] data = new byte[in.available()];
in.read(data);
user.setEFileContent(data);
user.setEFileName(System.currentTimeMillis()+"."+file.getPostfix());
}
}
}
4。用service保存
public
void
saveUser(SysUserPO user)
...
{
hibernateTemplate.save(user);
hibernateTemplate.flush();
}
hibernateTemplate.save(user);
hibernateTemplate.flush();
}