@RequestMapping(value="createQRCode", method = RequestMethod.GET)
public void createQRCode(HttpServletRequest request, HttpServletResponse response) throws IOException {
JSONObject json = new JSONObject();
json.put("method", "get");
json.put(
"url",
"https://www.baidu.com/");
String content = json.toJSONString();// 内容
Map<EncodeHintType, Object> hints = new HashMap<EncodeHintType, Object>();
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
ServletOutputStream stream = response.getOutputStream();
int width = 200; // 图像宽度
int height = 200; // 图像高度
QRCodeWriter writer = new QRCodeWriter();
try {
BitMatrix bitMatrix = writer.encode(content, BarcodeFormat.QR_CODE, width, height, hints);
MatrixToImageWriter.writeToStream(bitMatrix, "jpeg", stream);// 输出图像
} catch (WriterException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (stream != null) {
stream.flush();
stream.close();
}
}
}
在扫二维码的时候,是跳转到了另一个界面,不过显示的是content数据,不知道是不是因为我没有给二维码添加他需要跳转到的页面的网址。我只能做到显示content数据。无法做到例如扫码调到百度网页这种功能
求大神帮忙!