长沙市天心区建设局网站做购物网站需要学数据库吗

news/2025/9/26 9:54:13/文章来源:
长沙市天心区建设局网站,做购物网站需要学数据库吗,中山建网站最好的公司,网站建设的意义与目的前言#xff1a;在日常的开发工作当中可能需要实现一个二维码小功能#xff0c;我参考了网上很多关于SpringBoot生成二维码的教程#xff0c;最终还是自己封装了一套完整生成二维码的工具类#xff0c;可以支持基础的黑白二维码、带颜色的二维码、带Logo的二维码、带颜色和… 前言在日常的开发工作当中可能需要实现一个二维码小功能我参考了网上很多关于SpringBoot生成二维码的教程最终还是自己封装了一套完整生成二维码的工具类可以支持基础的黑白二维码、带颜色的二维码、带Logo的二维码、带颜色和Logo的二维码和解析二维码五大功能还可以生成具体的二维码文件或返回Base64都是博主自己手写封装好的这边免费开源给大家一键使用只求大家一个免费的三连支持 目录 一、问题记录 二、导入pom依赖 三、QRCodeUtil工具类完整代码 四、使用示例 五、Gitee源码 六、总结 一、问题记录 这边我使用的是zxing提供的jar包生成的二维码不过有1个问题博客目前暂时未解决如果有解决的方法希望可以在评论区交流一下问题如下 二维码的内容如果设置为中文会报com.google.zxing.NotFoundException的错误这个问题博主搜索了网上很多的信息也没有找到具体的解决方案。 二、导入pom依赖 dependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependency!-- 二维码生成器依赖 --dependencygroupIdcom.google.zxing/groupIdartifactIdcore/artifactIdversion3.3.0/version/dependencydependencygroupIdcom.google.zxing/groupIdartifactIdjavase/artifactIdversion3.3.0/version/dependency!-- 常用工具类 --dependencygroupIdorg.apache.commons/groupIdartifactIdcommons-lang3/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-test/artifactIdscopetest/scope/dependency/dependencies 三、QRCodeUtil工具类完整代码 package com.example.ewm.utils;import java.awt.BasicStroke; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Image; import java.awt.Shape; import java.awt.geom.RoundRectangle2D; import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.io.OutputStream; import java.util.HashMap; import java.util.Hashtable; import java.util.Random; import javax.imageio.ImageIO;import com.google.zxing.*; import com.google.zxing.client.j2se.BufferedImageLuminanceSource; import com.google.zxing.client.j2se.MatrixToImageWriter; import com.google.zxing.common.BitMatrix; import com.google.zxing.common.HybridBinarizer; import com.google.zxing.qrcode.QRCodeWriter; import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; import com.sun.org.apache.xerces.internal.impl.dv.util.Base64; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Component;/*** author HTT*/ Component public class QRCodeUtil {/*** 编码格式*/private static final String CHARSET utf-8;/*** 二维码后缀名*/private static final String FORMAT_NAME JPG;/*** 二维码尺寸*/private static final int QRCODE_SIZE 300;/*** 插入图宽度*/private static final int WIDTH 60;/*** 插入图高度*/private static final int HEIGHT 60;/*** 插入图片* param source 文件流* param imgPath 图片路径* param needCompress 是否压缩图片* throws Exception*/private void insertImage(BufferedImage source, String imgPath, boolean needCompress) throws Exception {File file new File(imgPath);if (!file.exists()) {throw new Exception(imgPath图片文件不存在);}Image src ImageIO.read(new File(imgPath));int width src.getWidth(null);int height src.getHeight(null);// 压缩LOGOif (needCompress) {if (width WIDTH) {width WIDTH;}if (height HEIGHT) {height HEIGHT;}Image image src.getScaledInstance(width, height, Image.SCALE_SMOOTH);BufferedImage tag new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);Graphics g tag.getGraphics();// 绘制缩小后的图g.drawImage(image, 0, 0, null);g.dispose();src image;}// 插入LOGOGraphics2D graph source.createGraphics();int x (QRCODE_SIZE - width) / 2;int y (QRCODE_SIZE - height) / 2;graph.drawImage(src, x, y, width, height, null);Shape shape new RoundRectangle2D.Float(x, y, width, width, 6, 6);graph.setStroke(new BasicStroke(3f));graph.draw(shape);graph.dispose();}/*** 创建带图片的二维码核心方法如果图片路径为空不会生成图片* param content 二维码内容* param imgPath 图片路径* param needCompress 是否压缩图片* return* throws Exception*/private BufferedImage createEwm(String content, String imgPath, boolean needCompress) throws Exception {Hashtable hints new Hashtable(16);hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);hints.put(EncodeHintType.CHARACTER_SET, CHARSET);hints.put(EncodeHintType.MARGIN, 1);BitMatrix bitMatrix new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, QRCODE_SIZE, QRCODE_SIZE,hints);int width bitMatrix.getWidth();int height bitMatrix.getHeight();BufferedImage image new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);for (int x 0; x width; x) {for (int y 0; y height; y) {image.setRGB(x, y, bitMatrix.get(x, y) ? 0xFF000000 : 0xFFFFFFFF);}}if (StringUtils.isEmpty(imgPath)) {return image;}// 插入图片insertImage(image, imgPath, needCompress);return image;}/*** 创建自定义颜色和图片的二维码核心方法如果图片路径为空不会生成图片* param content 二维码内容* param imgPath 图片路径* param needCompress 是否压缩图片* param frontColor 前景色* param backgroundColor 背景色* return* throws Exception*/private BufferedImage createEwm(String content, String imgPath, boolean needCompress,int frontColor,int backgroundColor) throws Exception {Hashtable hints new Hashtable(16);hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);hints.put(EncodeHintType.CHARACTER_SET, CHARSET);hints.put(EncodeHintType.MARGIN, 1);BitMatrix bitMatrix new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, QRCODE_SIZE, QRCODE_SIZE,hints);int width bitMatrix.getWidth();int height bitMatrix.getHeight();BufferedImage image new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);for (int x 0; x width; x) {for (int y 0; y height; y) {image.setRGB(x, y, bitMatrix.get(x, y) ? frontColor : backgroundColor);}}if (StringUtils.isEmpty(imgPath)) {return image;}// 插入图片insertImage(image, imgPath, needCompress);return image;}/*** 生成带图片的二维码保存为文件如果图片路径为空不会生成图片* param content 二维码内容* param imgPath 图片路径* param destPath 存放路径* param needCompress 是否压缩图片* throws Exception*/private void generate(String content, String imgPath, String destPath, boolean needCompress) throws Exception {BufferedImage image createEwm(content, imgPath, needCompress);mkdirs(destPath);ImageIO.write(image, FORMAT_NAME, new File(destPath));}/*** 创建自定义颜色和图片的二维码保存为文件如果图片路径为空不会生成图片* param content 二维码内容* param imgPath 图片路径路径为空则只生成基础的二维码* param destPath 存放路径* param needCompress 是否压缩图片* param frontColor 前景色* param backgroundColor 背景色* 例举一些16进制的颜色代码* 0x000000 黑* 0xff0000 亮红* 0x00ff00 亮绿* 0xffff00 亮黄* 0x0000ff 亮蓝* 0xff00ff 亮紫* 0x00ffff 亮浅蓝* 0xffffff 白* 0xc6c6c6 亮灰* 0x848484 暗灰* throws Exception*/private void generate(String content, String imgPath, String destPath, boolean needCompress,int frontColor,int backgroundColor) throws Exception {BufferedImage image createEwm(content, imgPath, needCompress,frontColor,backgroundColor);mkdirs(destPath);ImageIO.write(image, FORMAT_NAME, new File(destPath));}/*** 生成带有图片的二维码并返回Base64如果图片路径为空不会生成图片* param content 二维码内容* param imgPath 图片路径* param needCompress 是否压缩图片* return* throws Exception*/private String generateBase64(String content, String imgPath, boolean needCompress) throws Exception {if (!StringUtils.isEmpty(content)) {HashMapEncodeHintType, Comparable hints new HashMap();hints.put(EncodeHintType.CHARACTER_SET, utf-8);hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);hints.put(EncodeHintType.MARGIN, 0);BufferedImage bufferedImage createEwm(content, imgPath, needCompress);ByteArrayOutputStream os new ByteArrayOutputStream();ImageIO.write(bufferedImage, FORMAT_NAME, os);String base64 Base64.encode(os.toByteArray());os.flush();os.close();return data:image/png;base64, base64;}return ;}/*** 生成带有自定义颜色和图片的二维码并返回Base64如果图片路径为空不会生成图片* param content 二维码内容* param imgPath 图片路径* param needCompress 是否压缩图片* param frontColor 前景色* param backgroundColor 背景色* return* throws Exception*/private String generateBase64(String content, String imgPath, boolean needCompress,int frontColor,int backgroundColor) throws Exception {if (!StringUtils.isEmpty(content)) {HashMapEncodeHintType, Comparable hints new HashMap();hints.put(EncodeHintType.CHARACTER_SET, utf-8);hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);hints.put(EncodeHintType.MARGIN, 0);BufferedImage bufferedImage createEwm(content, imgPath, needCompress,frontColor,backgroundColor);ByteArrayOutputStream os new ByteArrayOutputStream();ImageIO.write(bufferedImage, FORMAT_NAME, os);String base64 Base64.encode(os.toByteArray());os.flush();os.close();return data:image/png;base64, base64;}return ;}/*** 创建多级目录* param destPath*/private void mkdirs(String destPath) {File file new File(destPath);if (!file.exists() !file.isDirectory()) {file.mkdirs();}}/*** 根据文件解析二维码* param file* return* throws Exception*/private String analysis(File file) throws Exception {BufferedImage image;image ImageIO.read(file);if (image null) {return null;}BufferedImageLuminanceSource source new BufferedImageLuminanceSource(image);BinaryBitmap bitmap new BinaryBitmap(new HybridBinarizer(source));HashMap hints new HashMapDecodeHintType, Object();hints.put(DecodeHintType.CHARACTER_SET, CHARSET);Result result new MultiFormatReader().decode(bitmap, hints);String resultStr result.getText();return resultStr;}/*******************************************************以下是创建二维码提供的方法封装*******************************************************//******************************另存为文件版本******************************//*** 创建基础的二维码* param content 二维码内容* param destPath 存放路径* throws Exception*/public void create(String content, String destPath) throws Exception {generate(content, null, destPath, false);}/*** 创建带颜色基础的二维码* param content 二维码内容* param destPath 存放路径* throws Exception*/public void create(String content, String destPath,int frontColor,int backgroundColor) throws Exception {generate(content, null, destPath, false,frontColor,backgroundColor);}/*** 创建带图片的二维码* param content 二维码内容* param imgPath 图片路径* param destPath 存放路径* param needCompress 是否压缩图片* throws Exception*/public void create(String content, String imgPath, String destPath,boolean needCompress) throws Exception {generate(content, imgPath, destPath, needCompress);}/*** 创建带有自定义颜色和图片的二维码* param content 二维码内容* param imgPath 图片路径* param destPath 存放路径* param needCompress 是否压缩图片* param frontColor 前景色* param backgroundColor 背景色* throws Exception*/public void create(String content, String imgPath, String destPath,boolean needCompress,int frontColor,int backgroundColor) throws Exception {generate(content, imgPath, destPath, needCompress,frontColor,backgroundColor);}/******************************另存为文件版本******************************//******************************Base64版本******************************//*** 创建基础的二维码并返回Base64* param content* throws Exception*/public String create(String content) throws Exception {return generateBase64(content,null,false);}/*** 创建带颜色基础的二维码并返回Base64* param content* throws Exception*/public String create(String content,int frontColor,int backgroundColor) throws Exception {return generateBase64(content,null,false,frontColor,backgroundColor);}/*** 创建带图片的二维码并返回Base64* param content 二维码内容* param imgPath 图片路径* param needCompress 是否压缩图片* throws Exception*/public String create(String content, String imgPath,boolean needCompress) throws Exception {return generateBase64(content, imgPath, needCompress);}/*** 创建带有自定义颜色和图片的二维码并返回Base64* param content 二维码内容* param imgPath 图片路径* param needCompress 是否压缩图片* param frontColor 前景色* param backgroundColor 背景色* throws Exception*/public String create(String content, String imgPath,boolean needCompress,int frontColor,int backgroundColor) throws Exception {return generateBase64(content, imgPath, needCompress,frontColor,backgroundColor);}/******************************Base64版本******************************//*** 根据文件路径解析二维码* param path 文件路径* return* throws Exception*/public String decode(String path) throws Exception {File file new File(path);if(!file.exists()){throw new Exception(文件不存在);}return analysis(file);}} 四、使用示例 友情提醒代码中的布尔值是代表Logo图片是否需要被压缩如果是true说明嵌入的Logo图片需要被压缩我的建议是默认为true因为如果不压缩在使用decode解析带Logo的二维码的时候会报com.google.zxing.NotFoundException的错误博主亲自测试过。 单元测试 SpringBootTest class EwmApplicationTests {Resourceprivate QRCodeUtil qrCodeUtil;Testvoid contextLoads() throws Exception {qrCodeUtil.create(httstudy,F:\\基础二维码.jpg);qrCodeUtil.create(httstudy,F:\\带颜色的二维码.jpg,0xff0000,0xffff00);qrCodeUtil.create(httstudy,F:\\Logo.png,F:\\带logo的二维码.jpg,true);qrCodeUtil.create(httstudy,F:\\Logo.png,F:\\带颜色和logo的二维码.jpg,true,0xff0000,0xffff00);String str qrCodeUtil.create(httstudy);String str2 qrCodeUtil.create(httstudy,0xff0000,0xffff00);String str3 qrCodeUtil.create(httstudy,F:\\Logo.png,true);String str4 qrCodeUtil.create(httstudy,F:\\Logo.png,true,0xff0000,0xffff00);System.out.println(str);System.out.println(str2);System.out.println(str3);System.out.println(str4);String result qrCodeUtil.decode(F:\\基础二维码.jpg);String result2 qrCodeUtil.decode(F:\\带颜色的二维码.jpg);String result3 qrCodeUtil.decode(F:\\带logo的二维码.jpg);String result4 qrCodeUtil.decode(F:\\带颜色和logo的二维码.jpg);System.out.println(result);System.out.println(result2);System.out.println(result3);System.out.println(result4);}} 运行结果 五、Gitee源码 码云地址SpringBoot生成二维码完整工具类分享 六、总结 良心博主原创封装不易把常见场景需要用到的二维码类型都给大家封装好了只要像单元测试那样一键生成就好了如有问题欢迎评论区留言

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

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

相关文章

网站建设设计费用手机怎么制作网站网址

gulp需要全局安装和当前目录都安装才能使用gulp命令 安装gulp插件 npm install gulp-rev gulp-rev-replace gulp-useref gulp-filter gulp-uglify gulp-csso --save-dev gulp-rev:给每个文件添加版本号,根据文件内容计算hash码,修改文件名&am…

可信网站服务周村网站制作价格低

【高并发】高并发环境下如何防止Tomcat内存溢出?看完我懂了!!发布时间:2020-04-19 00:47,浏览次数:126, 标签:Tomcat写在前面随着系统并发量越来越高,Tomcat所占用的内存就会越来越大&#xff0…

云主机如何做网站宜宾建设教育培训中心网站

YOLO v3可以说是单阶段检测器中的佼佼者,融合了多个框架的优势,在保持模型简洁性的同时,性能上也在当时达到了stoa。YOLO v3的主干网络是darknet-53的前面的52层,所以它是一个全卷积网络,并且为了降低池化带来的梯度负…

鸿蒙自定义弹出框响应式更新数据

鸿蒙自定义弹出框响应式更新数据1.原因: openCustomDialog不支持自定义组件使用@Reusable、@Link、@Provide、@Consume等装饰器,来同步弹出框弹出的页面与ComponentContent中自定义组件的状态 2.解决class Params { …

CCS开发环境和TMS320系列DSP实现IP-IQ谐波与无功电流检测

CCS开发环境和TMS320系列DSP实现IP-IQ谐波与无功电流检测一、系统架构设计 1. 硬件组成 +-------------------+| 三相电网 || (电压/电流互感器) |+--------+----------+|v +-------------------+ +---…

深入解析:Python数据分析:求矩阵的秩。啥是矩阵秩?听故事学线代并用Python实现,娘来太容易学会了!

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

多机动模型PHD滤波算法

一、算法框架与核心思想 多机动模型PHD(Probability Hypothesis Density)滤波结合了交互多模型(IMM)与概率假设密度滤波的优势,通过动态模型切换实现多机动目标跟踪。 关键特性:多模型交互:每个粒子携带模型索引…

Navicat17无限试用重置14天

若navicat 17安装后无法正常注册,则可以尝试以下方法。 把以下文本另存为.bat文件,每次执行,都会将试用剩余天数重置为14天,实现无限试用的目的。 本脚本主要以测试学习为目的用后请及时删除,如果需要请购买正版.…

基于Electron的Web打印解决方案:web-print-pdf技术分享

引言 在Web应用开发中,打印功能一直是一个令人头疼的问题。传统的Web打印方案存在样式丢失、兼容性差、功能单一等诸多痛点。最近偶然发现了一个名为web-print-pdf的npm包,在调查了几款常见的Web打印实现后,发现大多…

CF455D Serega and Fun

洛谷传送 看起来很能分块啊!然后一个分块吧唧一下拍上去就过了。 好的我们还是来看看平衡树做法。 我们考虑每次操作是什么。发现其实是把 \(a_r\) 的位置移到了 \(a_l\) 的前面,\(a_i\sim a_{r-1}\) 内的所有元素向…

实验任务1

实验任务1实验任务11 #include<stdio.h> 2 int main() 3 { 4 printf(" O \n"); 5 printf("<H>\n"); 6 printf("I I\n"); 7 return 0; 8 }View Code 截图task 21 #include&l…

实验任务

实验任务实验任务11 #include <stdio.h>2 int main()3 {4 printf(" O \n");5 printf("<H>\n");6 printf("I I\n");7 printf(" O \n");8 pri…

61.【.NET8 实战--孢子记账--从单体到微服务--转向微服务】--新增功能--提取金额 - 实践

61.【.NET8 实战--孢子记账--从单体到微服务--转向微服务】--新增功能--提取金额 - 实践pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important…

使用 Ansible 部署 Elasticsearch 集群

使用 Ansible 部署 Elasticsearch 集群1. 集群规划 1.1 服务器列表IP 主机名 内存(GB) CPU核数 磁盘 操作系统 CPU 架构 备注11.0.0.11 arc-dev-dc01 8 1 500GB CentOS 7.9.2009 x86_64 Ansible 管理机,无法访问互联…

免费无广告!这款开源工具让文件转换像复制粘贴一样简单!

FileConverter —— 一个非常简单的工具,通过使用 Windows 资源管理器的上下文菜单转换和压缩一个或多个文件。大家好,我是 Java陈序员。 之前,给大家介绍一款格式转换全能王,支持超过一千多种的文件格式转换。 格…

时序InSAR形变结果合并操作说明 - ENVI

采用PS-InSAR或SBAS-InSAR对同一个地区得到不同时间段内的形变结果,有时候我们需要将这些不同时间段内形变结果进行合并,得到以最早时间点为基准、覆盖整个时间跨度的形变结果。 SARscape从5.5.3版本开始提供栅格或矢…

建设网站的基本技术网络规划设计师教程pdf

主题 进程同步与进程互斥 01进程同步 问题在多道批处理系统中&#xff0c;多个进程是并发执行的&#xff0c;而并发执行的进程具有异步性&#xff0c;也就是说&#xff0c;各个进程以各自独立的、不可预知的速度向前推进。这样会带来什么问题呢&#xff1f;如果有 AB…

北京建网站需要多少钱动漫网站html

一、 python语法 1. 请说一下你对迭代器和生成器的区别&#xff1f; 2. 什么是线程安全&#xff1f; 3. 你所遵循的代码规范是什么&#xff1f;请举例说明其要求&#xff1f; 4. Python中怎么简单的实现列表去重&#xff1f; 5. python 中 yield 的用法…

深圳seo网站优化公司360公司官网首页

Unity3D 小案例 像素贪吃蛇 第二期 蛇的觅食 像素贪吃蛇 食物生成 在场景中创建一个 2D 正方形&#xff0c;调整颜色&#xff0c;添加 Tag 并修改为 Food。 然后拖拽到 Assets 文件夹中变成预制体。 创建食物管理器 FoodManager.cs&#xff0c;添加单例&#xff0c;可以设置…

网站建设软硬件要求江西省建设招标网站

一 ISN序列号探究 本文主要探究三次握手建立TCP连接的细节备注&#xff1a; 某些问题探究的比较深入,当前用不到,暂时通过链接引入进来吃水不忘挖井人&#xff1a; 小林 coding ① 初始序列号 ISN 是如何随机产生的 ISN: 初始化序列号 Initial Sequence Number 接收方和…