- addDay(Date aDate, int iDay) : Date
- addMonth(Date aDate, int iMonth) : Date
- addQuarter(Date aDate, int iQuarter) : Date
- addWeek(Date aDate, int iWeek) : Date
- addYear(Date aDate, int iYear) : Date
- getDayOfMonth(Date aDate) : int
- getDayOfWeek(Date aDate) : int
- getDayOfYear(Date aDate) : int
- getDaysBt(Date dFrom, Date dTo) : int
- getFirstDayOfMonth(Date aDate) : Date
- getFirstDayOfQuarter(Date aDate) : Date
- getFirstDayOfWeek(Date aDate) : Date
- getFirstDayOfYear(Date aDate) : Date
- getLastDayOfMonth(Date aDate) : Date
- getLastDayOfQuarter(Date aDate) : Date
- getLastDayOfWeek(Date aDate) : Date
- getLastDayOfYear(Date aDate) : Date
- getMonth(Date aDate) : int
- getQuarter(Date aDate) : int
- getYear(Date aDate) : int
- main(String[] args) : void
- trunc(Date aDate, String aFormat) : Date
2006年7月26日
公司經常更換框架,好不容易寫好的業務模型經常要推倒重來。
為此考慮將業務模型獨立出來,不受框架的影響。
具體考慮如下:
1.接口定義
DBConnection.java
public interface DBConnection {
? PreparedStatement prepareStatement(String aSql);
?....
? void free();
? void commit();
? void rollback();
}
DBContext.java
public interface DBContext {
? DBConnection newDBConnection();
}
2.模型實現
public class ActualFlow {
? DBContext dbContext=null;
? public ActualFlow() {
? }
? public void init(DBContext aContext){
??? dbContext=aContext;
? }
? public int calculate(String aBranchId,String aYear,String aMonth,String aUserId){
??? int iRtn=-1
??? PreparedStatement objState=null;
??? ResultSet objSet=null;
??? DBConnection objCon=null;
??? try {
????? objCon=dbContext.newDBConnection();
????? objState=objCon.prepareStatement("具體的sql語句");
????? //業務模型操作......
??? }
??? catch (Exception ex) {
????? ex.printStackTrace();
????? iRtn=-1;
??? }finally{
????? if (objSet!=null) {
??????? try {
????????? objSet.close();//關閉結果集合
??????? }
??????? catch (Exception ex) {
????????? ex.printStackTrace();
??????? }
????? }
????? if (objState!=null) {
??????? try {
????????? objState.close();//關閉statement
??????? }
??????? catch (Exception ex1) {
????????? ex1.printStackTrace();
??????? }
????? }
????? if (objCon!=null) {
??????? objCon.free();//釋放連接
????? }
??? }
??? return iRtn;
? }
}
3.在具體的開發框架下面
?? 定義EAPDBContext 實現 DBContext
???如下方式復用模型:
????? ActualFlow objActualFlow=new ActualFlow();
? ??? objActualFlow.init(new EAPDBContext("actualFlow"));
????? int i=objActualFlow.calculate(this.m_branchID,this.m_year,this.m_month);
不知道是否合理,先練習練習
//例子:
//var it=new StringIterator("a,b,c,d",",");
//while(it.hasNext()){
//? alert(it.next());
//}



?2

?3

?4

?5

?6

?7



?8

?9



10



11

12

13

14

15



16

17

18



19

20

21

22

23

24

25



26

27

28

29

30

31

? <servlet>
??? <servlet-name>excel</servlet-name>
??? <servlet-class>××××</servlet-class>
? </servlet>
? <servlet-mapping>
??? <servlet-name>excel</servlet-name>
??? <url-pattern>*.xls</url-pattern>
? </servlet-mapping>
2.頁面代碼
<a title='Excel' id=aa href='/fmudemo/Export.xls?para1=7¶2=1267¶3=null¶4=*'>
????? <font size=2>Excel</font>
</a>
3.編寫servlet
?? 輸出html字符串,
效果:
? 點擊鏈接后,會彈出對話框提示用excel打開。