Java Vue uni-app 三端实现,滑动拼图验证码

2023-05-16

一步一步实现 图片滑动验证码

项目中要使用 图片滑动验证码,顾了解之

需要以下几步来完成:

1.后端随机计算抠图的距离,生成背景与拼图块的图片,缓存 拼图块需 滑动的距离像素。

2.前端加载背景图 和 浮动框,通过拖动条拖动,后台进行验证。

项目需求,满足PC和移动Web调用:

此时要考虑PC和不同移动设备Web端的图形大小,防止变形。

参考【小红书】的滑块验证

在这里插入图片描述

后端生成 600* 300的背景图,浮动层 90*300。 它的浮动层模板 高度是和原图一致的,可省去计算高度的过程。

PC端缩放如: 400 *200,

移动端:288*144、 300 * 150

生成背景和滑动块的工具类:


import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.Transparency;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;

import javax.imageio.ImageIO;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.util.Base64Utils;


/**
 * 滑动验证码
 */
public class VerifyImageUtil {

    private final static  Logger log = LogManager.getLogger(VerifyImageUtil.class);
    private static int BOLD = 5;
    private static final String IMG_FILE_TYPE = "jpg";
    private static final String TEMP_IMG_FILE_TYPE = "png";

    /**
     * 根据模板切图
     *
     * @param templateFile
     * @param targetFile
     * @return
     * @throws Exception
     */
    public static Map<String, Object> pictureTemplatesCut(File templateFile, File targetFile) throws Exception {
        Map<String, Object> pictureMap = new HashMap<>();
        // 模板图
        BufferedImage imageTemplate = ImageIO.read(templateFile);
        int templateWidth = imageTemplate.getWidth();
        int templateHeight = imageTemplate.getHeight();

        // 原图
        BufferedImage oriImage = ImageIO.read(targetFile);
        int oriImageWidth = oriImage.getWidth();
        int oriImageHeight = oriImage.getHeight();

        //随机生成抠图坐标X,Y
        //X轴距离右端targetWidth  Y轴距离底部targetHeight以上
        Random random = new Random();
        int widthRandom = random.nextInt(oriImageWidth - 2 * templateWidth) + templateWidth;
        int heightRandom = 0;
        // 新建一个和模板一样大小的图像,TYPE_4BYTE_ABGR表示具有8位RGBA颜色分量的图像,正常取imageTemplate.getType()
        BufferedImage newImage = new BufferedImage(templateWidth, templateHeight, imageTemplate.getType());
        //得到画笔对象
        Graphics2D graphics = newImage.createGraphics();
        //如果需要生成RGB格式,需要做如下配置,Transparency 设置透明
        newImage = graphics.getDeviceConfiguration().createCompatibleImage(templateWidth, templateHeight, Transparency.TRANSLUCENT);

        // 新建的图像根据模板颜色赋值,源图生成遮罩
        cutByTemplate(oriImage, imageTemplate, newImage, widthRandom, heightRandom);

        // 设置“抗锯齿”的属性
        graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        graphics.setStroke(new BasicStroke(BOLD, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
        graphics.drawImage(newImage, 0, 0, null);
        graphics.dispose();
        //新建流。
        ByteArrayOutputStream newImageOs = new ByteArrayOutputStream();
        //利用ImageIO类提供的write方法,将bi以png图片的数据模式写入流。
        ImageIO.write(newImage, TEMP_IMG_FILE_TYPE, newImageOs);
        byte[] newImagebyte = newImageOs.toByteArray();
        //新建流。
        ByteArrayOutputStream oriImagesOs = new ByteArrayOutputStream();
        //利用ImageIO类提供的write方法,将bi以jpg图片的数据模式写入流。
        ImageIO.write(oriImage, IMG_FILE_TYPE, oriImagesOs);
        byte[] oriImageByte = oriImagesOs.toByteArray();

        pictureMap.put("smallImage", Base64Utils.encodeToString(newImagebyte));
        pictureMap.put("bigImage", Base64Utils.encodeToString(oriImageByte));
//        System.out.println("widthRandom:" + widthRandom);
        pictureMap.put("xWidth", widthRandom);
        pictureMap.put("yHeight", heightRandom);
        return pictureMap;
    }

    /**
     * 添加水印
     * @param oriImage
     */
    /*private static BufferedImage addWatermark(BufferedImage oriImage) throws IOException {
        Graphics2D graphics2D = oriImage.createGraphics();
        graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BILINEAR);
        // 设置水印文字颜色
        graphics2D.setColor(Color.BLUE);
        // 设置水印文字Font
        graphics2D.setFont(new java.awt.Font("宋体", java.awt.Font.BOLD, 50));
        // 设置水印文字透明度
        graphics2D.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 0.5f));
        // 第一参数->设置的内容,后面两个参数->文字在图片上的坐标位置(x,y)
        graphics2D.drawString("zhoujin@qq.com", 400,300);
        graphics2D.dispose(); //释放
        return oriImage;
    }*/

    /**
     * @param oriImage      原图
     * @param templateImage 模板图
     * @param newImage      新抠出的小图
     * @param x             随机扣取坐标X
     * @param y             随机扣取坐标y
     * @throws Exception
     */
    private static void cutByTemplate(BufferedImage oriImage, BufferedImage templateImage, BufferedImage newImage, int x, int y) {
        //临时数组遍历用于高斯模糊存周边像素值
        int[][] martrix = new int[3][3];
        int[] values = new int[9];

        int xLength = templateImage.getWidth();
        int yLength = templateImage.getHeight();
        // 模板图像宽度
        for (int i = 0; i < xLength; i++) {
            // 模板图片高度
            for (int j = 0; j < yLength; j++) {
                // 如果模板图像当前像素点不是透明色 copy源文件信息到目标图片中
                int rgb = templateImage.getRGB(i, j);
                if (rgb < 0) {
                    //模板图 位置上色
                    newImage.setRGB(i, j, oriImage.getRGB(x + i, y + j));

                    //抠图区域高斯模糊
                    readPixel(oriImage, x + i, y + j, values);
                    fillMatrix(martrix, values);
                    oriImage.setRGB(x + i, y + j, avgMatrix(martrix));
                }

                //防止数组越界判断
                if (i == (xLength - 1) || j == (yLength - 1)) {
                    continue;
                }
                int rightRgb = templateImage.getRGB(i + 1, j);
                int downRgb = templateImage.getRGB(i, j + 1);
                //描边处理,,取带像素和无像素的界点,判断该点是不是临界轮廓点,如果是设置该坐标像素是白色
//                if ((rgb >= 0 && rightRgb < 0) || (rgb < 0 && rightRgb >= 0) || (rgb >= 0 && downRgb < 0) || (rgb < 0 && downRgb >= 0)) {
//                    newImage.setRGB(i, j, Color.white.getRGB());
//                    oriImage.setRGB(x + i, y + j, Color.white.getRGB());
//                }
            }
        }
    }

    private static void readPixel(BufferedImage img, int x, int y, int[] pixels) {
        int xStart = x - 1;
        int yStart = y - 1;
        int current = 0;
        for (int i = xStart; i < 3 + xStart; i++) {
            for (int j = yStart; j < 3 + yStart; j++) {
                int tx = i;
                if (tx < 0) {
                    tx = -tx;

                } else if (tx >= img.getWidth()) {
                    tx = x;
                }
                int ty = j;
                if (ty < 0) {
                    ty = -ty;
                } else if (ty >= img.getHeight()) {
                    ty = y;
                }
                pixels[current++] = img.getRGB(tx, ty);

            }
        }
    }

    private static void fillMatrix(int[][] matrix, int[] values) {
        int filled = 0;
        for (int i = 0; i < matrix.length; i++) {
            int[] x = matrix[i];
            for (int j = 0; j < x.length; j++) {
                x[j] = values[filled++];
            }
        }
    }

    private static int avgMatrix(int[][] matrix) {
        int r = 0;
        int g = 0;
        int b = 0;
        for (int i = 0; i < matrix.length; i++) {
            int[] x = matrix[i];
            for (int j = 0; j < x.length; j++) {
                if (j == 1) {
                    continue;
                }
                Color c = new Color(x[j]);
                r += c.getRed();
                g += c.getGreen();
                b += c.getBlue();
            }
        }
        return new Color(r / 8, g / 8, b / 8).getRGB();
    }
}

在项目resource的目录存放背景图和浮动层模板:
在这里插入图片描述

	/**
	* 获取资源图片路径
	*/
    public List<String> queryFileList(String path) {

        //获取容器资源解析器
        ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
        List<String> filelist = new ArrayList<String>();
        // 获取远程服务器IP和端口
        try {
            //获取所有匹配的文件
            Resource[] resources = resolver.getResources(path);
            for (Resource resource : resources) {
                filelist.add(resource.getFile().getPath());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return filelist;
    }

    /**
     * 获取验证码
     *
     * VerifyImageUtil 可考虑 加强验证难度,比如【小红书】 背景图生成时 多抠图一次随机模板。
     *
     *
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getImageVerify", method = RequestMethod.GET)
    public AjaxResult getImageVerifyCode(HttpServletRequest request) {
        //bg图
        String IMG_PATH = "/image/bg/*.*";
        //模板图
        String TEMP_IMG_PATH = "/image/fg/*.*";

        // 读取背景图目录
        List<String> imgList = queryFileList(IMG_PATH);
        int randNum = new Random().nextInt(imgList.size());
        File targetFile = new File(imgList.get(randNum));
        // 读取模板目录
        List<String> tempimgList = queryFileList(TEMP_IMG_PATH);
        randNum = new Random().nextInt(tempimgList.size());
        File tempImgFile = new File(tempimgList.get(randNum));

        // 根据模板裁剪图片
        Map<String, Object> resultMap = null;
        try {
            resultMap = VerifyImageUtil.pictureTemplatesCut(tempImgFile, targetFile);            
            int xWidth = (int) resultMap.get("xWidth");        
            //缓存记录key,项目实现 redis 或者 requset seesion
            // Cached.set(key, xWidth);
            request.setAttribute("xWidth",xWidth);
            // 移除map的滑动距离,不返回给前端
            resultMap.remove("xWidth");
            //resultMap 包含 背景图片和浮动图片
            return AjaxResult.success(resultMap);

        } catch (Exception e) {
            return AjaxResult.error("获取验证码失败");
        }
    }

  /**
     * 校验滑块拼图验证码
     *
     * @param moveLength 移动距离
     * @return BaseRestResult 返回类型
     * @Description: 生成图形验证码
     */
    @RequestMapping(value = "/verifyImageCode", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public AjaxResult verifyImageCode(@RequestParam(value = "moveLength") String moveLength, HttpServletRequest request) {
        Double dMoveLength = Double.valueOf(moveLength);
        AjaxResult resultMap;
        try {
        	//从redis或者reqest中获取 横向移动的距离
            int xWidth =  request.getAttribute("xWidth");
            if (xWidth < 1) {
                resultMap = AjaxResult.error("验证过期,请重试");
            } else {
            	// 设置允许的偏差值
                if (Math.abs((int) xWidth - dMoveLength) > 10) {
                    resultMap = AjaxResult.error("验证不通过");
                } else {
                    resultMap = AjaxResult.success("验证通过");
                }
            }
        } catch (Exception e) {
            resultMap = AjaxResult.success("验证失败,请重试");
        } 
        return resultMap;
    }

我的前端vue实现,先看效果:
在这里插入图片描述
vue组件:


<template>
  <div class="slide-verify" id="slideVerify" :style="widthlable" onselectstart="return false;">
    <canvas :width="w" :height="h" ref="canvas" ></canvas>

    <canvas :width="w" :height="h" ref="block"  class="slide-verify-block"></canvas>
    <div @click="refresh" class="slide-verify-refresh-icon"></div>

    <div class="slide-verify-slider" :style="widthlable" :class="{'container-active': containerActive, 'container-success': containerSuccess, 'container-fail': containerFail}">
      <div class="slide-verify-slider-mask" :style="{width: sliderMaskWidth}">
        <!-- slider -->
        <div @mousedown="sliderDown"
             @touchstart="touchStartEvent"
             @touchmove="touchMoveEvent"
             @touchend="touchEndEvent"
             class="slide-verify-slider-mask-item"
             :style="{left: sliderLeft}">
          <div class="slide-verify-slider-mask-item-icon"></div>
        </div>
      </div>
      <span class="slide-verify-slider-text">{{sliderText}}</span>
    </div>
  </div>
</template>
<script>
const PI = Math.PI;

function sum(x, y) {
  return x + y
}

function square(x) {
  return x * x
}
export default {
  name: 'SlideVerify',
  props: {
    // block length
    l: {
      type: Number,
      default: 42,
    },
    // block radius
    r: {
      type: Number,
      default: 10,
    },
    // canvas width
    w: {
      type: Number,
      default: 310,
    },
    // canvas height
    h: {
      type: Number,
      default: 155,
    },
    block_x: {
      type: Number,
      default: 155,
    },
    block_y: {
      type: Number,
      default: 20,
    },
    // sliderText: {
    //   type: String,
    //   default: 'Slide filled right',
    // },
    imgurl: {
      type: String,
      default: '',
    },
    miniimgurl: {
      type: String,
      default: '',
    },

  },
  data() {
    return {
      containerActive: false, // container active class
      containerSuccess: false, // container success class
      containerFail: false, // container fail class
      canvasCtx: null,
      blockCtx: null,
      block: null,
      canvasStr: null,
      //block_x: undefined, // container random position
      // block_y: undefined,
      L: this.l + this.r * 2 + 3, // block real lenght
      img: undefined,
      originX: undefined,
      originY: undefined,
      isMouseDown: false,
      trail: [],
      widthlable:'',
      sliderLeft: 0, // block right offset
      sliderMaskWidth: 0, // mask width
      sliderText:'向右划'
    }
  },
  mounted() {
    //随机生成数this.block_x =
    this.init()
  },
  methods: {
    init() {
      this.initDom()
      this.bindEvents()
      this.widthlable ='width:'+this.w+'px;'
    },
    initDom() {
      this.block = this.$refs.block;
      this.canvasStr = this.$refs.canvas;

      this.canvasCtx = this.canvasStr.getContext('2d')
      this.blockCtx = this.block.getContext('2d')
    },
    initImg(h) {
      var that = this
      const img = document.createElement('img');
      img.onload = onload;
      img.onerror = () => {
        img.src = that.imgurl
      }
      img.src = that.imgurl
      img.onload = function(){
        that.canvasCtx.drawImage(img, 0, 0, that.w, that.h)
      }

      this.img=img
      const img1 = document.createElement('img');
      var  blockCtx = that.blockCtx
      var block_y = h||that.block_y
      img1.onerror = () => {
        img1.src = that.miniimgurl
      }
      img1.src = that.miniimgurl
      img1.onload = function(){
        blockCtx.drawImage(img1, 0, block_y, 60, that.h)
      }
    },
    refresh() {
      this.$emit('refresh')
    },
    sliderDown(event) {
      this.originX = event.clientX;
      this.originY = event.clientY;
      this.isMouseDown = true;
    },
    touchStartEvent(e) {
      this.originX = e.changedTouches[0].pageX;
      this.originY = e.changedTouches[0].pageY;
      this.isMouseDown = true;
    },
    bindEvents() {
      document.addEventListener('mousemove', (e) => {
        if (!this.isMouseDown) return false;
        const moveX = e.clientX - this.originX;
        const moveY = e.clientY - this.originY;
        if (moveX < 0 || moveX + 38 >= this.w) return false;
        this.sliderLeft = moveX + 'px';
        let blockLeft = (this.w - 40 - 20) / (this.w - 40) * moveX;
        this.block.style.left = blockLeft + 'px';

        this.containerActive = true; // add active
        this.sliderMaskWidth = moveX + 'px';
        this.trail.push(moveY);
      });
      document.addEventListener('mouseup', (e) => {
        if (!this.isMouseDown) return false
        this.isMouseDown = false
        if (e.clientX === this.originX) return false;
        this.containerActive = false; // remove active
        this.verify()

      })
    },
    touchMoveEvent(e) {
      if (!this.isMouseDown) return false;
      const moveX = e.changedTouches[0].pageX - this.originX;
      const moveY = e.changedTouches[0].pageY - this.originY;
      if (moveX < 0 || moveX + 38 >= this.w) return false;
      this.sliderLeft = moveX + 'px';
      let blockLeft = (this.w - 40 - 20) / (this.w - 40) * moveX;
      this.block.style.left = blockLeft + 'px';

      this.containerActive = true;
      this.sliderMaskWidth = moveX + 'px';
      this.trail.push(moveY);
    },
    touchEndEvent(e) {
      if (!this.isMouseDown) return false
      this.isMouseDown = false
      if (e.changedTouches[0].pageX === this.originX) return false;
      this.containerActive = false;
      this.verify()
    },
    verify() {
      const arr = this.trail // drag y move distance
      const average = arr.reduce(sum) / arr.length // average
      const deviations = arr.map(x => x - average) // deviation array
      const stddev = Math.sqrt(deviations.map(square).reduce(sum) / arr.length) // standard deviation
      const left = parseInt(this.block.style.left)
      this.$emit('success',left)

    },
    reset(h) {
      this.containerActive = false;
      this.containerSuccess = false;
      this.containerFail = false;
      this.sliderLeft = 0;
      this.block.style.left = 0;
      this.sliderMaskWidth = 0;
      this.canvasCtx.clearRect(0, 0, this.w, this.h)
      this.blockCtx.clearRect(0, 0, this.w,this.h)
      this.initImg(h)

    }
  }
}
</script>
<style scoped>
.slide-verify {
  position: relative;
  width: 310px;
}

.slide-verify-block {
  position: absolute;
  left: 0;
  top: 0
}

.slide-verify-refresh-icon {
  position: absolute;
  right: 0;
  top: 0;
  width: 34px;
  height: 34px;
  cursor: pointer;
  background: url(https://cstaticdun.126.net//2.13.6/images/icon_light.4353d81.png) 0 -233px;
  background-size: 32px 544px;
}

.slide-verify-slider {
  position: relative;
  text-align: center;
  width: 310px;
  height: 40px;
  line-height: 40px;
  margin-top: 15px;
  background: #f7f9fa;
  color: #45494c;
  border: 1px solid #e4e7eb
}

.slide-verify-slider-mask {
  position: absolute;
  left: 0;
  top: 0;
  height: 40px;
  border: 0 solid #1991FA;
  background: #D1E9FE
}

.slide-verify-slider-mask-item {
  position: absolute;
  top: 0;
  left: 0;
  width: 40px;
  height: 40px;
  background: #fff;
  box-shadow: 0 0 3px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  transition: background .2s linear
}

.slide-verify-slider-mask-item:hover {
  background: #1991FA
}

.slide-verify-slider-mask-item:hover .slide-verify-slider-mask-item-icon {
  background-position: 0 -13px
}

.slide-verify-slider-mask-item-icon {
  position: absolute;
  top: 15px;
  left: 13px;
  width: 14px;
  height: 12px;
  background: url("../../assets/images/light.svg") 0 -26px;
  background-size: 34px 471px
}
.container-active .slide-verify-slider-mask-item {
  height: 38px;
  top: -1px;
  border: 1px solid #1991FA;
}

.container-active .slide-verify-slider-mask {
  height: 38px;
  border-width: 1px;
}

.container-success .slide-verify-slider-mask-item {
  height: 38px;
  top: -1px;
  border: 1px solid #52CCBA;
  background-color: #52CCBA !important;
}

.container-success .slide-verify-slider-mask {
  height: 38px;
  border: 1px solid #52CCBA;
  background-color: #D2F4EF;
}

.container-success .slide-verify-slider-mask-item-icon {
  background-position: 0 0 !important;
}

.container-fail .slide-verify-slider-mask-item {
  height: 38px;
  top: -1px;
  border: 1px solid #f57a7a;
  background-color: #f57a7a !important;
}

.container-fail .slide-verify-slider-mask {
  height: 38px;
  border: 1px solid #f57a7a;
  background-color: #fce1e1;
}

.container-fail .slide-verify-slider-mask-item-icon {
  top: 14px;
  background-position: 0 -82px !important;
}

.container-active .slide-verify-slider-text,
.container-success .slide-verify-slider-text,
.container-fail .slide-verify-slider-text {
  display: none;
}
</style>

使用:

        <slideverify :l="42"  ref="dialogopen"
                     :r="10"
                     :w="400"
                     :h="200"
                     :block_y="block_y"
                     :imgurl="imgurl"
                     :miniimgurl="miniimgurl"
                     @success="onSuccess"
                     @refresh="onRefresh"
                     :slider-text="text"
        ></slideverify>
methods: {
	//获取验证码
    getImageVerifyCode: function () {
      var that = this
      getImageVerifyCodeImg().then(res => {
        if (!res || res.code != '200') {
          this.$message({
            showClose: true,
            message: '获取图形验证码失败,请重试',
            type: 'error'
          })
        } else {
          var imgobj = res.data
          that.block_y = imgobj.yHeight
          that.imgurl = 'data:image/jpg;base64,' + imgobj.bigImage
          that.miniimgurl = 'data:image/jpg;base64,' + imgobj.smallImage
        }
      })
    },
    //刷新
    onRefresh() {
      this.imgurl = ''
      this.miniimgurl = ''
      this.getImageVerifyCode()
    },
	//滑动结束,后台验证, l是滑动距离
    onSuccess(l) {
      verifyImageCode(l).then(res => {
        if (res.msg === "验证通过") {
          Message({
            message: res.msg,
            type: 'success'
          })
        } else {
          Message({
            message: res.msg,
            type: 'error'
          })
          this.onRefresh();
        }
      })

    }
  }

移动端:uni-app插件市场
图片滑动验证码
根据后台返回内容,稍加修改,效果如图:
在这里插入图片描述

后台抠图所需的模板图:
在这里插入图片描述

更多模板图从【小红书】抓取下载。
小红书滑动块验证

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Java Vue uni-app 三端实现,滑动拼图验证码 的相关文章

  • 如何用Java写入OS系统日志?

    Mac OS 有一个名为 Console 的应用程序 其中包含记录的消息 错误和故障 我相信 Windows 中的等效项是事件查看器 我想 Linux 上也有一个 但我不知道它是什么 也不知道它在哪里 是否可以像这样从 Java 输出获取消
  • 如何使用 Java 将 HTML 内容转换为 PDF 而不丢失格式?

    我有一些 HTML 内容 包括格式化标签 例如strong 图像等 在我的 Java 代码中 我想将此 HTML 内容转换为 PDF 文档 而不丢失 HTML 格式 有没有办法用 Java 来实现 使用 iText 或任何其他库 I use
  • 在 Android 中绘制一条带有弯曲边缘的线

    I am using canvas drawLine to draw some line in android but the lines are too sharp but i need a curved edges 这里的 1 是我所拥
  • java中队列的实现

    在 Java 中实现队列是一个非常常见的面试问题 我在网上冲浪 看到了许多实现 他们做了一些奇特的事情 比如实现队列接口和编写自己的addLast and removeFirst 方法 我的问题是我不能使用LinkedList 类并使用其预
  • 如果按下 Esc 则中断循环

    我用 JAVA 语言编写了一个程序 它使用 Scanner 类接受来自控制台的输入 现在我想将此功能添加到我的代码中 以便在用户按下 Esc 按钮时存在循环 while 到目前为止 我认为键盘类可以帮助我 但它就像扫描仪一样 我尝试使用事件
  • JAX-WS:有状态 WS 在独立进程中失败

    我在 Tomcat 上部署了一个有状态的 Web 服务 它由工厂服务和主要 API 服务组成 并且工作得很好 工厂服务将 W3CEndpointReference 返回到主 API 实例 客户端使用会话 现在 我尝试将相同的服务作为独立应用
  • 如何屏蔽 Protobuf 中的某些字段

    我找不到一种方法来屏蔽 protobuf 结构中的某些字段 我确实阅读了有关 FieldMaskUtil 的内容并尝试了几个示例 但它似乎做了相反的操作 即复制 FieldMask 中提到的字段 这与我想要的不同 这是示例结构和相应的测试代
  • 带有面板的 Java Swing JToolbar:外观和感觉

    我有一个JToolbar其中包含多个JPanels 需要 因为我希望每个都有特定的边界 不幸的是 外观管理器无法识别JPanels属于工具栏和JButtons因此 渲染器与普通按钮一样 即没有工具栏上的特殊鼠标悬停效果 更换JPanels
  • JavaFx 中装饰且不可移动的舞台

    我想在 JavaFx 中创建一个装饰舞台 它也将不可移动 我正在从另一个控制器类创建这个阶段 我能够创造和展示舞台 但它是自由移动的 我怎样才能创建这个 非常感谢帮助和建议 我把打开新关卡的方法贴出来 private void addRec
  • Java 中 static 关键字如何工作?

    我正在阅读Java教程 http docs oracle com javase tutorial index html从一开始我就有一个问题static字段或变量上的关键字 作为Java said here http docs oracle
  • Java 类:匿名类、嵌套类、私有类

    有人能解释一下Java中匿名类 嵌套类和私有类之间的区别吗 我想知道与每个相关的运行时成本以及每个编译器的方法 这样我就可以掌握哪个最适合用于例如性能 编译器优化的潜力 内存使用以及其他 Java 编码人员的普遍可接受性 我所说的匿名类是指
  • NoSuchMethodError:将 Firebase 与应用程序引擎应用程序集成时

    我试图将 firebase 实时数据库与谷歌应用程序引擎应用程序集成 我在调用时收到此错误 gt DatabaseReference ref FirebaseDatabase gt getInstance gt getReference t
  • 删除 ArrayList 对象问题

    我在处理作业时遇到从 ArrayList 中删除对象的问题 如果我使用 正常 for 循环 它的工作原理如下 public void returnBook String isbn for int i 0 i lt booksBorrowed
  • Hibernate @OneToMany 注释到底是如何工作的?

    我对 Hibernate 还很陌生 我正在通过教程学习它 我在理解到底如何一对多注释作品 所以我有这两个实体类 Student代表一个学生并且Guide代表指导学生的人 因此 每个学生都与一名向导相关联 但一名向导可以跟随多个学生 我想要一
  • C++ 中的 Java ArrayList [重复]

    这个问题在这里已经有答案了 在Java中我可以做 List
  • 如何在 Java 中创建要打印到 JFrame 的 JLabels 数组

    我正在尝试制作一系列标签 每个标签都有一个来自函数的不同值 我不知道要使用的标签的确切数量 我的意思是可以打印任意数量的值 请帮我做这件事 很简单 只需一个方法返回一个数组或一些 JLabels 集合 并将它们全部添加到您的 JCompon
  • 在方法内声明类 - Final 关键字 [重复]

    这个问题在这里已经有答案了 给定方法中的以下内部类 IsSomething public class InnerMethod private int x public class Something private int y public
  • 如何使用 Hibernate Session.doWork(...) 进行保存点/嵌套事务?

    我正在使用 JavaEE JPA 托管事务与 Oracle DB 和 Hibernate 并且需要实现某种嵌套事务 据我所知 此类事情不受开箱即用的支持 但我应该能够为此目的使用保存点 正如建议的https stackoverflow co
  • Java 8根据Map属性过滤Map对象列表以删除一些重复项

    Have a List
  • java中的回调是什么[重复]

    这个问题在这里已经有答案了 可能的重复 什么是回调函数 https stackoverflow com questions 824234 what is a callback function 我已经阅读了回调的维基百科定义 但我仍然没有明

随机推荐

  • 三分钟学会lightGBM安装及入门指南(一)

    果然标题大法好啊 xff0c 还是成功的让你进来了吧 xff0c xff0c 但是以下都是干货 我的机器环境python3 6 xff0c win7操作系统 xff0c 当然win10也是同样适用的 xff0c 有不懂的可以留言 xff0c
  • 微信小程序文字水平垂直居中对齐问题(完美解决方案)

    我们知道常用的居中对齐方式有很多种例如 xff1a text align center align items center justify content center margin auto 子容器在父容器中居中 但是在view中的文字
  • mac下python matplotlib中文乱码解决方案(亲测可用)!!

    在网上找了一大堆方法 xff0c 花了很久 xff0c 发现不是要安装各种字体就是要改配置 xff0c 而且字体真的不好找也不好安装 就例如下面这两种办法 xff0c mac下根本不管用 xff0c 别人管不管用我不知道 xff0c 反正我
  • python使用threading.Timer实现线程循环任务定时器(一)

    在进行爬虫系统开发的过程中遇到需要间隔一段时间就重复执行的任务的需求 xff0c 就想实现一个线程服务在后台监控数据的抓取状态 xff0c 要想实现定时循环任务的脚本可以使用linux下的crontab命令来执行 xff0c 但是在一个常驻
  • cross_val_score的 scoring参数值解析

    一般我们在模型训练过程中 xff0c 会采用K折交叉验证的方法来验证模型的表现 xff0c 从而进行调参 xff0c 一般我们会用到 sklearn model selection 的 cross val score 方法来计算模型的得分
  • windows 10下 itunes 备份默认存储路径问题

    最近在研究iphone手机备份的问题 xff0c 在使用itunes给手机备份的时候 xff0c 发现C盘空间不够用了 xff0c 于是想把itunes的默认存储路径修改一下 xff0c 在网上查找资料了解了相关操作教程后 xff0c 发现
  • MAC查看与修改系统默认的shell

    查看系统当前默认使用的shell有如下几个方法 一 查看所有的shell cat etc shells 输出 List of acceptable shells for chpass 1 Ftpd will not allow users
  • windows下redis的配置文件(redis.windows.conf)

    redis的配置 Redis默认不是以守护进程的方式运行 xff0c 可以通过该配置项修改 xff0c 使用yes启用守护进程 daemonize yes 当Redis以守护进程方式运行时 xff0c Redis默认会把pid写入redis
  • UITabBarController

    1 UITabBarController的常用属性和方法 一般来说 xff0c 目前市面上的App很多都是由一个UITabBarController管理着4 xff5e 5个UINavigationController xff0c 然后每个
  • LJSpeech-1.1.tar.bz2 下载分享

    数据集 xff1a http data keithito com data speech LJSpeech 1 1 tar bz2 xff08 用迅雷下载很快 xff09 百度网盘地址 xff1a 链接 xff1a https pan ba
  • cookie存放位置(Win10)

    IE浏览器 xff1a APPDATA Microsoft Windows Cookies 目录中的xxx txt文件 xff08 IE浏览器分开存放的 xff09 火狐浏览器 xff1a APPDATA Mozilla Firefox P
  • C语言 将一个整数的二进制序列分别输出

    include lt stdio h gt int main int i j num char arr1 16 char arr2 16 printf 34 输入一个整数 xff1a 34 scanf 34 d 34 amp num for
  • openSSL中SSL_MODE_AUTO_RETRY使用引发的问题

    1 SSL MODE AUTO RETRY的作用 关于这个flag的作用 xff0c openSSL官方的解释如下所示 xff1a SSL MODE AUTO RETRY Never bother the application with
  • Github下载代码和运行

    本文介绍利用Git工具下载和运行GitHub代码 文章目录 一 Win下载安装Git二 运行python代码1 下载Github代码2 运行代码 一 Win下载安装Git 官网下载 xff1a https git scm com downl
  • 批量修改txt文件名,删除相同部分

    转载 xff1a https www cnblogs com cyh2009 p 10593776 html 1 在包括需要修改的txt文件夹中新建txt文件 xff0c 输入 xff1a 64 echo off span class to
  • 8086汇编指令笔记

    8086 8088汇编指令总结 一 数据传送指令 1 传送指令 xff1a MOV move 格式 xff1a mov dst src 具体用法 xff1a 1 CPU内部寄存器之间的数据传送 xff0c 如 xff1a mov ah al
  • CentOS(linux)循环登录(闪退)的一种可能的解决方法

    前言 最近开机之后通过远程ssh刷init 5进系统时发现 xff0c 我经常使用的账号输入账号密码后屏幕闪一下又回到登录界面 xff0c 也就是所谓的循环登录 xff0c 其他的账号登录都是正常的 xff0c 烦了我有一段时间了 xff0
  • 百度ECharts地图 地名位置坐标微调

    百度ECharts地图 地名位置坐标微调 百度Echarts出现地市名字不居中或者重叠 下载的地图json数据里坐标位置导致出现这种问题 下载的地图json数据里坐标位置导致出现这种问题 xff0c 修改json数据中的cp 属性存储的是经
  • Java中抽象类 abstract和interface的区别

    abstract class和interface是Java语言中对于抽象类定义进行支持的两种机制 xff0c 正是由于这两种机制的存在 xff0c 才赋予了Java强大的面向对象能力 abstract class和interface之间在对
  • Java Vue uni-app 三端实现,滑动拼图验证码

    一步一步实现 图片滑动验证码 项目中要使用 图片滑动验证码 xff0c 顾了解之 需要以下几步来完成 xff1a 1 后端随机计算抠图的距离 xff0c 生成背景与拼图块的图片 xff0c 缓存 拼图块需 滑动的距离像素 2 前端加载背景图