簡體   English   中英

使用jdbcTemplate從Spring MVC中的MySQL數據庫讀取blob類型圖像

[英]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;

}

基本上,此sql返回3個產品列表,它們看起來像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}]

這是我使用jdbcTemplateMySql數據庫中獲取的結果的示例。 我在數據庫中使用Spring MVC4上傳圖像。 現在,我想檢索或讀取Blob圖像類型,以便可以將這些圖像顯示在我的jsp頁面上。 如何轉換此Blob圖片,以便可以正確顯示到頁面?

圖像類型在域類中定義為MultipartFile image

您需要在dispatcher-servlet.xml中進行資源映射


將此添加到您的jsp頁面..我定義的靜態位置是/ WEB-INF / assets /

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM