1.导入依赖
<dependency> <groupId>com.google.zxing</groupId> <artifactId>core</artifactId> <version>3.3.0</version> </dependency>
2.工具类qrcodeutils
public class QrcodeUtils { public static void downloadQrcode(String content, HttpServletResponse response, HttpServletRequest request) throws Exception { //转换字符,避免中文乱码问题 content = new String(content.getBytes("UTF-8"),"ISO-8859-1"); Hashtable<EncodeHintType, ErrorCorrectionLevel> hintMap = new Hashtable<EncodeHintType, ErrorCorrectionLevel>(); hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M); // 矫错级别 QRCodeWriter qrCodeWriter = new QRCodeWriter(); //创建比特矩阵(位矩阵)的QR码编码的字符串 BitMatrix byteMatrix = qrCodeWriter.encode(content, BarcodeFormat.QR_CODE, 900, 900, hintMap); // 使BufferedImage勾画Q