前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >开源!一款基于Spring Boot的二维码生成和解析工具

开源!一款基于Spring Boot的二维码生成和解析工具

作者头像
闫同学
发布2022-10-31 15:04:11
4420
发布2022-10-31 15:04:11
举报
文章被收录于专栏:扯编程的淡

之前闲暇时间写过的一款二维码生成和解析工具,目前基本功能已经完成并开始使用。

1 概览

设计技术点:

  • Spring Boot(restful API)
  • zxing

readme:

2 项目截图

2.1 体验地址

http://59.110.25.8:8080/tools/

2.2 截图

3 部分代码

枚举:

代码语言:javascript
复制
package org.ymx.sb_qr_code.enums;import lombok.Getter;/**
 * @desc: 图片大小枚举
 * @author: YanMingXin
 * @create: 2022/6/2-20:15
 **/@Getterpublic enum ImgSize {

    MINI(80, 80), SMALL(120, 120), MIDDLE(200, 200), BIG(500, 500);

    int width;

    int height;

    ImgSize(int width, int height) {
        this.width = width;
        this.height = height;
    }

    @Override
    public String toString() {
        return "ImgSize{" +
                "width=" + width +
                ", height=" + height +
                '}';
    }}

service层实现类

代码语言:javascript
复制
package org.ymx.sb_qr_code.service.impl;import org.springframework.beans.factory.annotation.Value;import org.springframework.stereotype.Service;import org.springframework.util.ObjectUtils;import org.ymx.sb_qr_code.service.ZXingService;import org.ymx.sb_qr_code.utils.ZXingUtil;import org.springframework.web.multipart.MultipartFile;import java.io.File;import java.io.IOException;import java.util.UUID;/**
 * @desc: Service文件处理
 * @author: YanMingXin
 * @create: 2022/6/2-19:22
 **/@Servicepublic class ZXingServiceImpl implements ZXingService {

    @Value("${file.upload.path}")
    private String imgPath;

    @Override
    public String encodeImg(String format, String content, int width, int height, String logo) {
        String fileName = UUID.randomUUID() + "." + format;
        String text = content;
        if (ObjectUtils.isEmpty(content)) {
            text = "null";
        }
        if (!ObjectUtils.isEmpty(logo)) {
            logo = imgPath + logo;
        }
        String path = imgPath + fileName;
        try {
            ZXingUtil.encodeImg(path, format, text, width, height, logo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return fileName;
    }

    @Override
    public String decodeImg(File file) {
        String content = null;
        try {
            content = ZXingUtil.decodeImg(file);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return content;
    }}

4 获取方式

关注下方公众号【扯编程的淡】,回复【二维码】即可获取

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2022-07-05,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 扯编程的淡 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1 概览
  • 2 项目截图
    • 2.1 体验地址
      • 2.2 截图
      • 3 部分代码
      • 4 获取方式
      领券
      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档