为数据列表的每条记录生成对应的二维码

news2024/10/6 18:22:10

效果图:

一、前端

<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('固定资产信息列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>资产名称:</label>
                                <input type="text" name="zcmc"/>
                            </li>
                            <li>
                                <label>资产型号:</label>
                                <input type="text" name="zcxh"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="biz:gdzcxx:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="biz:gdzcxx:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="biz:gdzcxx:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="biz:gdzcxx:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var qrcodeFlag = [[${@permission.hasPermi('biz:gdzcxx:createQRCode')}]];
        var editFlag = [[${@permission.hasPermi('biz:gdzcxx:edit')}]];
        var removeFlag = [[${@permission.hasPermi('biz:gdzcxx:remove')}]];
        var prefix = ctx + "biz/gdzcxx";

        //生成二维码
        function createQRCode(id){
            $.ajax({
                url: prefix + "/createQRCode",
                data: {gdzcxxid:id},
                type: 'POST',
                success: function (result) {
                    $.table.refresh();
                }
            });
        }
        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "固定资产信息",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'gdzcxxId',
                    title: '资产ID'
                },
                {
                    field: 'zcmc',
                    title: '资产名称'
                },
                {
                    field: 'zcxh',
                    title: '资产型号'
                },
                {
                    field: 'ewm',
                    title: '二维码',
                    formatter:function(value, row, index){
                        var imageDataUrl = 'data:image/png;base64,' + value;
                        return "<img src='"+imageDataUrl+"' width='100' height='100' />";
                    }
                },
                {
                    field: 'bz',
                    title: '备注'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.gdzcxxId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.gdzcxxId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        actions.push('<a class="btn btn-success btn-xs ' + qrcodeFlag + '" href="javascript:void(0)" onclick="createQRCode(\'' + row.gdzcxxId + '\')"><i class="fa fa-edit"></i>生成二维码</a> ');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
    </script>
</body>
</html>

二、后端


        <!--二维码-->
        <dependency>
            <groupId>com.google.zxing</groupId>
            <artifactId>core</artifactId>
            <version>3.4.1</version>
        </dependency>
        <dependency>
            <groupId>com.google.zxing</groupId>
            <artifactId>javase</artifactId>
            <version>3.4.1</version>
        </dependency>
@Controller
@RequestMapping("/biz/gdzcxx")
public class BizGdzcxxController extends BaseController
{
    private String prefix = "biz/gdzcxx";
    /**
     * 创建二维码
     */
    @RequiresPermissions("biz:gdzcxx:createQRCode")
    @PostMapping("/createQRCode")
    public String createQRCode(String gdzcxxid) throws IOException, WriterException {
        
        //根据ID取记录,并为其生成二维码
        BizGdzcxx bizGdzcxx = bizGdzcxxService.selectBizGdzcxxByGdzcxxId(Long.valueOf(gdzcxxid));

        QRCode qrCode = new QRCode();

        //二维码物理存放路径
        String uploadPath = "D:/qrcode";
        qrCode.setFilePath(uploadPath + "/ewm/gdzcxx/" + bizGdzcxx.getZcmc() + ".png");
        
        //二维码内容:http://localhost:8088/prefix/info/1
        qrCode.setQrCodeData("/" + prefix + "/info/" + bizGdzcxx.getGdzcxxId());
        
        //创建二维码
        qrCodeService.createQRCode(qrCode);

        //将二维码转二进制
        FileInputStream fis = new FileInputStream(qrCode.getFilePath());
        byte[] bytes = FileCopyUtils.copyToByteArray(fis);

        //二进制入库
        bizGdzcxx.setEwm(bytes);
        bizGdzcxxService.updateBizGdzcxx(bizGdzcxx);
        
        return prefix + "/gdzcewm";
    }

import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.WriterException;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import com.chenf.biz.domain.QRCode;
import com.chenf.biz.service.IQRCodeService;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;

@Service
public class QRCodeServiceImpl implements IQRCodeService {
    @Override
    public void createQRCode(QRCode qrCode) throws IOException, WriterException {
        QRCodeWriter qrCodeWriter = new QRCodeWriter();

        Map<EncodeHintType, Object> hintMap = new HashMap<>();
        hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
        hintMap.put(EncodeHintType.CHARACTER_SET, qrCode.getCharset());

        BitMatrix matrix = qrCodeWriter.encode(new String(qrCode.getQrCodeData().getBytes(qrCode.getCharset()), qrCode.getCharset()),
        //BitMatrix matrix = qrCodeWriter.encode(qrCode.getQrCodeData(),
                BarcodeFormat.QR_CODE, qrCode.getQrCodeWidth(), qrCode.getQrCodeHeight(), hintMap);
        Path path = Paths.get(qrCode.getFilePath());
        if (!Files.exists(path)) {
            try {
                Files.createDirectories(path);
                System.out.println("Path created!");
            } catch (Exception e) {
                System.out.println("An error occurred while creating the path: " + e.getMessage());
            }
        } else {
            System.out.println("Path already exists!");
        }
        MatrixToImageWriter.writeToPath(matrix, qrCode.getFilePath().substring(qrCode.getFilePath().lastIndexOf('.') + 1), path);
    }
}
import com.google.zxing.WriterException;
import com.chenf.biz.domain.QRCode;

import java.io.IOException;

public interface IQRCodeService {
    void createQRCode(QRCode qrCode) throws IOException, WriterException;
}

/**
 * 二维码
 */
public class QRCode {
    //二维码内容
    private String qrCodeData;
    //二维码存放路径
    private String filePath;
    private String charset="UTF-8";
    //二维码调度
    private int qrCodeHeight=200;
    //二维码宽度
    private int qrCodeWidth=200;

    public String getQrCodeData(){return this.qrCodeData;}
    public void setQrCodeData(String qrCodeData){ this.qrCodeData = qrCodeData;}
    public String getFilePath(){return this.filePath;}
    public void setFilePath(String filePath){ this.filePath = filePath;}
    public String getCharset(){return this.charset;}
    public void setCharset(String charset){ this.charset = charset;}
    public int getQrCodeHeight(){return this.qrCodeHeight;}
    public void setQrCodeHeight(int qrCodeHeight){ this.qrCodeHeight = qrCodeHeight;}
    public int getQrCodeWidth(){return this.qrCodeWidth;}
    public void setQrCodeWidth(int qrCodeWidth){ this.qrCodeWidth = qrCodeWidth;}
}

《完结》

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1093151.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

CA与区块链之数字签名详解

CA与区块链验证本质上都是数字签名&#xff0c;首先&#xff0c;我们看一下什么是数字签名&#xff01; 数字签名 数字签名是公钥密码学中的一种技术&#xff0c;用于验证信息的完整性和发送者的身份。简而言之&#xff0c;数字签名是一种确认信息来源和信息完整性的手段。它通…

沉睡的木乃伊:var_export() 与可解析字符串

文章目录 参考环境var_export()概念应用场景数据持久化调试 函数 var_export() 自定义类__set_state() 魔术方法设置 __set_state 魔术方法的逻辑以复原对象注意事项 通用内置空类 stdClassstdClass对 __set_state() 的天然支持 参考 项目描述搜索引擎Bing、GoogleAI 大模型文…

UI自动化测试 —— Jenkins配置

前一段时间帮助团队搭建了UI自动化环境&#xff0c;这里将Jenkins环境的一些配置分享给大家。 背景&#xff1a; 团队下半年的目标之一是实现自动化测试&#xff0c;这里要吐槽一下&#xff0c;之前开发的测试平台了&#xff0c;最初的目的是用来做接口自动化测试和性能测试&…

数睿通2.0:高效的数据处理,主数据与数据表功能全面升级

引言 八天很短&#xff0c;七天很长&#xff0c;数睿通 2.0 数据中台也随之迎来了新一轮的版本迭代&#xff0c;本次更新主要包括&#xff1a; 主数据模型&#xff08;可视化建模&#xff09;主数据派发&#xff08;支持派发主数据到下游数据表&#xff0c;rabbitMq&#xff…

字节码学习之常见java语句的底层原理

文章目录 前言1. if语句字节码的解析 2. for循环字节码的解析 3. while循环4. switch语句5. try-catch语句6. i 和i的字节码7. try-catch-finally8. 参考文档 前言 上一章我们聊了《JVM字节码指令详解》 。本章我们学以致用&#xff0c;聊一下我们常见的一些java语句的特性底层…

苍穹外卖(四) AOP切面公共字段自动填充及文件上传

一.AOP切面公共字段填充 问题分析 如果都按照上述的操作方式来处理这些公共字段, 需要在每一个业务方法中进行操作, 编码相对冗余、繁琐&#xff0c;那能不能对于这些公共字段在某个地方统一处理&#xff0c;来简化开发呢&#xff1f; 答案是可以的&#xff0c;我们使用AOP切…

Redis订阅和发布

Redis订阅和发布 一、订阅者和发布者二、使用示例三、常用命令 一、订阅者和发布者 发布者&#xff1a;publish&#xff0c;发送消息订阅者&#xff1a;subscribe&#xff0c;接收消息 如下图所示&#xff0c;可以有多个订阅者订阅同一个频道&#xff0c;如果该频道发送消息&…

【RocketMQ系列一】初识RocketMQ

您好&#xff0c;我是码农飞哥&#xff08;wei158556&#xff09;&#xff0c;感谢您阅读本文&#xff0c;欢迎一键三连哦。 &#x1f4aa;&#x1f3fb; 1. Python基础专栏&#xff0c;基础知识一网打尽&#xff0c;9.9元买不了吃亏&#xff0c;买不了上当。 Python从入门到精…

thinkphp6入门(9)-- 获取url路径中的应用名、控制器名、操作名

如果使用了多应用模式&#xff0c;可以通过下面的方法来获取当前应用 app(http)->getName(); 获取当前控制器 Request::controller(); 获取当前操作 Request::action(); 在中间件middleware中是无法获取控制器和操作的 需要将middleware的引入修改为 config 目录下的 ro…

计算机网络 实验六 Wireshark 抓包实验

实验目的&#xff1a; 通过实验掌握下列知识&#xff1a; 1. 掌握Wireshark抓包工具的使用。 2. 掌握建立telnet用户密码登录方式&#xff0c;并通过wireshark抓取相关信息。 3. 理解TCP的包结构&#xff0c;并掌握TCP建立连接的过程。 4. 掌握使用tftp工具&#xff0c;上…

一文带你了解以色列的当红38家网络安全公司

2014年&#xff0c;以色列出口的网络安全产品总值达60亿美金&#xff0c;占领了全球10%的网络安全市场。2014-2016年&#xff0c;微软用3.2亿美元买下数据隐私公司Adallom&#xff1b;Facebook花了1.5亿美元收购移动端数据分析公司Onavo&#xff1b;PayPal以6千万美元收下CyAct…

2023面试知识点二

1、vue双向绑定是如何实现的 原理主要通过数据劫持和发布订阅模式实现的通过Object.defineProperty()来劫持各个属性的setter&#xff0c;getter&#xff0c;监听数据的变化在数据变动时发布消息给订阅者(watcher)&#xff0c;订阅者触发响应的回调(update)更新视图。 2、ing…

非一线工程管理者的一对一沟通

一线工程管理者主要管理/领导工程师完成实际的工程任务&#xff0c;而非一线的工程管理者需要领导一线管理者&#xff0c;更多的关注团队本身&#xff0c;因此两者在做一对一沟通的时候需要有不同的关注点。原文: One-on-Ones for (Engineering) Manager of Managers 如果没有耐…

Linux该如何学习,给你支招

如果你已经确定对 Linux 产生了兴趣&#xff0c;那么接下来我们介绍一下学习 Linux 的方法。这只是自己关于学习Linux的建议。 一、如何去学习 学习大多类似庖丁解牛&#xff0c;对事物的认识一般都是由浅入深、由表及里的过程&#xff0c;循序才能渐进。学习 Linux 同样要有一…

复旦MBA魏文童:构建完备管理知识体系,助力企业数字化发展

日月光华&#xff0c;旦复旦兮&#xff01;复旦MBA如同一个巨大的磁场&#xff0c;吸引了诸多来自五湖四海、各行各业的职场精英。从初入职场的青涩懵懂到如今的独当一面专业干练&#xff0c;他们逐渐成长为职场的中坚力量&#xff0c;在各自领域内发光发热。作为新时代的青年&…

怒刷LeetCode的第27天(Java版)

目录 第一题 题目来源 题目内容 解决方法 方法一&#xff1a;位运算 第二题 题目来源 题目内容 解决方法 方法一&#xff1a;贪心算法 第三题 题目来源 题目内容 解决方法 方法一&#xff1a;二分查找 方法二&#xff1a;牛顿迭代法 方法三&#xff1a;位操作…

基于Pytest接口自动化的requests模块项目实战以及接口关联方法详解

1、基于pytest单元测试框架的规则 1.1 模块名&#xff08;即文件名&#xff09;必须以test_开头或者_test结尾 1.2 类名必须以Test开头且不能有init方法 1.3 用例名&#xff08;测试方法&#xff09;必须以test开头 同时&#xff0c;我也为大家准备了一份软件测试视频教程&…

【算法-动态规划】零钱兑换 II-力扣 518

&#x1f49d;&#x1f49d;&#x1f49d;欢迎来到我的博客&#xff0c;很高兴能够在这里和您见面&#xff01;希望您在这里可以感受到一份轻松愉快的氛围&#xff0c;不仅可以获得有趣的内容和知识&#xff0c;也可以畅所欲言、分享您的想法和见解。 推荐:kuan 的首页,持续学…

Smartforms 打印出现的问题

上半年ECC做了升级 程序代码从ECC迁移到S4 有用户反馈 打印不能用了 经过调试发现在打印程序中 竟然返回2&#xff0c;但是 smartforms ZRPT_CO_YFLL_DY又是存在的 。 然后去激活 并与 ECC对比发现问题 S4的页大小竟然这么小 找到对应的页格式 对比ECC和S4 果然是这个…

2023年中国商用服务机器人行业发展概况分析:国产机器人厂商向海外进军[图]

商用服务机器人指在非制造业的商用服务场景中&#xff0c;用来替代或辅助人类进行服务性质工作的机器人&#xff1b;常见的商用场景中&#xff0c;商用服务机器人主要分为终端配送类机器人&#xff0c;商用清洁类机器人&#xff0c;引导讲解类机器人等&#xff0c;被广泛应用在…