struts2前端頁面讀取Clob/BLOB,struts2clob
在通過Struts2標籤顯示對象的Clob屬性值的時候,顯示的並不是CLOB或者BLOB的內容,而是顯示的toString方法的值
例如我在實體中的註解為:
@Lob@Column(name = "CONTENT_TEXT")public String getContentText() {return contentText;}
前台頁面讀取方式為:
<s:property value="#entry.contentText" />
顯示結果為:
oracle.sql.CLOB@1077e76
要想正常顯示CLOB或者BLOB的內容。需要在action中加入對clob或者blob的轉換方法
public String getClob(Clob c){Reader reader = null;StringBuffer sb = new StringBuffer();try {reader = c.getCharacterStream();BufferedReader br = new BufferedReader(reader);String temp = null;while ((temp=br.readLine()) != null) {sb.append(temp);}} catch (Exception e) {}finally{if (reader!=null) {try {reader.close();} catch (IOException e) {}}} return sb.toString();}前端頁面調用改為
<s:property value="%{getClob(#entry.contentText)}" /></span>
這樣就可以正常顯示clob的內容了,blob類似,只是把讀取方式換成二進位流讀取
struts2從資料庫中讀取blob類型資料(圖片)
1. Reader rd = rs.getCharacterStream(1); 和 Blob blob = rs.getBlob(1); 中的1代表列編號,表示它將取出來的第一列的資料返回
2. 你的前台只顯示一個圖片那是因為你的SQL語言限制了只取一種圖片呀:select GoodsImage from table_goods where GoodTypeID=1
struts2從資料庫中讀取資料問題
在action中取到你需要的資料,放在action的類屬性中,再加上public的存取方法, action執行完畢後跳到頁面, 就可以直接用${}或者<s:property>方式訪問這個屬性
感覺你還沒有基本概念...