生成二维码需要的依赖:
<!-- 生成二维码需要的jar包 -->
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>javase</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>core</artifactId>
<version>3.0.0</version>
</dependency>
代码如下:
public class QRCode {
@GetMapping("/test")
public void dowanload(HttpServletRequest request, HttpServletResponse response) throws Exception {
// 二维码中包含的信息
String content = "需要传的内容";
Map<EncodeHintType, Object> hints = new HashMap<EncodeHintType, Object>();
// 指定编码格式
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
// 指定纠错级别(L--7%,M--15%,Q--25%,H--30%)
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCor