日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
WebWork實(shí)現(xiàn)數(shù)據(jù)導(dǎo)出CSV文本

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

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

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

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

 
 
 
  1. 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,為一個(gè)email封裝對(duì)象列表,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〉  

網(wǎng)站題目:WebWork實(shí)現(xiàn)數(shù)據(jù)導(dǎo)出CSV文本
文章URL:http://m.5511xx.com/article/dhchpgc.html