The principle of generating QR code and scanning code can access different paths: for example, the links published by different test papers of questionnaire star can access different test papers

reflection:

This is the first time I have encountered this situation: I want to configure the form of nginx, and linux will automatically map the path every time a QR code is generated

But I copied the test links of several questionnaire stars and found that:

The paths of the same type of questions are the same. The only difference is the value in the path suffix {id}

The comparison of copied paths is as follows:

https://ks.wjx.top/vj/YHySy1c.aspx
https://ks.wjx.top/vj/hljVcYb.aspx

It can be seen that if the path is: https://ks.wjx.top/vj/{ id} is it in line with our conjecture?

Test hypothesis: show me code mode

  • Because the path is related to the examination question type of the database, the database table must have a field corresponding to {id}. When generating, update the database, query the database when accessing, and display the corresponding information to ensure that the id is unique in the database. We can use the password generator to do this. We can integrate the password generator tool class and find a toolkit, You can also write an implementation class yourself. The reference codes are as follows:
  • Quote someone's answer. It's simple, but there are some small questions. Just change them yourself!
  • public class RandomPassword {
        /**
         * Length of password
         */
        private static int passwordLength;
        /**
         * Generated password
         */
        private static StringBuffer password = new StringBuffer();
     
        public static void main(String[] args) {
            //Initializing numbers and symbols
            String num = "0123456789";
            String english = "qwertyuiopasdfghjklzxcvbnm";
            String englishBig = "QWERTYUIOPASDFGHJKLZXCVBNM";
            String symbol = "!@#$%^&*_+-{}<>.*";
            String stringSum = num + english + englishBig + symbol;
            int length = stringSum.length();
            //Define the password length and write it to death 8
            passwordLength = 8;
            for (int i = 0; i < passwordLength; i++) {
                Random random = new Random();
                int a = random.nextInt(length + 1);
                char one = stringSum.charAt(a);
                password.append(one);
            }
            System.out.print(password + "  ");
        }
    }

     

  • Two dimensional code generation zxing, of course, can also use hutool, hutool is also based on zxing
  • If yes @PathVariable is a placeholder for mapping URL bindings If you don't understand, please understand by yourself
  • Basic usage examples are as follows:;
  • @RequestMapping("/getUserById/{name}")
        public User getUser(@PathVariable("name") String name){
            return userService.selectUser(name);
        }

Assuming that everyone copies or shares a set of test papers on the questionnaire star less than 100 times, it should be enough. If the password generator generates 8 bits, 10000 copies and similar operations, it should also be satisfied.

Build a basic project environment based on spring boot, including lombok mybatis database and postman for testing

There are two basic interfaces:

The code is as follows:

package com.example.demo;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description: It is used to generate QR code and simply access the corresponding links
 * @author: LiuYC
 * @date: 2021 15:25, April 21
 */
@RestController
public class QrcodeController {
    @Resource
    ExamMapper examMapper;

    @RequestMapping("/createQrcode/{name}")
    public String createQrcode(@PathVariable("name") String name) {
        System.out.println("Output name: ");
        System.out.println(name);
//        Tool class generation:
        String s = PswUtil.PswUtils();
        String http = "http://localhost:19999/getExam/";
//        Update database
        Exam exam = new Exam();
        exam.setA("a");
        exam.setExamId(s);
        exam.setId("3");
        exam.setHead("The title is test");
        exam.setContent("The content is: how to write the test scheme");
        examMapper.insert(exam);
        System.out.println("Insert database complete:");
//        Return value to front end
        return http + s;
    }

    @RequestMapping("/getExam/{name}")
    public Exam getExam(@PathVariable("name") String name) {
        ExamExample examExample = new ExamExample();
        examExample.createCriteria().andExamIdEqualTo(name);
        List<Exam> exams = examMapper.selectByExample(examExample);
        if (exams.isEmpty()) {
            return null;
        }
        return exams.get(0);
    }
}

For complete code configuration of the whole project, please visit personal gitee:

https://gitee.com/daka1004/demo

1. Interface for generating QR code (link)

 

2. Link to the test interface

 

That's all for today. Please come here for the third time.

 

 

 

Keywords: Spring

Added by kolanos7 on Thu, 03 Mar 2022 15:52:05 +0200