struts2前端頁面讀取Clob/BLOB,struts2clob

來源:互聯網
上載者:User

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>方式訪問這個屬性

感覺你還沒有基本概念...
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.