Java后台代码
/**
* 生成二维码
* @param request
* @param response
* @return
* @throws UnsupportedEncodingException
*/
public ModelAndView getQCIMG(HttpServletRequest request,HttpServletResponse response) throws UnsupportedEncodingException {
String id = request.getParameter("id");
// 获取实体类信息
LicenceManageInfo licence = licenceManageInfoService.editLicenceManageInfoById(id);
String content = "http://ip:port或域名/licencemanageinfoopen/getQCodeDate.do?id="+id;
request.setAttribute("content", content);
QrConfig config = new QrConfig(300, 300);
// 设置边距,既二维码和背景之间的边距
config.setMargin(3);
// // 设置前景色,既二维码颜色(青色)
// config.setForeColor(Color.black.getRGB());
// // 设置背景色(灰色)
// config.setBackColor(Color.GRAY.getRGB());
// 生成二维码到文件,也可以到流
try {
ServletOutputStream outputStream = response.getOutputStream();
BufferedImage bufferedImage = QrCodeUtil.generate(content, config);
ImageIO.write(bufferedImage, "png", outputStream);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
/**
* 生成二维码
* @param request
* @param response
* @return
* @throws UnsupportedEncodingException
*/
public ModelAndView getQCodeDate(HttpServletRequest request,HttpServletResponse response) throws UnsupportedEncodingException {
String id = request.getParameter("id");
request.setAttribute("id", id);
// 获取实体类信息
LicenceManageInfo licence = licenceManageInfoService.editLicenceManageInfoById(id);
StringBuffer sb = new StringBuffer();
sb.append("证书编证书号:"+licenceNumber);sb.append("\n");
sb.append("生产者名称:"+companyName);sb.append("\n");
sb.append("注册地址:"+companyAddress);sb.append("\n");
sb.append("产品名称:"+productName);sb.append("\n");
sb.append("产品型号:"+productModel);sb.append("\n");
sb.append("涵盖型号:"+productSubModel);sb.append("\n");
sb.append("有效期:"+sdf.format(new Date(licenceEndDate)));sb.append("\n");
sb.append("发证机构:山东省农业机械试验鉴定站");sb.append("\n");
sb.append("售后服务电话:"+shhou);
String content = new String(sb.toString().getBytes("gb2312"),"ISO8859-1");
request.setAttribute("qcodeContent", content);
request.setAttribute("licenceNumber", licenceNumber);
request.setAttribute("companyName", companyName);
request.setAttribute("companyAddress", companyAddress);
request.setAttribute("productName", productName);
request.setAttribute("productModel", productModel);
request.setAttribute("productSubModel", productSubModel);
request.setAttribute("shhouTel", shhou);
request.setAttribute("licenceEndDate", sdf.format(new Date(licenceEndDate)));
return new ModelAndView("app/qcode.jsp");
}
<title>二维码</title>
</head>
<body>
<%-- <div id="qrcode" style="text-align: center;margin-top: 5px;">
<img alt="证书二维码" src="getQCIMG.do?id=${id}" id="showQRCode" height="100%" width="100%">
</div>
<input type="hidden" value="${qcodeContent}" id="qcodeContent"> --%>
<div class="panel-body" style="margin-top: 10px;">
<table class="table table-bordered table-hover detail-table" id="alternatecolor">
<tr>
<td width="35%"><h4 style="font-weight: bold;">证书编号</h4></td>
<td width="65%"><span class="tablevalue">${licenceNumber}</span></td>
</tr>
<tr>
<td width="35%"><h4 style="font-weight: bold;">生产者名称</h4></td>
<td width="65%"><span class="tablevalue">${companyName}</span></td>
</tr>
<tr>
<td width="35%"><h4 style="font-weight: bold;">注册地址</h4></td>
<td width="65%"><span class="tablevalue">${companyAddress}</span></td>
</tr>
<tr>
<td width="35%"><h4 style="font-weight: bold;">产品名称</h4></td>
<td width="65%"><span class="tablevalue">${productName}</span></td>
</tr>
<tr>
<td width="35%"><h4 style="font-weight: bold;">产品型号</h4></td>
<td width="65%"><span class="tablevalue">${productModel}</span></td>
</tr>
<tr>
<td width="35%"><h4 style="font-weight: bold;">涵盖型号</h4></td>
<td width="65%"><span class="tablevalue">${productSubModel}</span></td>
</tr>
<tr>
<td width="35%"><h4 style="font-weight: bold;">有效期</h4></td>
<td width="65%"><span class="tablevalue">${licenceEndDate}</span></td>
</tr>
<tr>
<td width="35%"><h4 style="font-weight: bold;">售后服务电话</h4></td>
<td width="65%"><span class="tablevalue">${shhouTel}</span></td>
</tr>
</table>
</div>
</body>