日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java 列表组件_Jsp页面列表组件框架设计

發(fā)布時間:2025/10/17 编程问答 15 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java 列表组件_Jsp页面列表组件框架设计 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

一起學(xué)習(xí)

Jsp頁面列表組件框架設(shè)計

作者:李俊杰

概述

為了提高開發(fā)效率,減少重復(fù)的頁面多次開發(fā),提高系統(tǒng)的可配置性和代碼的可復(fù)用性,也是為了展示struts、hibernate框架,設(shè)計原則是降低顯示邏輯和數(shù)據(jù)的耦合,達到顯示邏輯和數(shù)據(jù)完全分離,即相同的數(shù)據(jù)使用不同的顯示邏輯,無須修改顯示邏輯,只需置換不同的顯示模版即可。

實現(xiàn)機制

其中SturtsAction是具體的需要調(diào)用列表的Action類,TempDataMap類是具體的列表數(shù)據(jù)的封裝類,TempData類是具體的表記錄類,即TempDataMap來適配TempData,把表記錄適配成我們需要的列表顯示類。

調(diào)用示例:

Action:

//獲取數(shù)據(jù)庫數(shù)據(jù)

listRowCount = query.findPayItemByParam(paramInfo,paramForm.getPageSize(),paramForm.getPageNo());

list = listRowCount.getList();

//調(diào)用列表組件

if(list != null && list.size() > 0)

ColDataMgrmgr = new ColDataMgr(getDataMaps(list));

//獲取列表的表列信息,數(shù)據(jù)信息

ArrayList colMetaInfos = mgr.getColMetaInfos();

ArrayList datas = mgr.getData();

//將列表信息傳到List頁面

request.setAttribute(CoreConstant.WEB_DISPLAY_COL_METAT_INFOS_KEY, colMetaInfos);

request.setAttribute(CoreConstant.WEB_DISPLAY_DATAS_KEY, datas);

同樣道理,給出的數(shù)據(jù)可以分發(fā)給打印組件和導(dǎo)出excel列表組件,根據(jù)列表的列信息和數(shù)據(jù)信息,導(dǎo)出excel和打印。

具體的map類的內(nèi)容可參照附件ReceiveItemAmountQueryMap.java文件。

獲取顯示列信息:

/**

*返回的list中每個元素是列元信息類對象,列元信息類對象包括列名稱,列顯示名稱,

*列顯示格式,其中列名稱是key

*導(dǎo)出excel和打印是同樣的道理

*/

public ArrayList getColMetaInfos()

{

ArrayList list = new ArrayList();

list.add(new ColMetaInfo("transCode", "單據(jù)編號", true, "height="20" align="center" nowrap"));

list.add(new ColMetaInfo("transDate", "單據(jù)日期", false, "height="20" align="center" nowrap"));

list.add(new ColMetaInfo("transTypeName", "業(yè)務(wù)類型", false, "height="20" align="left" nowrap"));

list.add(new ColMetaInfo("receiveOrgName", "收款單位", false, "height="20" align="left" nowrap"));

list.add(new ColMetaInfo("receiveAccountNo", "收款賬戶號", false, "height="20" align="center" nowrap"));

list.add(new ColMetaInfo("receiveBankName", "收款銀行", false, "height="20" align="left" nowrap"));

list.add(new ColMetaInfo("extAccountNo", "付款賬戶", false, "height="20" align="center" nowrap"));

list.add(new ColMetaInfo("extBankName", "付款銀行", false, "height="20" align="left" nowrap"));

list.add(new ColMetaInfo("amount", "金額", false, "height="20" align="right" nowrap"));

list.add(new ColMetaInfo("memo", "摘要", false, "height="20" align="left" nowrap"));

return list;

}

//適配數(shù)據(jù),根據(jù)數(shù)據(jù)的類型如日期型,裝換成需要的字符串形式,金額類數(shù)據(jù)也轉(zhuǎn)換成相//應(yīng)的字符串格式,保存到HashMap中。

public HashMap getColData()

{

StringBuffer sb = new StringBuffer("receiveItemAmountQueryAction.do?operation=");

sb.append(CoreConstant.WEB_OPERATION_TYPE_TO_UPDATE_KEY);

sb.append("&id=");

sb.append(String.valueOf(form.getTransApplyItem().getTransApplyID().longValue()));

String link = sb.toString();

HashMap hm = new HashMap();

hm.put("transCode","?" IDataFormat.formatString(form.getTransCode()));

hm.put("transDate", "?" IDateFormat.toDateString(form.getTransDate()));

hm.put("transTypeName", "?" IDataFormat.formatString(form.getTransTypeName()));

hm.put("receiveOrgName", "?" IDataFormat.formatString(form.getReceiveOrgName()));

hm.put("receiveAccountNo", "?" IDataFormat.formatString(form.getReceiveAccountNo()));

hm.put("receiveBankName", "?" IDataFormat.formatString(form.getReceiveBankName()));

hm.put("extAccountNo", "?" IDataFormat.formatString(form.getTransApplyItem().getExtAccountNo()));

hm.put("extBankName", "?" IDataFormat.formatString(form.getTransApplyItem().getExtBankName()));

if (form.getTransApplyItem().getAmount() != null)

{

String sAmount = "?" IDataFormat.formatDisabledAmount(form.getTransApplyItem().getAmount().doubleValue() );

hm.put("amount", sAmount);

}

else

{

hm.put("amount", "0.00");

}

hm.put("memo", "?" IDataFormat.formatString(form.getTransApplyItem().getMemo()));

hm.put("SUPERLINK", link);

return hm;

}

