生成二维码

1.pom.xml <dependency> <groupId>com.google.zxing</groupId> <artifactId>core</artifactId> <version>3.3.0</version> &...

1.pom.xml

<dependency>
		    <groupId>com.google.zxing</groupId>
		    <artifactId>core</artifactId>
		    <version>3.3.0</version>
</dependency>
<dependency>
		    <groupId>com.google.zxing</groupId>
		    <artifactId>javase</artifactId>
		    <version>3.3.0</version>
</dependency>

 2.后台代码

@RequestMapping("/imageCode.action")
	public void imageCode(HttpServletRequest request,HttpServletResponse response) {
		
		String url = "http://www.baidu.com";
        ServletOutputStream stream = null;
        try {
	        stream = response.getOutputStream();
	        QRCodeWriter writer = new QRCodeWriter();
	        BitMatrix m = writer.encode(url, BarcodeFormat.QR_CODE, 300, 300);
	        MatrixToImageWriter.writeToStream(m, "png", stream);
	    } catch (Exception e) {
	        e.printStackTrace();
	    } finally {
		    if (stream != null) {
		    	try {
					stream.flush();
					stream.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
		    }
	    }
	 }

 3.前端代码

<img src="imageCode.action">
  • 发表于 2019-09-04 10:20
  • 阅读 ( 68 )
  • 分类:网络文章

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除