java查询图片显示无图片显示项目默认图片

时间:2022-11-07 17:26:44

/**
* 读取图片
* @param request
* @param record
* @return
*/
@RequestMapping(params ="method=queryWlmxZp")
public void queryWlmxZp(HttpServletRequest request,HttpServletResponse response,HttpWlmxZpBean record){
  OutputStream outputStream = null;
  try {
    record =wSWlmxZpService.queryWlmxZp(record);
    if(record!=null&&record.getZp().length>0){
      byte [] zp=record.getZp();
      outputStream = response.getOutputStream();
      outputStream.write(zp);
    }else{
      RequestDispatcher dis = request.getRequestDispatcher("/static/images/timg.jpg");
      dis.forward(request, response);
    }
  } catch (Exception e) {
    e.printStackTrace();
  }finally{
    try {
      if(outputStream!=null){
        outputStream.close();
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}