扫码关注官方订阅号
根据URL生成二维码,并返回到jsp页面,生成的改二维码可通过扫描得到URL跳转页面。特别说明一下:所有的url都在存在了一个集合里面,要把所有的url都变成二维码,然后在前台把这些生成的二维码都遍历出来。因为前台的每一个分享对应一个二维码。
第一次接触这个,无从下手,希望多多指教。给个方法
欢迎选择我的课程,让我们一起见证您的进步~~
google zxing 二维码生成库。
直接使用url生成即可使用了。
url
Map<EncodeHintType, Object> hints = new HashMap<>(); hints.put(EncodeHintType.CHARACTER_SET, "UTF-8"); hints.put(EncodeHintType.MARGIN, 0); BitMatrix bitMatrix = new MultiFormatWriter() .encode(url, BarcodeFormat.QR_CODE, 300, 300, hints); MatrixToImageWriter.writeToStream(bitMatrix, "png", stream);
@RequestMapping("/qr-code") public void placeQrOrder(HttpServletResponse resp) { resp.setHeader("Cache-Control", "no-store"); resp.setHeader("Pragma", "no-cache"); resp.setDateHeader("Expires", 0); resp.setContentType("image/png"); Map<EncodeHintType, Object> hints = new HashMap<>(); hints.put(EncodeHintType.CHARACTER_SET, "UTF-8"); hints.put(EncodeHintType.MARGIN, 0); BitMatrix bitMatrix = new MultiFormatWriter() .encode("https://www.google.com", BarcodeFormat.QR_CODE, 300, 300, hints); MatrixToImageWriter.writeToStream(bitMatrix, "png", resp.getOutputStream()); }
上面是一个完整的Spring例子。生成的图片直接通过http流写出去。前端直接使用<img src="/qr-code"/>显示二维码即可。
Spring
http
<img src="/qr-code"/>
http://pan.baidu.com/share/qr...最简单的,使用第三方二维码生成服务。
前端就可以实现,jquery-qrcode,使用也很简单,按照README即可。
README
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
google zxing 二维码生成库。
直接使用
url生成即可使用了。上面是一个完整的
Spring例子。生成的图片直接通过http流写出去。前端直接使用<img src="/qr-code"/>显示二维码即可。http://pan.baidu.com/share/qr...
最简单的,使用第三方二维码生成服务。
前端就可以实现,jquery-qrcode,使用也很简单,按照
README即可。