策略模式 定义了算法族,分别封装起来,让他们之间可以相互替换,此模式让算法的变化独立于使用算法的客户。 Java实现 模拟鸭子应用,不同鸭子有不同的行为 策略接口及实现 飞行行为 接口 public interface FlyBehavior { void fly(); } 不同实现 public class FlyWithWings implements FlyBehavior { @Override public void fly() { System.out.println("I'm flying"); } } public class FlyNoWay implements FlyBehavior { @Override public void fly() { System.out.println("I can't fly"); } } public class FlyRocketPowered implements FlyBehavior { @Override public void fly() { System.out.println("I'm flying wit.... 策略模式 设计模式
流程 前端调用wx.login接口获取code,然后再调用wx.getUserInfo接口获取用户的信息。 调用服务器接口,将获取到的code,rawData,signature,encryptedData,iv发送到后端。 服务器通过code获取openid和session_key 数据签名校验 解密用户敏感数据获取用户信息 Java后端实现 数据签名校验 使用sha1加密rawDate+session_key,和signature进行比对 String sha1Hex = DigestUtils.sha1Hex(wxLogin.getRawData() + sessionKey); boolean signatureResult = sha1Hex.equals(wxLogin.getSignature()); 解密用户敏感数据获取用户信息 base64解码 Java 8 内置了 Base64 编码的编码器和解码器。 // 被加密的数据 byte[] dataByte = Base64.getDecoder().decode(encryptedData); // 加密秘钥.... Java获取小程序用户信息 小程序
服务器版本: CentOS 7 拉取官方的镜像 docker pull redis 准备 创建conf,data文件夹 下载配置文件 wget https://raw.githubusercontent.com/antirez/redis/5.0/redis.conf 放至conf文件夹下 配置 密码设置 修改配置文件中的requirepass参数 持久化 appendonly yes 运行容器 docker run \ -p 6379:6379 \ -v $PWD/data:/data \ -v $PWD/conf/redis.conf:/usr/local/etc/redis/redis.conf \ --name redis \ -d redis redis-server /usr/local/etc/redis/redis.conf redis-server /usr/local/etc/redis/redis.conf 指定配置文件启动redis-server进程 连接容器 docker exec -it redis redis-cli Docker 安装 Redis Docker
环境 使用阿里云DMS的数据库实验室 创建需要的表 课程表 CREATE TABLE `courses` ( `cid` int(20) NOT NULL COMMENT '课程ID', `name` varchar(32) NOT NULL COMMENT '课程名', PRIMARY KEY (`cid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 随机生成20条数据 学生表 CREATE TABLE `students` ( `sid` int(11) NOT NULL, `name` varchar(32) NOT NULL, PRIMARY KEY (`sid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 随机生成5W条数据 学生成绩表 CREATE TABLE `sc` ( `sc_id` int(11) NOT NULL, `sid` int(11) NOT NULL, `cid` int(11) NOT NULL, `score` int(11) NOT NULL, PRIMARY KEY .... 一个嵌套子查询的sql优化 MySQL
题目 Implement strStr(). Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. [28] Implement strStr() LeetCode
题目 Given an array nums and a value val, remove all instances of that value in-place and return the new length. Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory. The order of elements can be changed. It doesn’t matter what you leave beyond the new length. [27] Remove Element LeetCode
题目 Given a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new length. Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory. [26] Remove Duplicates from Sorted Array LeetCode
题目 Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. Example: Input: 1->2->4, 1->3->4 Output: 1->1->2->3->4->4 [21] Merge Two Sorted Lists LeetCode
题目 Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. An input string is valid if: Open brackets must be closed by the same type of brackets. Open brackets must be closed in the correct order. Note that an empty string is also considered valid. [20] Valid Parentheses LeetCode