如何使用速度模板生成QR码

问题描述 投票:1回答:2

我正在使用带有java的velocity模板来创建电子邮件内容。我需要在我的电子邮件模板中添加QR码,如何使用力度模板生成QR码?

java javamail velocity
2个回答
0
投票

Velocity生成文本。 QR码是图像。基本上,Velocity可以生成<img src = ...>标签,但不能生成QR码本身。

您将不得不使用QRGen等QR码生成器来生成QR码。


0
投票
String Cus_Name = (String) cmbCus_NameAdd.getSelectedItem();
String Cus_Id = lblCus_IDAdd2.getText();
String Odr_No = lblOrderNoAdd2.getText();
String Matir = lblMeterialAdd2.getText();
String amount = txtNoOfProductAdd.getText();
String date = lblDateAdd2.getText();
String time = lblTimeAdd2.getText();
String place = (String) cmbPlaceAdd.getSelectedItem();

String newLine = System.getProperty("line.separator");
String Details = "Customer Name - " + Cus_Name + "" + newLine + " Customer ID - " + Cus_Id + "" + newLine + " Order No - " + Odr_No + "" + newLine + " Material - " + Matir + "" + newLine + " Amount - " + amount + "" + newLine + " Date - " + date + "" + newLine + " Time - " + time + "" + newLine + " Place - " + place + "";

ByteArrayOutputStream out = QRCode.from(Details).to(ImageType.JPG).stream(); // this line creates QR code
File f = new File("C:\\Users\\Pulasthi Dinusha\\Desktop\\MainGui\\lib\\QR_Generator_Libs\\" + Odr_No + ".jpg");
FileOutputStream fos;
try {
    fos = new FileOutputStream(f);
    fos.write(out.toByteArray());
    fos.flush();

} catch (FileNotFoundException ex) {
    Logger.getLogger(test2.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
    Logger.getLogger(test2.class.getName()).log(Level.SEVERE, null, ex);
}
ImageIcon iconLogo = new ImageIcon("C:\\Users\\Pulasthi Dinusha\\Desktop\\MainGui\\lib\\QR_Generator_Libs\\" + Odr_No + ".jpg");
// In init() method write this code
lblQRcodeAdd.setIcon(iconLogo);
© www.soinside.com 2019 - 2024. All rights reserved.