1. 程式人生 > >將以位元組儲存在伺服器的圖片在頁面進行顯示

將以位元組儲存在伺服器的圖片在頁面進行顯示

頁面程式碼:

<div class="photobox" style="width: 280px;height: 260px">

<img src="${photoUrl}" onerror="this.src='${pageContext.request.contextPath }/photo/default.jpg'" style="width: 100%;height: 100%"/>

</div>

controller相關程式碼:

//根據id去查詢流水

String custId = SessionUtils.getPartyGroupIdFromSession(Const.SESS_USER);

BaseAttenceCommonRequest<AttenceBizRo> req = new BaseAttenceCommonRequest<AttenceBizRo>();

AttenceBizRo attenceBizRo = new AttenceBizRo();

attenceBizRo.setTransactionId(transactionId);

req.setObj(attenceBizRo);

BaseAttenceCommonResponse<AttenceBizRo> rep = attenceBizProvider.queryAttenceBiz(custId, req);

if("0000".equals(rep.getRespCode())){

if(rep.getObj()!=null && rep.getObj().getPhoto()!=null){

//獲取圖片的位元組陣列

byte[] photo = rep.getObj().getPhoto();

//base64

String image = MyBase64.encode(photo);

if(image!=null && !"AA==".equals(image)){

String header = "data:image/jpeg;base64,";

image = header+image;

map.put("photoUrl", image);

}

}

}

return "/attence/bizPhoto";