剛剛接觸了FreeMarker覺得不錯
做了個小例子
首先建立個數據表裡面有username,passWord兩個字段自己隨便加幾條數據建立一個webwork action TestAction.Java在xwork.XML裡加入如下內容----------------------------------------
import com.opensymphony.xwork.ActionSupport;import Java.util.*;import com.ResultGather;
public class TestAction extends ActionSupport { private List lis; private ResultGather rs; public List getLis() { return this.lis; } public String execute() throws Exception { rs = new ResultGather(); lis = rs.selectRS("select * from userbasedatum");//數據結果我是用List,HashMap封裝的,HashMap存的是單條記錄 return SUCCESS; }}
-------------------------------------------------------------------------------------------------------------------ResultGather.Java代碼如下----------------------------------------------------------package com;
import conn.DBConnManager;//數據庫連接池import java.sql.*;import Java.util.*;
public class ResultGather { private String sql; public ResultGather() { } public ResultGather(String sqlcom) { this.sql=sqlcom; } public List selectRS(String sqlStr) { this.sql = sqlStr; return selectRS(); } public List selectRS() //數據結果在這裡裝入List和Map { List rsall = new ArrayList(); DBConnManager conn = null; Connection con = null; Statement stmt = null; ResultSet rs = null; Map rsTree; try{ conn = DBConnManager.getInstance(); con = conn.getConnection("mssql"); stmt = con.createStatement(); rs = stmt.executeQuery(sql); ResultSetMetaData rsmd = rs.getMetaData(); int numberOfColumns = rsmd.getColumnCount(); while(rs.next()) { rsTree = new HashMap(numberOfColumns); for(int r=1;r
//freemarker用法網上有相關介紹-------------------------------------------------------------------------------------
OK 完成了 沒有用到JSp<%.....%>和JSPtag用這個例子做一點修改就可以具有分頁用能了