生成二维码

阅读更多

1.pom.xml


		    com.google.zxing
		    core
		    3.3.0


		    com.google.zxing
		    javase
		    3.3.0

 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.前端代码

 

你可能感兴趣的:(java,二维码)