struts中处理非String类型(Date类型的处理)
1.Dao层的处理:XML:namespace prefix = o ns = "urn:schemas-microsoft-com:Office:office" />
/**
* 开始日期转换
* */
SimpleDateFormat format = new SimpleDateFormat(ApplicationConstants.DATE_FORMAT);
Date dateTime = format.parse("2003" Day="1" Month="10" ls="trans" w:st="on">10/1/2003");
long lDate = dateTime.getTime();
Java.sql.Date sqlDate = new java.sql.Date(lDate);
... ...
Ps.setDate(nPara++,...);
/**
* 日期转换结束
*/
2. Bean的处理方法:
Bean中含有Date成员的,应增加两个相应的方法,实例如下:
/**
* 页面查询终止时间
* */
public Date getStartTime()
{
return dtStartTime;
}
public void setStartTime(Date starttime)
{
this.dtStartTime = starttime;
}
//注意以下两个方法是为页面参数传递和显示方便而加的
public String getEndTimeString()
{
String result = "";
if (dtEndTime != null)
{
SimpleDateFormat format = new SimpleDateFormat(ApplicationConstants.DATE_FORMAT);
return format.format(dtEndTime);
}
return result;
}
public void setEndTimeString(String dateString) throws ActionException
{
try
{
if (dateString != null && dateString.length() > 0)
{
dtEndTime = java.sql.Date.valueOf(dateString);
}
else
{
dtEndTime = null;
}
}
catch (Exception exp)
{
//指定的日期字符串格式不对,应为mm/dd/yyyy
throw new ActionException("error.com.cycloneqi.dateformat.invalidate");
}
}
3. 页面的显示方法。
例如:在需要输入日期的地方编码如下:
请输入终止时间:
Javascript:showTimeCtrol();”>sourceValue="0" HasSpace="False" Negative="False" NumberType="1" TCSC="0">0”>
注意:本文的一切权力归Mailto:hzqi@isoftstone.com" rel="nofollow">本文作者所有
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10748419/viewspace-963687/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/10748419/viewspace-963687/