我想用图像显示hows细节。实际上可能是一个如何没有形象。这是我的控制器显示它
@RequestMapping(value="/Hows/{categoryId}/{categoryName}",method=RequestMethod.GET)
public String showHowsCategory(@PathVariable("categoryId")int category,Model model,HttpServletRequest request){
int page = 1;
if(request.getParameter("page")!=null)
page = Integer.parseInt(request.getParameter("page").toString());
ListHows = showCategoryService.showAllHowInCategory(category,(page- 1)*pageSize,pageSize);
for(int i=(page-1)*pageSize;i<pageSize;i++){
byte[] binaryData = ListHows.get(i).getImage();
if(binaryData != null){
try {
byte[] encodeBase64 = Base64.encode(binaryData);
String base64Encoded = new String(encodeBase64, "UTF-8");
imageList.add(base64Encoded);
} catch (Exception e) {
e.printStackTrace();
}
}
}
model.addAttribute("image", imageList);
model.addAttribute("howList",ListHows);
并在jsp视图中使用此代码。但不显示图像。
<c:forEach var="how" items="${howList}" varStatus="counter">
<c:set var="url" value="${how.how}"/>
<c:set var="count" value="0" />
<div class="table">
<div style="float: left;margin-left: 10px;">
<c:if test="${how.image != null}">
<img src="data:image/jpeg;base64,${image[count]}" width="150" height="120"/>
<c:set var="count" value="${count + 1}" />
</c:if>
<c:if test="${how.image == null}">
<img width="150" height="120" src="<c:url value="/resources/images/how.jpg" />"/>
</c:if>
</div>
我的问题是什么?
答案 0 :(得分:1)
<img src="data:image/jpeg;charset=utf-8;base64,${image[count]}" width="150" height="120"/>
数据将是编码的base64字符串。