<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>javase</artifactId>
<version>3.3.2</version>
</dependency>
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.9.11</version>
</dependency>
String myGoogleStr = String.format("ndfdfd");
Map<EncodeHintType, Object> hints = new HashMap<EncodeHintType, Object>();
// 设置QR二维码的纠错级别(H为最高级别)具体级别信息
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
// 内容所使用编码
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
// 设置图片的边距
hints.put(EncodeHintType.MARGIN, 1);
// 生成矩阵
BitMatrix bitMatrix = new MultiFormatWriter().encode(myGoogleStr, BarcodeFormat.QR_CODE, width, height, hints);
OutputStream os = response.getOutputStream();// 取得输出流
MatrixToImageWriter.writeToStream(bitMatrix, "png", os);// 写入文件刷新
os.flush();
os.close();// 关闭输出流