国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > HTML > 正文

html實現頁面靜態化的案例

2020-03-24 16:18:15
字體:
來源:轉載
供稿:網友
靜態化文件位置注意:

wKioL1m2KwSD3R_pAAAjiwpj0zM659.png

實體類定義:

html' target='_blank'>public class News { private String title; private String pubTime; private String category; private String newsContent;
in = new BufferedReader(new FileReader(fsrc)); out = new PrintWriter(new BufferedWriter(new FileWriter(fDest))); String strRet; while((strRet=in.readLine()) != null){ out.println(strRet); out.flush(); } catch (Exception e) { e.printStackTrace(); }finally{ if(in != null){ try { in.close(); } catch (Exception e2) { e2.printStackTrace(); if(out != null){ try { out.close(); } catch (Exception e2) { e2.printStackTrace(); * 把傳入的信息,保存成文件 * @param finfo 傳入的文件內容信息 * @param fname 目標路徑和文件名 public void writeFile(String finfo,String fDest){ File file = new File(fDest); if(file.exists()){ file.delete(); PrintWriter out = null; try { out = new PrintWriter(new BufferedWriter(new FileWriter(fDest))); out.write(finfo); out.flush(); } catch (Exception e) { e.printStackTrace(); }finally{ if(out !=null){ out.close(); * 讀取文本型文件 * @param name * @return public String readFile(String fname){ File file = new File(fname); StringBuilder bild = new StringBuilder(); BufferedReader in = null; if(file.exists()){ try { in = new BufferedReader(new FileReader(fname)); String strRet; while((strRet=in.readLine()) != null){ bild.append(strRet); } catch (Exception e) { e.printStackTrace(); }finally{ if(in != null){ try { in.close(); } catch (Exception e2) { e2.printStackTrace(); }else{ System.out.println(fname + 不存在
CharStreamIO io = new CharStreamIO(); SimpleDateFormat sd = new SimpleDateFormat( yyyy-MM-dd HH:mm:ss List News newsList = new ArrayList News News n1 = new News(); n1.setCategory( sport String c1 = io.readFile( NewsInfo//news1.txt n1.setNewsContent(c1); n1.setPubTime(sd.format(new Date())); n1.setTitle( 深足教練組:說我們買球是侮辱 朱廣滬常暗中支招 News n2 = new News(); n2.setCategory( hot String c2 = io.readFile( //NewsInfo//news2.txt n2.setNewsContent(c2); n2.setPubTime(sd.format(new Date())); n2.setTitle( 對對對發發發失誤失誤 newsList.add(n1); newsList.add(n2); return newsList;}

業務邏輯層

public class NewsBiz { * 讀取數據庫中要生成的新聞信息 * @return public void createAllNews() throws Exception{  NewsDao dao = new NewsDao(); List News newsList = dao.getAllNews(); String destPath = /News/newspages  for(int i=0;i newsList.size();i++){ //讀取模板 CharStreamIO io = new CharStreamIO(); String tmp = io.readFile( /News/news.tmp  //替換模板中的參數數據 News n = newsList.get(i); String newTmp; newTmp = tmp.replace(TemplateParam.TITLE, n.getTitle()); newTmp = newTmp.replace(TemplateParam.CATEGORY,n.getCategory()); newTmp = newTmp.replace(TemplateParam.PUB_TIME,n.getPubTime()); newTmp = newTmp.replace(TemplateParam.CONTENT, n.getNewsContent()); //把替換后的內容保存成新聞頁面 io.writeFile(newTmp, destPath + /news- + i + .html }

TemplateParam類

public class TemplateParam { public static final String TITLE = %{title}%  public static final String CATEGORY = %{category}%  public static final String CONTENT = %{newsContent}%  public static final String PUB_TIME = %{pubTime}% }

用戶接口層

public class NewsTest { public static void main(String[] args) { NewsBiz biz = new NewsBiz(); try { biz.createAllNews();  System.out.println( 新聞頁面創建完畢!  } catch (Exception e) { e.printStackTrace();}

以上就是html實現頁面靜態化的案例的詳細內容,html教程

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 惠来县| 皋兰县| 三原县| 台东县| 侯马市| 宁陕县| 筠连县| 旬邑县| 海门市| 蓬溪县| 怀化市| 琼中| 新巴尔虎左旗| 孝感市| 平顶山市| 广德县| 广饶县| 滁州市| 遂溪县| 临武县| 安庆市| 陈巴尔虎旗| 安义县| 延川县| 津市市| 巴林左旗| 汶川县| 江都市| 黄石市| 阳山县| 封丘县| 瓮安县| 高邑县| 翼城县| 扎鲁特旗| 海口市| 辽中县| 五指山市| 峨边| 定州市| 红安县|