/**
* 获取预览活动二维码
* @author 向龙飞
* @date 2015-10-9
* @param m
* @param request
* @return
* @throws IOException
*/
@RequestMapping({"/lookevent.htm"})
public void lookevent(Map<String, Object> m,HttpServletRequest request, HttpServletResponse response) throws IOException {
//设置不缓存图片
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "No-cache");
response.setDateHeader("Expires", 0);
//指定生成的响应图片.
response.setContentType("p_w_picpath/jpeg");
BufferedImage img = null;
try {
int duankou = request.getLocalPort();
String duan = String.valueOf(duankou);
String url = "http://"+WXUtil.OAUTH_DOMAIN+":"+duan+"/getActivityDetailsForWeb.htm?activityId="+m.get("eventId")+"&isShow=1";
img = MatrixToImageWriter.getQr_imgbuffer(url, 150, 150);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ImageIO.write(img, "jpeg", response.getOutputStream());
}
将URL生成BufferedImage类,然后使用response将图片打印到前台页面。
页面显示时只需要将图片的src属性设置为该controller的地址即可显示。
转载于:https://blog.51cto.com/idlong/1708720