Easyui+springmvc+mybaits page picture pop-up window display

Source: Internet
Author: User

The project needs to complete a click Hyperlink pop-up window, which is used to display the image stored in the database, such as the function;

# Preparation Tools:Environment:Eclipse 4.3jdk1.7.0_72apache-maven-3.0.4apache-tomcat-7.0.53spring-mvc-4.0spring-beans-4.0mybatis-3.2.8Oracle 11.2.0.3.0  # Basic ideas (according to data flow analysis): ------------------------Backstage:>>> First obtains a applyprocess instance with a BLOB field from the database;>>> get an output stream by using the Blob field's own method;>>> outputs the stream to the buffer through the write method of the Bufferoutputstream instance;>>> Brushes The stream in the buffer to the page by means of the flush method;  ------------------------Front Desk:>>> using jquery's $.post () method to retrieve the output stream from the background;>>> gets the output stream to an object that needs to traverse the object again and get to the output stream;>>> get the output stream to the image display path according to the prosn of the object;>>> Add a picture path node below a div node; 
<DivID= "Mpic">    <imgsrc= "http://192.168.24.9:8281/acctSettlement/rfcheck/printImage?prosn=20150901100501"width= "100%"Height= "100%">    <BR>    <HR>    <BR></Div>
# code section: # Controller.java
1@RequestMapping (value = "/printimage", method =requestmethod.get)2      Public voidprintimage (Long prosn, httpservletresponse response) {3Arefundapplyprocess Annex =Arefundapplycheckservice4 . Queryannexbyprosn (PROSN);5InputStream in =NULL;6         Try {7in = ((Blob) annex.getcontent ()). Getbinarystream ();//The content node is obtained here because the return type is configured in Resultmap in mapper Bolb8}Catch(SQLException e) {9 e.printstacktrace ();Ten         } One         Try { ABufferedoutputstream BOS =NewBufferedoutputstream ( - Response.getoutputstream ()); -             intN; the              while((n = in.read ())! = 1) { - bos.write (n); -             } - Bos.flush (); + bos.close (); -}Catch(IOException e) { +Log.info ("Show refund Request information Picture exception"); A}finally { at             Try { - in.close (); -}Catch(IOException e) { -Log.info ("Output stream shutdown failed"); -             } -         } in}

As can be seen here, in line seventh has been obtained through the Pojo get method to save the Blob object, which is stored in the database picture;

After obtaining the Inputstrem, the object can be output to memory through the response Getoutpstream method, although the specific principle remains to be verified, but the function is realized at present;

> Knowledge Point Record: The Getoutputstream method of response, and the IO system related in Java;

Finally, the resulting output stream is brushed out to the page via the Flush method;

Java code is done in this step, the biggest problem is how to get from the page to the memory of the picture;

# page.jsp Code

1 <aID= "Searchbut"href="#"class= "Easyui-linkbutton"data-options= "Iconcls: ' Icon-search '">2 View3 </a>4 5 functions Showimg () {//This method is called when the View button is clicked;6 7$.post ("<%=BasePath%>Rfcheck/queryrefundapplyannex ",8 {"Applyid": Applyidvar},9 function (data) {Ten $ ("#searchBut"). Click (function () { One $ ("#mpic"). HTML (""); A var mdata = data; - $ (mdata.rows). Each (function (i, elem) { -var url = "<%=BasePath%>rfcheck/printimage?prosn= "+ELEM.PROSN; thevar img = "<imgsrc= ' "+url+" 'width= ' 100% 'Height= ' 100% '/>"; - $ ("#mpic"). Append (img); -$ ("#mpic"). Append ("<BR/><HR/><BR/>"); -                 }); + $ (' #imageWindow '). Window (' open '); -         }); + }, "json"); A          at}

As can be seen here, by looping through the way to get the image object in memory, and stitching it into a path for display in the pop-up window;

Easyui+springmvc+mybaits page picture pop-up window display

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.