附錄:

DataMap接口:

/**

* @author lijj

*

* To change the template for this generated type comment go to

* Window - Preferences - Java - Code Generation - Code and Comments

*/

public interface DataMap {

public ArrayList getColMetaInfos();

public ArrayList getExeclColMetaInfos();

public ArrayList getPrintColMetaInfos();

public ArrayList getColSearchs();

public HashMap getQueryData();

public String getSearchUrl();

public HashMap getColData();

}

抽象實現(xiàn)類DefaultDataMap

import java.util.ArrayList;

import java.util.HashMap;

/**

* @author lijj

*

* To change the template for this generated type comment go to

* Window - Preferences - Java - Code Generation - Code and Comments

*/

public abstract class DefaultDataMap implements DataMap{

public abstract ArrayList getColMetaInfos();

public abstract HashMap getColData();

public ArrayList getExeclColMetaInfos()

{

return new ArrayList();

}

public ArrayList getPrintColMetaInfos()

{

return new ArrayList();

}

public String getSearchUrl()

{

return null;

}

public HashMap getQueryData()

{

return null;

}

public ArrayList getColSearchs()

{

ArrayList retList = new ArrayList();

return retList;

}

}

ColDataMgr管理類:

import java.util.ArrayList;

import java.util.HashMap;

/**

* @author lijj

*

* To change the template for this generated type comment go to Window - Preferences - Java - Code Generation - Code and

* Comments

*/

public class ColDataMgr

{

ArrayListlist= null;

DataMapmap= null;

public ColDataMgr(ArrayList list)

{

this.list = list;

}

public ColDataMgr(DataMap map)

{

this.map = map;

}

public ArrayList getColMetaInfos()

{

if (list != null)

{

return ((DataMap) list.get(0)).getColMetaInfos();

}

else

{

return this.map.getColMetaInfos();

}

}

public ArrayList getExeclColMetaInfos()

{

if (list != null)

{

return ((DataMap) list.get(0)).getExeclColMetaInfos();

}

else

{

return this.map.getExeclColMetaInfos();

}

}

public ArrayList getPrintColMetaInfos()

{

if (list != null)

{

return ((DataMap) list.get(0)).getPrintColMetaInfos();

}

else

{

return this.map.getPrintColMetaInfos();

}

}

public ArrayList getData()

{

ArrayList retList = new ArrayList();

DataMap dataMap = null;

if (list != null)

{

for (int i = 0; i < list.size(); i )

{

dataMap = (DataMap) list.get(i);

retList.add(dataMap.getColData());

}

}

return retList;

}

public ArrayList getSearchInfos()

{

return getDataMap().getColSearchs();

}

public String getSearchUrl()

{

return getDataMap().getSearchUrl();

}

public HashMap getQueryData()

{

return getDataMap().getQueryData();

}

private DataMap getDataMap()

{

if (this.map != null)

{

return map;

}

else

{

return ((DataMap) list.get(0));

}

}

}

列元信息類ColMetaInfo

/**

* @author lijj

*

* To change the template for this generated type comment go to Window - Preferences - Java - Code Generation - Code and

* Comments

*/

public class ColMetaInfo

{

private Stringname;

private StringdisplayName;

private booleanisLink;

private String property;

public ColMetaInfo(String name, String displayName, boolean isLink, String property)

{

this.name = name;

this.displayName = displayName;

this.isLink = isLink;

this.property = property;

}

public String getDisplayName()

{

return displayName;

}

public void setDisplayName(String displayName)

{

this.displayName = displayName;

}

public boolean isLink()

{

return isLink;

}

public void setLink(boolean isLink)

{

this.isLink = isLink;

}

public String getName()

{

return name;

}

public void setName(String name)

{

this.name = name;

}

public String getProperty()

{

return property;

}

public void setProperty(String property)

{

this.property = property;

}

}

模版文件list.jsp

ArrayList colMetaInfos = (ArrayList) request.getAttribute("colMetaInfos");

ArrayList datas = (ArrayList) request.getAttribute("datas");

int colLen = colMetaInfos.size();

int resultCount = datas.size();

%>

ColMetaInfo colMeta = null;

for (int i = 0; i < colLen; i )

{

colMeta = (ColMetaInfo) colMetaInfos.get(i);

%>

}

%>

HashMap hm = null;

for (int i = 0; i < resultCount; i )

{

%>

hm = (HashMap) datas.get(i);

for (int j = 0; j < colLen; j )

{

colMeta = (ColMetaInfo) colMetaInfos.get(j);

%>

>

if (colMeta.isLink() && hm.get(colMeta.getName()) != null

&& !((String) hm.get(colMeta.getName())).equals(""))

{

%>

}

else

{

%>

}

%>

}

%>

}

%>

//沒有記錄顯示空白行

if (resultCount == 0)

{

%>

for (int i = 0; i < colLen; i )

{

colMeta = (ColMetaInfo) colMetaInfos.get(i);

%>

}

}

%>

Jsp使用列表模版的片斷

開戶申請

新增" name="bt" class=button onClick="JavaScript:to_Add();">

總結(jié)

以上是生活随笔為你收集整理的java 列表组件_Jsp页面列表组件框架设计的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。