JAvaバックグラウンドでQRコードを生成してダウンロード(バイナリストリーム形式で出力)
2878 ワード
前提業務要求:フロントページにデータを展示し、ダウンロードボタンがあり、ダウンロードをクリックし、対応するデータのQRコードをダウンロードする.
まずpomでxmlファイルに依存を追加
転載先:https://www.cnblogs.com/jing5464/p/9951198.html
まずpomでxmlファイルに依存を追加
com.google.zxing
core
3.3.3
compile
com.google.zxing
javase
3.3.3
compile
,Controller ( )
@RequestMapping("/test")
public void dowanload(HttpServletRequest request,HttpServletResponse response) throws Exception {
//
String content = " :
:https://www.cnblogs.com/jing5464";
Map hints = new HashMap();
//
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
// (L--7%,M--15%,Q--25%,H--30%)
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
// , ( ), , ,
BitMatrix bitMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, 200, 200, hints);
//
response.setHeader("Content-Type","application/octet-stream");
response.setHeader("Content-Disposition", "attachment;filename=" + " .png");
OutputStream outputStream = response.getOutputStream();
MatrixToImageWriter.writeToStream(bitMatrix, "png", outputStream);
outputStream.flush();
outputStream.close();
}
, :http://ip + +
:http://1.0.0.1:9090/test
転載先:https://www.cnblogs.com/jing5464/p/9951198.html