# 3.9 renderQrCode QR code generation

# 1. Usage of renderQrCode

Generating QR codes using renderQrCode is extremely simple and convenient. Here's a common use case:

// Data carried by the QR code
String data = "weixin://wxpay/bizpayurl?appid=xx&mch_id=xx......";
 
// Render the QR code image with a length and width of 200 pixels
renderQrCode(data, 200, 200);
1
2
3
4
5

In the above example, the data represents the information carried by the QR code. This information will be read by a QR code scanner.

Furthermore, renderQrCode allows you to specify the "error correction level" of the QR code. For example:

// The last parameter 'M' denotes the error correction level
renderQrCode(data, 200, 200, 'M');
1
2

The error correction parameter ensures that the QR code can still be read correctly even if a part of it is obscured or damaged.

The error correction levels in descending order of robustness are: 'H', 'Q', 'M', and 'L'. Their respective error correction rates are: 30%, 25%, 15%, and 7%. If this parameter is not specified, the default is 'L'.

# 2. Maven Dependency

To use the renderQrCode method, you need to introduce a third-party dependency. Here's the Maven dependency:

<dependency>
    <groupId>com.google.zxing</groupId>
    <artifactId>javase</artifactId>
    <version>3.2.1</version>
</dependency>
1
2
3
4
5

With this dependency, you'll be able to generate QR codes seamlessly in your JFinal application. QR codes are widely used in various applications, such as payments, ticketing, and more, because of their ability to encode a significant amount of data into a compact visual format.

Last Updated: 9/17/2023, 5:50:29 AM