eclipse+CDT+MinGW+wxWidgets开发c环境Word格式文档下载.docx
《eclipse+CDT+MinGW+wxWidgets开发c环境Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《eclipse+CDT+MinGW+wxWidgets开发c环境Word格式文档下载.docx(22页珍藏版)》请在冰豆网上搜索。
publicStringgetFileId(){
returnthis.fileId;
}
publicvoidsetFileId(Stringid){
this.fileId=id;
publicStringgetFileName(){
returnthis.fileName;
publicvoidsetFileName(Stringname){
this.fileName=name;
publicbyte[]getFileContent(){
returnthis.fileContent;
publicvoidsetFileContent(byte[]content){
this.fileContent=content;
publicStringgetRemark(){
returnthis.remark;
publicvoidsetRemark(Stringremark){
this.remark=remark;
}
说明:
fileContent定义为byte[]类型,对应于表t_file中Blob类型的file_content字段
2)映射文件File.hbm.xml
<
hibernate-mappingpackage="
hbm"
>
<
classname="
com.yqh.upload.domain.files.File"
table="
t_file"
<
comment>
Fileelements.<
/comment>
idname="
fileId"
column="
file_id"
type="
string"
<
generatorclass="
sequence"
<
paramname="
s_ssh_file_id<
/param>
/generator>
/id>
propertyname="
fileName"
file_name"
not-null="
true"
/>
fileContent"
file_content"
type="
org.springframework.orm.hibernate3.support.BlobByteArrayType"
lazy="
not-null="
remark"
/class>
/hibernate-mapping>
file_id是通过sequnce生成的,insert时该字段的值即s_ssh_file_id.nextval;
file_content定义为org.springframework.orm.hibernate3.support.BlobByteArrayType类型,BlobByteArrayType通过sessionFactory中定义的lobHandler实现byte[]到Blob的“转型”,lazy="
表示返回file对象时并不携带file_content(重量级数据)的数据,只有在显示file.getFileConten()时才返回其值
3)DAO(DataAccessor)
FileDAO.java
publicinterfaceFileDAO{
publicFilefindByFildId(StringfileId);
publicvoidsave(Filefile);
publicListfindAll();
FileDAOImpl.java
publicclassFileDAOImplextendsHibernateDaoSupportimplementsFileDAO{
publicFilefindByFildId(StringfileId){
return(File)getHibernateTemplate().get(File.class,fileId);
publicvoidsave(Filefile){
getHibernateTemplate().save(file);
getHibernateTemplate().flush();
publicListfindAll(){
returngetHibernateTemplate().loadAll(File.class);
HibernateDaoSupport封装了HibernateTemplate,而HibernateTemplate封装了Hibernate所提供几乎所有的的数据操作方法,如execute(HibernateCallbackaction),load(ClassentityClass,Serializableid),save(finalObjectentity)等
4)Spring配置文件applicationContext.xml
beans>
!
--**********数据库连接**********-->
beanid="
dataSource"
class="
mons.dbcp.BasicDataSource"
destroy-method="
close"
driverClassName"
value="
oracle.jdbc.driver.OracleDriver"
url"
jdbc:
oracle:
thin:
@localhost:
1521:
orcl"
username"
value="
mydb"
password"
/bean>
--**********Hibernate会话工厂配置**********-->
nativeJdbcExtractor"
org.springframework.jdbc.support.nativejdbc.CommonsDbcpNativeJdbcExtractor"
lazy-init="
lobHandler"
org.springframework.jdbc.support.lob.OracleLobHandler"
reflocal="
/property>
sessionFactory"
org.springframework.orm.hibernate3.LocalSessionFactoryBean"
ref="
--为处理Blob类型字段的句柄声明-->
mappingDirectoryLocations"
list>
value>
classpath:
/hbm<
/value>
/list>
hibernateProperties"
props>
propkey="
hibernate.dialect"
org.hibernate.dialect.OracleDialect
/prop>
show_sql"
true<
hibernate.cglib.use_reflection_optimizer"
true
/props>
--**********Hibernate模板**********-->
hibernateTemplate"
org.springframework.orm.hibernate3.HibernateTemplate"
--**********DAO配置**********-->
fileDAO"
com.yqh.upload.domain.files.dao.impl.FileDAOImpl"
--**********事务处理的AOP配置**********-->
transactionManager"
org.springframework.orm.hibernate3.HibernateTransactionManager"
proxyTemplate"
abstract="
org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
transactionAttributes"
get*"
PROPAGATION_REQUIRED,readOnly<
find*"
save"
PROPAGATION_REQUIRED<
write"
fileServiceProxy"
parent="
target"
bean
class="
com.yqh.upload.domain.files.service.impl.FileServiceImpl"
beanname="
/fileAction"
class="
com.yqh.upload.web.actions.FileAction"
singleton="
false"
fileService"
refbean="
/beans>
dataSource定义的是数据源,实现类为BasicDataSource;
sessionFactory定义hibernate的会话工厂,使用Spring的LocalSessionFactoryBean进行管理;
对oracle的Blob类型字段操作比较复杂,我们采用BlobByteArrayType类型通过LobHandler简化对其的操作,使Blob字段平民化,配置文件中定义的LobHandler即为Blob字段处理句柄,其属性nativeJdbcExtractor为可从本地提取jdbc对象的抽取器
2.业务层
1)业务层代码
FileService.java
publicinterfaceFileService{
publicvoidsave(FileFormfileForm);
//将表单中的数据保存到数据库
publicListgetAllFile();
//取t_file表中所有记录
publicvoidwrite(OutputStreamos,StringfileId);
//根据id取文件且输出
publicStringgetFileName(StringfileId);
//根据id取文件名
FileServiceImpl.java
publicclassFileServiceImplimplementsFileService{
privateFileDAOfileDAO;
publicvoidsave(FileFormfileForm){
Filefile=newFile();
try{
file.setFileContent(fileForm.getFileContent().getFileData());
}catch(FileNotFoundExceptionex){
thrownewRuntimeException(ex);
}catch(IOExceptionex){
}
file.setFileName(fileForm.getFileContent().getFileName());
file.setRemark(fileForm.getRemark());
fileDAO.save(file);
publicvoidwrite(OutputStreamos,StringfileId)
{
Filefile=fileDAO.findByFildId(fileId);
os.write(file.getFileContent());
os.flush();
thrownewRuntimeException(ex);
publicListgetAllFile(){
ListfileList=fileDAO.findAll();
returnfileList;
publicStringgetFileName(StringfileId){
StringfileName=file.getFileName();
returnfileName;
publicFileDAOgetFileDAO(){
returnfileDAO;
publicvoidsetFileDAO(FileDAOfileDAO){
this.fileDAO=fileDAO;
具体实现细节不罗嗦了,相信将你一看便知
2)Spring事务配置
class="
Spring的事物配置分两部分
a)事务管理器transactionManager,使用HibernateTransactionManager实现事务管理
b)定义业务接口,proxyTemplate和fileServiceProxy是父子关系,本来可以将proxyTemplate定义的内容合并到fileServiceProxy中,可是如果有很多业务接口需要定义这种写法就不使用了,proxyTemplate注入了事务管理器,还定义了业务接口事务管理的方法,有些方法仅对数据进行读操作,不涉及更改,于是定义为readOnly,这样做可以提高性能,proxyTemplate是子节点配置的抽象,并不能够实现一个bean对象,所以声明为abstract="
3.表示层
1)Struts-config.xml
struts-config>
--**********FormBeanDefinitions**********-->
form-beans>
form-beanname="
fileForm"
com.yqh.upload.web.forms.FileForm"
/form-beans>
--**********ActionMappingDefinitions**********-->
action-mappings>
actionpath="
/welcome"
forward="
/page/jsp/fileUpload.jsp"
org.springframework.web.struts.DelegatingActionProxy"
name="
parameter="
method"
forwardname="
fileList"
path="
/page/jsp/fileList.jsp"
listFiles"
path="
/fileAction.do?
method=listFiles"
/action>
/action-mappings>
plug-in
className="
org.springframework.web.struts.ContextLoaderPlugIn"
set-propertyproperty="
contextConfigLocation"
/WEB-INF/applicationContext.xml"
/plug-in>
/struts-config>
Struts通过org.springframework.web.struts.DelegatingActionProxy对action进行管理,在其配置中加入
相应Spring的配置如
com.yqh.upload.web.a