自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

WebWork實(shí)現(xiàn)數(shù)據(jù)導(dǎo)出CSV文本

開發(fā) 后端
本文向您介紹使用WebWork框架將數(shù)據(jù)導(dǎo)出CSV文本,作者使用簡單的配置和代碼實(shí)現(xiàn)了這個功能。

以往,在WebWork中實(shí)現(xiàn)導(dǎo)出CSV文本時,采用的是之前自己實(shí)現(xiàn)的csv result,但是這個實(shí)現(xiàn)有個缺陷就是對象嵌套不支持,而且需要構(gòu)造dto遍歷獲取列表進(jìn)行列表字段顯示的封裝,且在WebWork配置文件要羅列出需要導(dǎo)出的字段,過于繁瑣。

于是產(chǎn)生了采用直接用freemarker作為導(dǎo)出CSV文本文件模板的想法,這樣后臺只做查詢列表數(shù)據(jù)的獲取,WebWork配置文件只需要定位到指定freemarker模板,而且導(dǎo)出排版可以在freemarker中更靈活的得到控制。

其中,WebWork在導(dǎo)出CSV文本過程中,中文亂碼問題上尤其需要注意的是,一定要設(shè)置模板文件的編碼。

以下是實(shí)現(xiàn)實(shí)例:

  1. public String sampelExport()throws Exception{  
  2. 2     samplelist = SampleService.getAll();  
  3. 3     return SUCCESS;  
  4. 4}  

//samplelist的getter不要忘記哦。

SampleObject具有name屬性,類型為String,createDate屬性,類型為java.util.date,emails屬性,類型為java.util.list,為一個email封裝對象列表,status屬性,類型為Enum,提供按locale獲取顯示內(nèi)容方法。

  1. 1 〈action name="sampleexport" method="sampleExport" 
  2. 2      class="org.hook.webwork.SampleExportAction"〉  
  3. 3      〈result type="freemarker" name="success"〉  
  4. 4          template/default/sampleexport.ftl  
  5. 5      〈result〉  
  6. 6 〈/action〉  
  1. 1 〈#ftl encoding="GBK"〉   
  2. 2 〈#if response?exists〉${response.setHeader  
  3. ("Content-Disposition","attachment;   
  4. filename=sample_export.csv")}${response.setHeader  
  5. ("Cache-  Control""cache")}${response.setContentType  
  6. ("text/plain; charset=GBK")}${action.getText  
  7. ('org.hook.sampleobject.name')},  
  8. ${action.getText('org.hook.sampleobject.createdate')},  
  9. ${action.getText('org.hook.sampleobject.emails')},  
  10. ${action.getText('org.hook.sampleobject.status')}〈/#if〉  
  11. 3 〈#if samplelist?exists〉  
  12. 4 〈#list samplelist as sampleobject〉"${sampleobject.name}",  
  13. "${sampleobject.createDate?date}",  
  14. "〈#list sampleobject.emailss as email〉${email.fullinfo}   
  15. 〈/#list〉",  
  16. 〈#if sampleobject.status?exists&&sampleobject.status.  
  17. getValue(locale)?exists〉  
  18. ${sampleobject.status.getValue(locale)}〈/#if〉  
  19. 5 〈/#list〉  
  20. 6 〈/#if〉  

【編輯推薦】

  1. Webwork配置詳解
  2. 用WebWork注冊頁面建立過程
  3. WebWork注入Servlet方法詳解
  4. WebWork中返回INPUT的原因
  5. WebWork如何實(shí)現(xiàn)文件上傳配置過程
責(zé)任編輯:冰荷 來源: blogjava
相關(guān)推薦

2009-07-08 09:55:51

WebWork下載

2009-07-08 10:11:30

WebWork

2009-07-14 17:20:31

Webwork文件上傳

2009-07-16 15:14:27

WebWork用戶登陸

2009-07-08 09:29:58

WebWork

2009-07-14 16:08:41

WebWork學(xué)習(xí)

2009-07-14 17:34:53

Webwork配置

2009-07-14 15:52:00

WebWork文件下載

2009-07-16 14:08:14

webwork配置

2009-07-14 00:15:52

Webwork Act

2009-12-04 16:49:33

PHP批量導(dǎo)出csv文

2009-07-16 16:08:30

WebWork Act

2009-07-16 16:51:56

WebWork驗證機(jī)制

2009-07-16 16:01:54

WebWork敏捷開發(fā)

2009-07-14 14:04:36

WebWork框架

2009-07-08 10:30:57

WebWork

2023-02-03 08:21:30

excelMySQL

2009-07-09 15:55:18

WebWork配置文件

2009-07-14 17:53:11

WebWork安裝WebWork配置

2009-07-16 17:42:47

WebWork配置
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號