页面代码:
<div class="photobox" style="width: 280px;height: 260px">
<img src="${photoUrl}" οnerrοr="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";