1.jar 包 maven:
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>core</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>javase</artifactId>
<version>3.0.0</version>
</dependency>
2.代码
int width=300;
int height=300;
String format="png";
String content="傻逼";
//定义二维码参数
HashMap code = new HashMap();
code.put(EncodeHintType.CHARACTER_SET, "utf-8");
code.put(EncodeHintType.MARGIN, 2);
try{
BitMatrix encode = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, width, height,code);
Path file = new File("D:/test/img.png").toPath();
MatrixToImageWriter.writeToPath(encode,format,file);
}catch(Exception e){
e.printStackTrace();
}