??xml version="1.0" encoding="utf-8" standalone="yes"?> 件的方便的途径QHSSFWorkbook、HSSFSheet、HSSFRow、HSSFCellQ分别代表了Excel电子表格中的Book、Sheet、行和单元格。你可以在下面地址下蝲到最新的POI工具包:
Ҏ一行HSSFRowQ它可以通过getFirstCellNum(cellNum) or getLastCellNum(cellNum)取得此行的格?列数)?/p>
通过HSSFCell可以判断每个表格中的数据cdQDOC中描q如下:
C现在实中应用当然不会q么单,此类库的更多功能我们可以参考其APIQ在此将中附带了API?/p>
看struts参考文档中Qbean:define 是指定义一个在指定范围内bean相关属性的脚本变量QDefine a scripting variable based on the value(s) of the specified bean propertyQ?br /> PrintUtil与UtilDateDTO均是在JSP面预先包含q来的(也不用关注)Q这些都是后台部分的处理了,q里L说明在JSP中其脚本如何引用STRUTS标签中的变量倹{?br />
1:java源文件编?/strong>
2:XDoclet--->Hbm(写在build.xml文g中,ANTq行)
3:SchemaExport---->数据?/strong>
DB中已l生成syn_dept表了,快去看下?
]]>
http://jakarta.apache.org/poi/index.html
一些常用操作如下:
//
所导入的第三方cd
import
org.apache.poi.hssf.usermodel.HSSFCell;
import
org.apache.poi.hssf.usermodel.HSSFRow;
import
org.apache.poi.hssf.usermodel.HSSFSheet;
import
org.apache.poi.hssf.usermodel.HSSFWorkbook;
import
org.apache.poi.poifs.filesystem.POIFSFileSystem;
//
初始?/span>
POIFSFileSystem poiFs
=
new
POIFSFileSystem(inputStream);
HSSFWorkbook wb
=
new
HSSFWorkbook(poiFs);
HSSFSheet sheet
=
wb.getSheetAt(
0
);
int
rowNumber
=
sheet.getFirstRowNum();
int
lastRowNumber
=
sheet.getLastRowNum();
通过sheet.getRow(rowNumber)取得一行的数据?/p>
static
int
CELL_TYPE_BLANK
Blank Cell type (
3
)
static
int
CELL_TYPE_BOOLEAN
Boolean Cell type (
4
)
static
int
CELL_TYPE_ERROR
Error Cell type (
5
)
static
int
CELL_TYPE_FORMULA
Formula Cell type (
2
)
static
int
CELL_TYPE_NUMERIC
Numeric Cell type (
0
)
static
int
CELL_TYPE_STRING
String Cell type (
1
)
q样Q对于一个现有的excel文gQ我们可以取得它所以行的数据,q对行中的每条数据根据不同的cdq行操作了!
excel文g中的一行具体cell转换成java数据实例:
private
String getStringCellValue(HSSFCell cell,
boolean
dateFlag)
{
String value
=
null
;
if
(cell
==
null
)
return
null
;
switch
(cell.getCellType())
{
case
HSSFCell.CELL_TYPE_BOOLEAN:
value
=
String.valueOf(cell.getBooleanCellValue());
break
;
case
HSSFCell.CELL_TYPE_NUMERIC:
if
(dateFlag)
value
=
new
java.text.SimpleDateFormat(
"
yyyy-MM-dd HH:mm
"
).format(cell.getDateCellValue());
else
{
//
value=String.valueOf(cell.getNumericCellValue());
value
=
new
DecimalFormat(
"
0.##########
"
).format(cell.getNumericCellValue());
}
break
;
case
HSSFCell.CELL_TYPE_ERROR:
value
=
String.valueOf(cell.getErrorCellValue());
break
;
case
HSSFCell.CELL_TYPE_FORMULA:
case
HSSFCell.CELL_TYPE_BLANK:
case
HSSFCell.CELL_TYPE_STRING:
value
=
cell.getStringCellValue();
if
(DATE_CELL.equals(value))
dateCellNumber
=
cell.getCellNum();
break
;
}
return
value;
}
]]>
从bean标签中引用,比如Q?/p>
<
bean:define
id
="birthdayInfo"
name
="person"
property
="info.birthday"
/>
此中Qperson可能是在request{中预先已经定义好的DTO{等Q这里暂时不是我们所要关注的啦)Q然后直接引用:
<%
=
PrintUtil.printTimeArea((UtilDateDTO)birthdayInfo)
%>
也可以直接从logic中引用,如:
<
logic:iterate
id
="detailsdto"
name
="eduCalendar"
type
="com.jbbis.netedu.eduadmin.dto.CalendarDetailDTO"
property
="details"
>
<%
=
PrintUtil.printTimeArea((CalendarDetailDTO)detailsdto)
%>
</
logic:iterate
>
其原理一L?br /> logic:iterate是用来P代指定范围内一些特定的集合容器QCustom tag that iterates the elements of a collection, which can be either an attribute or the property of an attribute. The collection can be any of the following: an array of objects, an Enumeration, an Iterator, a Collection (which includes Lists, Sets and Vectors), or a Map (which includes Hashtables) whose elements will be iterated over.Q?br />
应用CZQ?br /> 在DTO中我的一属?--生日Q在实体与DTO均定义ؓLongQ所以假如有一个ؓ1950-01-01生日的数据,那么在DTO与实体中pCZؓ631124235983
<%
java.text.DateFormat _fmt
=
new
java.text.SimpleDateFormat(
"
yyyy-MM-dd
"
, Locale.SIMPLIFIED_CHINESE);
%>
<
logic:notEmpty
name
="dto"
property
="birthday"
>
<
bean:define
id
="curbirthday"
name
="dto"
property
="birthday"
/>
<%
=
_fmt.format(
new
Date
(((
Long
)curbirthday).longValue()))
%>
</
logic:notEmpty
></
span
></
td
>
当然q样在JSP中加了个<%=%>W号Q要不就在DTO中额外ؓ生日另一个属性提供对生日的字W显C?"yyyy-MM-dd")?br />
在JSP中恰当应用相x{,不仅~程方便Q而且代码也可以美观不?/p>
]]>
具体来说是Q?br />只有JavaQ?java--->XDoclet(hibernatedoclet)--->Hbm---->SchemaExport(schemaexport,hbm2ddl)---->数据?/p>
/**/
/*
* Created on 2006-4-7
*/
package
com.entity;
/** */
/**
*
@author
jkallen
* @hibernate.class lazy="true" table="syn_dept"
* @hibernate.cache usage="read-write"
*/
public
class
SynDepartment
{
/** */
/**
主键 id
*/
private
Long id;
/** */
/**
部门名称
*/
private
String code_name;
/** */
/**
*
@return
Returns the id.
* @hibernate.id generator-class="native" column="id"
*/
public
Long getId()
{
return
id;
}
public
void
setId(Long id)
{
this
.id
=
id;
}
/** */
/**
*
@return
Returns the code_name.
* @hibernate.property column = "code_name"
*/
public
String getCode_name()
{
return
code_name;
}
public
void
setCode_name(String code_name)
{
this
.code_name
=
code_name;
}
}
q里用到了几U@hibernate标记的用?br />@hibernate.class标记指定cȝ映射代码Qlazy="true" table="syn_dept"则如
hibernate的映文件class元素的属性值具有相同的意义
@hibernate.id标记指定cȝOID映射代码
@hibernate.property标记指定cȝ属性映代?br />另外q可能用到@hibernate.set(如一对多的情况下)
<
target
name
="toHbm"
depends
="compileEntity"
description
="Generate hibernate mapping documents"
>
<
hibernatedoclet
destdir
="${generated.dir}"
>
<
fileset
dir
="${src.dir}"
>
<
include
name
="**/entity/*.java"
/>
</
fileset
>
<
hibernate
version
="2.0"
/>
</
hibernatedoclet
>
<
copy
todir
="${classes.dir}"
>
<
fileset
dir
="${generated.dir}"
/>
</
copy
>
</
target
>
通过hibernatedoclet可以生成SynDepartment.hbm.xml映射文g
fileset思义是qo文g了?br />注:compileEntity--~译java源文?自定?
<
target
name
="toddl"
depends
="init"
>
<
schemaexport
properties
="${classes.dir}/hibernate.properties"
quiet
="no"
text
="no"
drop
="no"
delimiter
="
go
"
output
="${sql.dir}/${synup.sql.file}"
>
<
fileset
refid
="hibernate.synup.mapping.files"
/>
</
schemaexport
>
<
echo
message
="Output sql to file: ${sql.dir}/${sql.file}"
/>
</
target
>
<
fileset
id
="hibernate.synup.mapping.files"
dir
="${classes.dir}"
>
<
include
name
="**/entity/*.hbm.xml"
/>
</
fileset
>
通过schemaexport向DB中生成table了。其中可能用到如下的一些属性:
quietQ如果ؓyes,表示不把子DDL脚本输出到控制台
dropQ如果ؓyesQ只执行删除数据库中的操作,但不创徏新的?br /> textQ如果ؓyesQ只会生成DDL脚本文gQ但不会在数据库中执行DDL脚本
outputQ指定存放DDL脚本文g的目?br /> configQ设定基于XML格式的配|文Ӟ hbm2ddl(schemaexport)工具从这个文件中d数据库的配置信息
propertiesQ设定基于java属性文件格式的配置文gQhbm2ddl(schemaexport)工具从这个文件中dDB的配|信?br /> formatQ设定DDL脚本中SQL语句的格?br /> delimiterQؓDDL脚本讄行结束符
在ANT中执行:
<target name="initOnlySynup" depends="toHbm,toddl">
</target>
OK,最后生成的映射文g如下Q?br />
<?
xml version="1.0"
?>
<!
DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd"
>
<
hibernate-mapping
>
<
class
name
="com.SynDepartment"
table
="syn_dept"
dynamic-update
="false"
dynamic-insert
="false"
>
<
cache
usage
="read-write"
/>
<
id
name
="id"
column
="id"
type
="java.lang.Long"
>
<
generator
class
="native"
>
</
generator
>
</
id
>
<
property
name
="code_name"
type
="java.lang.String"
update
="true"
insert
="true"
access
="property"
column
="code_name"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-SynDepartment.xml
containing the additional properties and place it in your merge dir.
-->
</
class
>
</
hibernate-mapping
>
控制C部分信息如下Q?/p>
[schemaexport] drop table syn_dept cascade constraints
[schemaexport] go
[schemaexport] drop sequence hibernate_sequence
[schemaexport] go
[schemaexport] create table syn_dept (
[schemaexport] id number(19,0) not null,
[schemaexport] code_name varchar2(255),
[schemaexport] primary key (id)
[schemaexport] )
关于Xdoclet 中的hibernate标签更多信息可以参考:
http://xdoclet.sourceforge.net/xdoclet/tags/hibernate-tags.html#@hibernate_collection-key__0__1_
我还在一个网友的博客上看C他对此的汉化Q?br />http://blog.csdn.net/fasttalk/archive/2005/09/19/484615.aspx
参考资料:Hibernate持久化技术详?/p>
]]>
]]>
http://searchwebservices.techtarget.com.cn/wpsum/29/2217529.shtml?504
1.2 Spring实战
http://searchwebservices.techtarget.com.cn/wpsum/75/2215575.shtml?2994
1.3 Spring - Java/J2EE Application Framework
Spring Framework 开发参考手册(中文版)
http://www.jactiongroup.net/reference/html/index.html
1.4 Introducing to Spring FrameworkQ中文修订版Q?/font>
http://spring.jactiongroup.net/viewtopic.php?t=453
1.5 Spring Framework 介绍 Qppt培训文档Q?/span>
http://www.jactiongroup.net/doc/Introduction2open-sourceSpringframework4J2EE.ppt
http://www.jactiongroup.net/doc/IntroductionToSpring.ppt
1.6 Spring 中文C
http://spring.jactiongroup.net
1.7 中国IT实验?Spring 框架完全q阶专题
http://www.chinaitlab.com/www/techspecial/spring/
1.8 本h再加一个啦:)~~
http://www.springframework.org
2 Appfuse:
http://raibledesigns.com/wiki/Wiki.jsp?page=AppFuse
3 DOJO
http://dojotoolkit.org/