简体   繁体   中英

How to retrieve multiple blob images from database

Hi i am using Spring mvc and hibernate. I want to retrieve multiple blob images from database and want to display in jsp. I tried a lot but did not get fruitful answer. If anyone gives link or sample code then it would be great for me.

If you are already using spring you could also have a look at spring data and the data repositories ( http://docs.spring.io/spring-data/commons/docs/current/reference/html/#repositories ).
There are a lot examples out there how it should look in action :)
If you use the newest Version you can stream the results. With that you can load the images async if you have performance issues.

i'm using server side this code it's works for me

Spring Controller

@RequestMapping(value ="/getImages", method = RequestMethod.GET)
    @ResponseBody
    public List<Product> getStateList(HttpServletResponse response, HttpServletRequest request) {
        List<Product> image = imageService.getImageList();
        List<Product> imageList= new ArrayList<Product>();
        for (Product m : new ArrayList<Product>(image)) {
            String base64Encoded = javax.xml.bind.DatatypeConverter.printBase64Binary(m.getImage());
            Product imagepath = new Product();
            imagepath.setImagePath(base64Encoded);
            imagepath.setItemName(m.getItemName());
            imageList.add(imagepath);
        } 
        return imageList;
    }

DAO

public List<Product> getImageList() {
        String getImageQuery = "FROM Product";
        Query query = sessionFactory.getCurrentSession().createQuery(getImageQuery);
        @SuppressWarnings("unchecked")
        List<Product> imgList = query.list();
        return imgList;
    }

Model Class

@Entity
@Table(name="imageUpload")
public class ImageUpload {

    @Id
    @Column(name="eloraId")
    private int eloraId;

    @Column(name="password")
    private String password;

    @Column(name="ownerName")
    private String ownerName;

    @Column(name="registeredId",columnDefinition="mediumblob")
    private byte[] registeredId;

    @Column(name="hospPanCard")
    private String hospPanCard;

    @Column(name="hospRegCert",columnDefinition="mediumblob")
    private byte[] hospRegCert;

    @Column(name="ownerPanCard",columnDefinition="mediumblob")
    private byte[] ownerPanCard;

    @Column(name="ownerselfDec",columnDefinition="mediumblob")
    private byte[] ownerselfDec;

    @Column(name="ownerAddProof",columnDefinition="mediumblob")
    private byte[] ownerAddProof;

    @Transient
    private String statusMessage;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM