我以字节格式在mysql数据库表中存储图像。当我从数据库中检索那个图像时,我越来越像这样。 如何从MySQL使用弹簧和休眠图像列表
所以调度员servlet.xml中如下:
<beans:bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!-- setting maximum upload size -->
<beans:property name="maxUploadSize" value="100000" />
</beans:bean>
的pom.xml
<!-- Apache Commons FileUpload -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
<!-- Apache Commons IO -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
driversList.jsp
<div style="color: teal; font-size: 20px">List Of Drivers</div>
<c:if test="${!empty listDrivers}">
<table border="1" bgcolor="black" width="600px">
<tr
style="background-color: teal; color: white; text-align: center;"
height="40px">
<th width="60">Name</th>
<th width="80">License Number</th>
<!-- <th width="80">Password</th> -->
<th width="80">Phone</th>
<th width="80">Password</th>
<th width="80">Address</th>
<th width="80">Photo</th>
</tr>
<c:forEach items="${listDrivers}" var="driver">
<tr
style="background-color: white; color: black; text-align: center;"
height="30px">
<td>${driver.name}</td>
<td>${driver.license}</td>
<td>${driver.number}</td>
<td>${driver.password}</td>
<td>${driver.address}</td>
<td><img src="/momcab1/myImage/imageDisplay?id=${driver.id}"/></td>
</tr>
</c:forEach>
</table>
</c:if>
<!-- Content data end -->
<br> <br> <br> <br> <br> <br> <br>
<br> <br> <br>
</div>
DriverController.java
@RequestMapping(value = "/DriversList", method = RequestMethod.GET)
public String listUsers(Model model,HttpServletRequest req,HttpServletResponse res) {
HttpSession session =req.getSession();
if(session.getAttribute("emailId")==null)
{
return "redirect:/login";
}
System.out.println("MY NAME IS GO PINK");
model.addAttribute("listDrivers", this.driverService.listDrivers());
return "driversList";
}
ImageController.java
@Controller
@RequestMapping("/myImage")
public class ImageController {
@Value("${login_session_token_timeout_mnts}")
private String loginSessionTokenTimeoutMnts;
private DriverService driverService;
@Autowired(required = true)
@Qualifier(value = "driverService")
public void setDriverService(DriverService ds) {
this.driverService = ds;
}
@RequestMapping(value = "/imageDisplay", method = RequestMethod.GET)
public void showImage(@RequestParam("id") Integer id, HttpServletResponse response,HttpServletRequest request)
throws ServletException, IOException{
Driver item = driverService.getDriverById(id);
response.setContentType("image/jpeg, image/jpg, image/png, image/gif");
response.getOutputStream().write(item.getBlobImg());
response.getOutputStream().close();
}
}
Driver.java
@Column(name = "photo")
private byte[] blobImg;
所以在这里当一个人点击 “驱动程序列表”,然后将请求映射去的DriverController.java
"/DriversList"
但在我driversList.jsp
有是从mysql数据库表中显示的图像。但是当页面加载时,它甚至不会进入"<img src>"
中给出的控制器请求映射,并且它显示如下所示的“十字标记”。任何帮助都将被理解。
感谢你
,我试图在这个enter link description here
我想没有人有关于从MySQL数据库获取图像的想法.GREAT !!!!!!! –
我会在你生气的人的底部张贴一个例子你! HAHAH – Snickers3192