ssh整合web导出excel案例Word格式.docx
- 文档编号:17333470
- 上传时间:2022-12-01
- 格式:DOCX
- 页数:35
- 大小:321.93KB
ssh整合web导出excel案例Word格式.docx
《ssh整合web导出excel案例Word格式.docx》由会员分享,可在线阅读,更多相关《ssh整合web导出excel案例Word格式.docx(35页珍藏版)》请在冰豆网上搜索。
xmlversion="
1.0"
encoding="
UTF-8"
>
<
beansxmlns="
http:
//www.springframework.org/schema/beans"
xmlns:
xsi="
//www.w3.org/2001/XMLSchema-instance"
p="
//www.springframework.org/schema/p"
aop="
//www.springframework.org/schema/aop"
context="
//www.springframework.org/schema/context"
jee="
//www.springframework.org/schema/jee"
tx="
//www.springframework.org/schema/tx"
xsi:
schemaLocation="
//www.springframework.org/schema/aop
http:
//www.springframework.org/schema/aop/spring-aop-2.5.xsd
//www.springframework.org/schema/beans
//www.springframework.org/schema/beans/spring-beans-2.5.xsd
//www.springframework.org/schema/context
//www.springframework.org/schema/context/spring-context-2.5.xsd
//www.springframework.org/schema/jee
//www.springframework.org/schema/jee/spring-jee-2.5.xsd
//www.springframework.org/schema/tx
//www.springframework.org/schema/tx/spring-tx-2.5.xsd"
<
beanid="
dataSource"
class="
mons.dbcp.BasicDataSource"
<
propertyname="
url"
value="
jdbc:
mysql:
//localhost:
3306/photo"
/property>
username"
root"
password"
hl1437"
driverClassName"
com.mysql.jdbc.Driver"
/bean>
sessionFactory"
org.springframework.orm.hibernate3.LocalSessionFactoryBean"
ref="
hibernateProperties"
<
props>
<
propkey="
hibernate.dialect"
org.hibernate.dialect.MySQLDialect
/prop>
hibernate.show_sql"
true<
hibernate.format_sql"
/props>
mappingResources"
list>
value>
com/luo/ssh/entity/Address.hbm.xml<
/value>
/list>
addressDao"
com.luo.ssh.dao.impl.AddressDaoHibernateImpl"
addressService"
com.luo.ssh.service.impl.AdressServiceImpl"
addressAction"
com.luo.ssh.action.AddressAction"
/beans>
5.hibernate映射配置(基本)
utf-8"
!
DOCTYPEhibernate-mappingPUBLIC"
-//Hibernate/HibernateMappingDTD3.0//EN"
"
hibernate-mapping>
classname="
com.luo.ssh.entity.Address"
table="
address"
catalog="
photo"
idname="
id"
type="
integer"
columnname="
/>
generatorclass="
native"
/generator>
/id>
name"
string"
length="
50"
level"
/>
upid"
info"
/class>
/hibernate-mapping>
6.struts配置
DOCTYPEstrutsPUBLIC
"
-//ApacheSoftwareFoundation//DTDStrutsConfiguration2.1.7//EN"
//struts.apache.org/dtds/struts-2.1.7.dtd"
struts>
packagename="
ssh"
extends="
struts-default"
actionname="
list"
method="
paramname="
pageSize"
36<
/param>
result>
/list.jsp<
/result>
/action>
detail"
/detail.jsp<
pageToExcel"
allToExcel"
childrenToExcel"
/package>
/struts>
7.web.xml配置
web-appversion="
2.5"
xmlns="
xmlns:
xsi:
--指明spring容器位置-->
context-param>
param-name>
contextConfigLocation<
/param-name>
param-value>
classpath:
ssh.xml<
/param-value>
/context-param>
listener>
listener-class>
org.springframework.web.context.ContextLoaderListener
/listener-class>
/listener>
filter>
filter-name>
struts2<
/filter-name>
filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
/filter-class>
/filter>
filter-mapping>
url-pattern>
/*<
/url-pattern>
/filter-mapping>
welcome-file-list>
welcome-file>
index.jsp<
/welcome-file>
/welcome-file-list>
/web-app>
8.实体类Address
packagecom.luo.ssh.entity;
importjava.io.Serializable;
/**
*地名类
*@author罗立明
*
*/
publicclassAddressimplementsSerializable{
/**地名的id,唯一*/
privateintid;
/**地名*/
privateStringname;
/**地名的下属级别,直辖市,省,自治区为1,其他没下一级级别+1*/
privateintlevel;
/**地名上一级的id,直辖市,省,自治区的上级id为0*/
privateintupid;
/**保留字段,地名备注及描述*/
privateStringinfo;
publicintgetId(){
returnid;
}
publicvoidsetId(intid){
this.id=id;
publicStringgetName(){
returnname;
publicvoidsetName(Stringname){
this.name=name;
publicintgetLevel(){
returnlevel;
publicvoidsetLevel(intlevel){
this.level=level;
publicintgetUpid(){
returnupid;
publicvoidsetUpid(intupid){
this.upid=upid;
publicStringgetInfo(){
returninfo;
publicvoidsetInfo(Stringinfo){
this.info=info;
@Override
publicinthashCode(){
returnid<
16;
publicbooleanequals(Objectobj){
if(this==obj)
returntrue;
if(obj==null)
returnfalse;
if(getClass()!
=obj.getClass())
Addressother=(Address)obj;
if(id!
=other.id)
returntrue;
publicStringtoString(){
return"
id:
+id+"
\n地名:
+name+"
\n级别:
+level+"
\n上一级id:
+upid;
}
9.dao接口定义
packagecom.luo.ssh.dao;
importjava.util.List;
importcom.luo.ssh.entity.Address;
publicinterfaceAddressDao{
/**
*查询地址总数
*@return
publicintcount();
*根据id查找地址
*@paramid
publicAddressfindById(intid);
*根据id查找所有下级地址
*@paramaddress
publicList<
Address>
findChildren(Addressaddress);
*根据id查找该地址的详细信息,追溯到最高上级
*@return结果形如:
湖北省-荆州市-公安县-狮子口镇
publicStringfindDetailById(intid);
*根据地名模糊查询所有满足条件的地址
*@paramname
findLikeName(Stringname);
*分页查询地址信息
*@parampage
*@parampageSize
findPage(intpage,intpageSize);
*查询全部
findAll();
10.dao的Hibernate实现
packagecom.luo.ssh.dao.impl;
importjava.sql.SQLException;
importorg.hibernate.HibernateException;
importorg.hibernate.Query;
importorg.hibernate.Session;
importorg.springframework.orm.hibernate3.HibernateCallback;
importorg.springframework.orm.hibernate3.HibernateTemplate;
importorg.springframework.orm.hibernate3.support.HibernateDaoSupport;
importcom.luo.ssh.dao.AddressDao;
publicclassAddressDaoHibernateImplextendsHibernateDaoSupportimplementsAddressDao{
publicAddressfindById(intid){
HibernateTemplatetemplate=getHibernateTemplate();
Addressaddress=(Address)template.get(Address.class,id);
returnaddress;
findChildren(Addressaddress){
Stringhql="
fromAddresswhereupid=?
;
returngetHibernateTemplate().find(hql,address.getId());
publicStringfindDetailById(intid){
Addressadd=findById(id);
Stringdetail=add.getName();
while(add.getLevel()!
=1){
add=findById(add.getUpid());
detail=add.getName()+"
-"
+detail;
}
returndetail;
findLikeName(Stringname){
fromAddresswherenamelike?
returngetHibernateTemplate().find(hql,"
%"
);
publicintcount(){
selectcount(*)fromAddress"
returnInteger.parseInt(getHibernateTemplate().find(hql).get(0).toString());
findPage(finalintpage,finalintpageSize){
List<
list=(List<
)template.execute(newHibernateCallback(){
publicObjectdoInHibernate(Sessionsession)throwsHibernateException,
SQLException{
Stringhql="
fromAddress"
Queryquery=session.createQuery(hql);
query.setFirstResult((page-1)*pageSize);
query.setMaxResults(pageSize);
returnquery.list();
}
});
returnlist;
findAll(){
returngetHibernateTemplate().find(hql);
11
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- ssh 整合 web 导出 excel 案例
![提示](https://static.bdocx.com/images/bang_tan.gif)