引入依赖
com.google.zxing
javase
3.3.0
写一个requestmapping
@GetMapping(value = “/code”)
public void myQrcode(HttpServletResponse response) throws Exception {
String infomation = “我的第一张二维码”;
BitMatrix matrix;
Map<EncodeHintType, String> param = new HashMap<>();
param.put(EncodeHintType.CHARACTER_SET, “UTF-8”);
matrix = new MultiFormatWriter().encode(infomation, BarcodeFormat.QR_CODE, 450, 450, param);
response.setDateHeader(“Expires”, 0);
response.setContentType(“image/png”);
response.setHeader(“Pragma”, “no-cache”);
response.setHeader(“Cache-Control”, “no-store”);
// 将二维码输出到页面中
MatrixToImageWriter.writeToStream(matrix, “png”, response.getOutputStream());
}
访问url得到