简体   繁体   中英

Reading blob type image from mysql database in Spring mvc with jdbcTemplate

ProductController.java

@RequestMapping(value = "/adminWelcome", method = RequestMethod.GET)
public String getAdminWelcomePage(Model model) {

    System.out.println("Product List:" + productService.getAllProducts());

    model.addAttribute("productList", productService.getAllProducts());
    return "adminHomepage";
}

ProductService.java

 public List<Map<String, Object>> getAllProducts() {
    String sql = "SELECT * FROM products LIMIT 3";

    List<Map<String, Object>> products = jdbcTemplate.queryForList(sql);
    return products;

}

Basically, this sql return the list of 3 products which are looks like Product List:[{id=1, name=Twitter-minimal, userId=0, image=[B@96a7858, price=1213322.0, dateManufacture=2017-02-07, dateAdded=2017-02-07 15:50:12.0, category=Clothing, description=ramedadadadad}] .

This is the sample of the result which I fetched from MySql database with jdbcTemplate . I upload the image using Spring MVC4 in the database. Now I want to retrieve or read the Blob image type so that I can display those images to my jsp pages. How can I convert this Blob image so that I can properly display to pages?

The image type was defined as MultipartFile image in the domain class.

yo need resource mapping in dispatcher-servlet.xml

and
add this in your jsp page.. where static as i have defined is /WEB-INF/assets/

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