java生成二维码(springboot maven项目)

java生成二维码(springboot maven项目)

配置pom.xml,引用google zxing jar

<!-- https://mvnrepository.com/artifact/com.google.zxing/core -->
		<dependency>
			<groupId>com.google.zxing</groupId>
			<artifactId>core</artifactId>
			<version>3.3.0</version>
		</dependency>
		<!-- https://mvnrepository.com/artifact/com.google.zxing/javase -->
		<dependency>
			<groupId>com.google.zxing</groupId>
			<artifactId>javase</artifactId>
			<version>3.3.0</version>
		</dependency>
		<!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
		<dependency>
			<groupId>com.alibaba</groupId>
			<artifactId>fastjson</artifactId>
			<version>1.2.62</version>
		</dependency>

java 代码

JSONObject jsonObject = new JSONObject();
		jsonObject.put("name1", "hao1");
		jsonObject.put("name2", "hao2");
		jsonObject.put("name2", "hao2");
		String string = jsonObject.toString();
		System.out.println(string);
		
		Map<EncodeHintType,Object> hints=new HashMap<EncodeHintType,Object>();
		hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
		
		BitMatrix bitMarix=new MultiFormatWriter().encode(string, BarcodeFormat.QR_CODE, 200, 200,hints);
	
		String path="/005_STS_ENV/";
		String name="eq.jpg";
		
		Path path2 = FileSystems.getDefault().getPath(path, name);
		
		MatrixToImageWriter.writeToPath(bitMarix, "jpg", path2);
		System.out.println("ok");

运行结果

展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 精致技术 设计师: CSDN官方博客
应支付0元
点击重新获取
扫码支付

支付成功即可阅读