11.关注、取消关注 + 关注列表、粉丝列表

news2024/9/24 3:27:28

目录

1.关注、取消关注 

1.1 把数据存到 Redis 中,构造 key

1.2 开发业务层

1.3 开发表现层

1.4 显示正确的关注数据

2.关注列表、粉丝列表

2.1 业务层

2.2 表现层


1.关注、取消关注 

  • 需求:开发关注、取消关注功能;统计用户的关注数、粉丝数
  • 关键:若 A 关注了 B,则 A 是 B 的 Follower(粉丝),B 是 A 的 Followee(目标);关注的目标可以是用户、帖子、题目等,在实现时将这些目标抽象为实体


1.1 把数据存到 Redis 中,构造 key

规划 key,在 RedisKeyUtil 包下添加方法:

  • 声明两个前缀(follower、followee),定义常量
  • 添加 某个用户关注的实体方法拼接 key:followee:userId:entityType -> zset(entityId,now)
  • 添加 某个用户拥有的粉丝 方法拼接 key:follower:entityType:entityId -> zset(userId,now)
    //声明两个前缀(follower、followee),定义常量——关注与取消关注
    private static final String PREFIX_FOLLOWEE = "followee";
    private static final String PREFIX_FOLLOWER = "follower";

    // 某个用户关注的实体
    // followee:userId:entityType -> zset(entityId,now)
    public static String getFolloweeKey(int userId, int entityType) {
        return PREFIX_FOLLOWEE + SPLIT + userId + SPLIT + entityType;
    }

    // 某个实体拥有的粉丝
    // follower:entityType:entityId -> zset(userId,now)
    public static String getFollowerKey(int entityType, int entityId) {
        return PREFIX_FOLLOWER + SPLIT + entityType + SPLIT + entityId;
    }

1.2 开发业务层

在 service 包下新建 FollowService 类(相关关注和取消关注的业务):

  • 将数据存入 Redis 中,注入 RedisTemplate
  • 添加关注的业务方法:传入 用户 id 和实体
  • 存入关注目标 和 粉丝,一项业务有两次存储需要保证事务,调用 redisTemplate.execute
  • 然后构造上述的两个 key(目标 key、粉丝 key)
  • 首先开启事务,再做两次增加存储操作(有序的存储)
  • 再添加取消关注的业务方法:和 添加关注方法一样,只是再开启事务的时候,做两次删除操作
package com.example.demo.service;

import com.example.demo.util.RedisKeyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.core.RedisOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.SessionCallback;
import org.springframework.stereotype.Service;

/**
 * 关注与取消关注业务方法
 */
@Service
public class FollowService {
    //将数据存入 Redis 中,注入 RedisTemplate
    @Autowired
    private RedisTemplate redisTemplate;

    //添加关注的业务方法:传入 用户 id 和实体
    public void follow(int userId, int entityType, int entityId) {

        //存入关注目标 和 粉丝,一项业务有两次存储需要保证事务,调用 redisTemplate.execute
        redisTemplate.execute(new SessionCallback() {
            @Override
            public Object execute(RedisOperations operations) throws DataAccessException {

                //然后构造上述的两个 key(目标 key、粉丝 key)
                //目标 key
                String followeeKey = RedisKeyUtil.getFolloweeKey(userId, entityType);
                //粉丝 key
                String followerKey = RedisKeyUtil.getFollowerKey(entityType, entityId);

                //开启事务
                operations.multi();

                //做两次增加存储操作(有序的存储)
                operations.opsForZSet().add(followeeKey, entityId, System.currentTimeMillis());
                operations.opsForZSet().add(followerKey, userId, System.currentTimeMillis());

                return operations.exec();
            }
        });
    }

    public void unfollow(int userId, int entityType, int entityId) {
        redisTemplate.execute(new SessionCallback() {
            @Override
            public Object execute(RedisOperations operations) throws DataAccessException {
                String followeeKey = RedisKeyUtil.getFolloweeKey(userId, entityType);
                String followerKey = RedisKeyUtil.getFollowerKey(entityType, entityId);

                operations.multi();

                做两次删除操作(有序的存储)、删除操作不需要当前时间
                operations.opsForZSet().remove(followeeKey, entityId);
                operations.opsForZSet().remove(followerKey, userId);

                return operations.exec();
            }
        });
    }

    // 查询关注的实体的数量
    public long findFolloweeCount(int userId, int entityType) {
        String followeeKey = RedisKeyUtil.getFolloweeKey(userId, entityType);
        return redisTemplate.opsForZSet().zCard(followeeKey);
    }

    // 查询实体的粉丝的数量
    public long findFollowerCount(int entityType, int entityId) {
        String followerKey = RedisKeyUtil.getFollowerKey(entityType, entityId);
        return redisTemplate.opsForZSet().zCard(followerKey);
    }

    // 查询当前用户是否已关注该实体
    public boolean hasFollowed(int userId, int entityType, int entityId) {
        String followeeKey = RedisKeyUtil.getFolloweeKey(userId, entityType);
        return redisTemplate.opsForZSet().score(followeeKey, entityId) != null;
    }
}

1.3 开发表现层

在 controller 包中添加 FollowController 类(关注、取消关注的请求):

  • 注入 FollowService
  • 分为两次请求,是一个异步请求:在页面点击关注,整个页面不刷新,只是一个局部刷新;提交数据:POST 请求
  • 关注请求:当前登陆用户关注某一个实体,传入实体参数并且注入 HostHolder
  • 首先获取当前用户、然后再去关注,给页面返回结果
  • 取消关注请求类似
package com.example.demo.controller;

import com.example.demo.entity.User;
import com.example.demo.service.FollowService;
import com.example.demo.util.CommunityUtil;
import com.example.demo.util.HostHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 关注、取消关注的请求
 */

@Controller
public class FollowController {

    @Autowired
    private FollowService followService;

    @Autowired
    private HostHolder hostHolder;

    //分为两次请求,是一个异步请求:在页面点击关注,整个页面不刷新,只是一个局部刷新;提交数据:POST 请求
    //关注请求:当前登陆用户关注某一个实体,传入实体参数并且注入 HostHolder
    @RequestMapping(path = "/follow", method = RequestMethod.POST)
    @ResponseBody
    public String follow(int entityType, int entityId) {

        //首先获取当前用户、然后再去关注,给页面返回结果
        User user = hostHolder.getUser();
        followService.follow(user.getId(), entityType, entityId);
        return CommunityUtil.getJSONString(0, "已关注!");
    }

    //取消关注
    @RequestMapping(path = "/unfollow", method = RequestMethod.POST)
    @ResponseBody
    public String unfollow(int entityType, int entityId) {
        User user = hostHolder.getUser();

        followService.unfollow(user.getId(), entityType, entityId);

        return CommunityUtil.getJSONString(0, "已取消关注!");
    }

}

CommunityConstant 类 添加实体用户:

    /**
     * 实体类型: 用户
     */
    int ENTITY_TYPE_USER = 3;

处理主页关注按钮 profile.html:

                <!-- 个人信息 -->
				<div class="media mt-5">
					<img th:src="${user.headerUrl}" class="align-self-start mr-4 rounded-circle" alt="用户头像" style="width:50px;">
					<div class="media-body">
						<h5 class="mt-0 text-warning">
							<span th:utext="${user.username}">nowcoder</span>
							<input type="hidden" id="entityId" th:value="${user.id}">
							<button type="button" th:class="|btn ${hasFollowed?'btn-secondary':'btn-info'} btn-sm float-right mr-5 follow-btn|"
									th:text="${hasFollowed?'已关注':'关注TA'}" th:if="${loginUser!=null&&loginUser.id!=user.id}">关注TA</button>
						</h5>
						<div class="text-muted mt-3">
							<span>注册于 <i class="text-muted" th:text="${#dates.format(user.createTime,'yyyy-MM-dd HH:mm:ss')}">2015-06-12 15:20:12</i></span>
						</div>
						<div class="text-muted mt-3 mb-5">
							<span>关注了 <a class="text-primary" href="followee.html" th:text="${followeeCount}">5</a> 人</span>
							<span class="ml-4">关注者 <a class="text-primary" href="follower.html" th:text="${followerCount}">123</a> 人</span>
							<span class="ml-4">获得了 <i class="text-danger" th:text="${likeCount}">87</i> 个赞</span>
						</div>
					</div>
				</div>

profile.js:

$(function(){
	$(".follow-btn").click(follow);
});

function follow() {
	var btn = this;
	if($(btn).hasClass("btn-info")) {
		// 关注TA
		$.post(
		    CONTEXT_PATH + "/follow",
		    {"entityType":3,"entityId":$(btn).prev().val()},
		    function(data) {
		        data = $.parseJSON(data);
		        if(data.code == 0) {
                    window.location.reload();
		        } else {
                    alert(data.msg);
		        }
		    }
		);
		// $(btn).text("已关注").removeClass("btn-info").addClass("btn-secondary");
	} else {
		// 取消关注
		$.post(
		    CONTEXT_PATH + "/unfollow",
		    {"entityType":3,"entityId":$(btn).prev().val()},
		    function(data) {
		        data = $.parseJSON(data);
		        if(data.code == 0) {
                    window.location.reload();
		        } else {
                    alert(data.msg);
		        }
		    }
		);
		//$(btn).text("关注TA").removeClass("btn-secondary").addClass("btn-info");
	}
}

1.4 显示正确的关注数据

访问用户主页,关注数量、状态显示正确,打开 FollowService 类添加正确的数量等等:

  • 补充查询目标实体的数量,传入用户 id、实体类别,构造目标 key,统计数量
  • 查询实体粉丝的数量,传入实体Type、实体 id,构造粉丝 key,统计数量
  • 查询当前用户是否已关注该实体类(传入当前用户、实体类型、实体 id):当前用户关注目标中有无实体,构造目标 key,在 redis 中查询某一个数据的分数,能查到说明已经关注
    // 查询关注的实体的数量
    public long findFolloweeCount(int userId, int entityType) {
        //构造目标 key,统计数量
        String followeeKey = RedisKeyUtil.getFolloweeKey(userId, entityType);
        return redisTemplate.opsForZSet().zCard(followeeKey);
    }

    // 查询实体的粉丝的数量
    public long findFollowerCount(int entityType, int entityId) {
        //构造粉丝 key,统计数量
        String followerKey = RedisKeyUtil.getFollowerKey(entityType, entityId);
        return redisTemplate.opsForZSet().zCard(followerKey);
    }

    // 查询当前用户是否已关注该实体
    public boolean hasFollowed(int userId, int entityType, int entityId) {
        String followeeKey = RedisKeyUtil.getFolloweeKey(userId, entityType);
        //在 redis 中查询某一个数据的分数,能查到说明已经关注
        return redisTemplate.opsForZSet().score(followeeKey, entityId) != null;
    }

在主页中显示正确数量,主页是通过 UserController 访问,则需要处理 UserController

  • 在个人主页的方法中,添加关注数量、粉丝数量、是否已关注,最后传给模板
  • 注入 FollowService
    // 个人主页
    @RequestMapping(path = "/profile/{userId}", method = RequestMethod.GET)
    public String getProfilePage(@PathVariable("userId") int userId, Model model) {
        User user = userService.findUserById(userId);
        if (user == null) {
            throw new RuntimeException("该用户不存在!");
        }

        // 用户
        model.addAttribute("user", user);
        // 点赞数量
        int likeCount = likeService.findUserLikeCount(userId);
        model.addAttribute("likeCount", likeCount);

        // 关注数量
        long followeeCount = followService.findFolloweeCount(userId, ENTITY_TYPE_USER);
        model.addAttribute("followeeCount", followeeCount);
        // 粉丝数量
        long followerCount = followService.findFollowerCount(ENTITY_TYPE_USER, userId);
        model.addAttribute("followerCount", followerCount);
        // 是否已关注
        boolean hasFollowed = false;
        //判断是否登陆
        if (hostHolder.getUser() != null) {
            hasFollowed = followService.hasFollowed(hostHolder.getUser().getId(), ENTITY_TYPE_USER, userId);
        }
        model.addAttribute("hasFollowed", hasFollowed);

        return "/site/profile";
    }

2.关注列表、粉丝列表

  • 业务层:查询某个用户关注的人、支持分页;查询某个用户的分析,支持分页
  • 表现层:处理“查询关注的人”、“查询粉丝”请求;编写“查询关注的人”、“查询粉丝”模板

2.1 业务层

在 FollowService 类中添加方法:

  • 补充新的方法:查询某个用户关注的人(传入用户,分页条件)
  • 拼接用户关注的 key:实现 CommunityConstant 接口
  • 从集合中查询数据(范围查询):传入 key,范围查询传入两个索引,从哪里到哪里——offset 到 offset + limit - 1
  • 查询的数据为整数:关注的目标 id
  • 判断目标 id 是 空值,直接返回空
  • 不为 空值,将目标 id 转化为详细数据传入集合中:首先实例化集合、遍历目标 id 查询封装到 map 中,实例化 map
  • 注入 UserService,根据 id 查询用户,并放入 map 中
  • 查询关注时间(有序集合中的分数)放入 map 中
  • 最后返回列表
  • 补充新的方法:查询某用户的粉丝(同理上述操作)
public class FollowService implements CommunityConstant {

    @Autowired
    private UserService userService;

    //查询某个用户关注的人(传入用户,分页条件)
    public List<Map<String, Object>> findFollowees(int userId, int offset, int limit) {
        //拼接用户关注的 key:实现 CommunityConstant 接口
        String followeeKey = RedisKeyUtil.getFolloweeKey(userId, ENTITY_TYPE_USER);
        //从集合中查询数据(范围查询):传入 key,范围查询传入两个索引,从哪里到哪里——offset 到 offset + limit - 1
        Set<Integer> targetIds = redisTemplate.opsForZSet().reverseRange(followeeKey, offset, offset + limit - 1);

        if (targetIds == null) {
            return null;
        }

        //首先实例化集合、遍历目标 id 查询封装到 map 中,实例化 map
        //注入 UserService,根据 id 查询用户,并放入 map 中
        List<Map<String, Object>> list = new ArrayList<>();
        for (Integer targetId: targetIds) {
            Map<String, Object> map = new HashMap<>();
            User user = userService.findUserById(targetId);
            map.put("user", user);
            Double score = redisTemplate.opsForZSet().score(followeeKey, targetId);
            map.put("followTime", new Date(score.longValue()));
            list.add(map);
        }
        return list;
    }

    // 查询某用户的粉丝(同理上述操作)
    public List<Map<String, Object>> findFollowers(int userId, int offset, int limit) {
        String followerKey = RedisKeyUtil.getFollowerKey(ENTITY_TYPE_USER, userId);
        Set<Integer> targetIds = redisTemplate.opsForZSet().reverseRange(followerKey, offset, offset + limit - 1);

        if (targetIds == null) {
            return null;
        }

        List<Map<String, Object>> list = new ArrayList<>();
        for (Integer targetId : targetIds) {
            Map<String, Object> map = new HashMap<>();
            User user = userService.findUserById(targetId);
            map.put("user", user);
            Double score = redisTemplate.opsForZSet().score(followerKey, targetId);
            map.put("followTime", new Date(score.longValue()));
            list.add(map);
        }

        return list;
    }
}

2.2 表现层

在 FollowController 类中添加请求:

  • 添加方法:声明访问路径(查询某个用户关注的人,通过路径传入用户 id),查询为 GET 请求
  • 添加方法:某个用户关注的人(得到路径当中的 id 做进一步查询、支持分页、给页面传数据传入 Model)
  • 查询得到 User ,注入 UserService
  • 如果用户为空,抛异常
  • 不为空将 User 传给页面
  • 查询列表中的数据,支持分页、访问路径、一共有多少行数据
  • 分页查询显示的数据:用 map 封装
  • 判断当前用户是否进行关注:遍历数据,得到 User,判断当前用户对此用户是否关注(添加是否关注方法),将此关注方法封装到 map 中
  • 将集合传给模板、返回模板
  • 添加查询某个用户的粉丝的请求(同理查询某个用户关注的人)
  • 添加方法:声明访问路径(查询某个用户关注的人,通过路径传入用户 id),查询为 GET 请求
public class FollowController implements CommunityConstant {

    @Autowired
    private UserService userService;


    //某个用户关注的人
    //添加方法:声明访问路径(查询某个用户关注的人,通过路径传入用户 id),查询为 GET 请求
    @RequestMapping(path = "/followees/{userId}", method = RequestMethod.GET)
    //添加方法:某个用户关注的人(得到路径当中的 id 做进一步查询、支持分页、给页面传数据传入 Model)
    public String getFollowees(@PathVariable("userId") int userId, Page page, Model model) {
        //查询得到 User ,注入 UserService
        User user = userService.findUserById(userId);
        //如果用户为空,抛异常
        if (user == null) {
            throw new RuntimeException("该用户不存在");
        }
        //不为空将 User 传给页面
        model.addAttribute("user", user);

        //查询列表中的数据,支持分页、访问路径、一共有多少行数据
        page.setLimit(5);
        page.setPath("/followees/" + userId);
        //findFolloweeCount 查询得到 long,强转为 int
        page.setRows((int) followService.findFolloweeCount(userId, ENTITY_TYPE_USER));

        //分页查询显示的数据:用 map 封装
        List<Map<String, Object>> userList = followService.findFollowees(userId, page.getOffset(), page.getLimit());
        //判断当前用户是否进行关注:遍历数据,得到 User,判断当前用户对此用户是否关注(添加是否关注方法),将此关注方法封装到 map 中
        if (userList != null) {
            for (Map<String, Object> map : userList) {
                User u = (User) map.get("user");
                map.put("hasFollowed", hasFollowed(u.getId()));
            }
        }
        //将集合传给模板、返回模板
        model.addAttribute("users", userList);

        return "/site/followee";
    }

    //添加查询某个用户的粉丝的请求(同理查询某个用户关注的人)
    @RequestMapping(path = "/followers/{userId}", method = RequestMethod.GET)
    public String getFollowers(@PathVariable("userId") int userId, Page page, Model model) {
        User user = userService.findUserById(userId);
        if (user == null) {
            throw new RuntimeException("该用户不存在!");
        }
        model.addAttribute("user", user);

        page.setLimit(5);
        page.setPath("/followers/" + userId);
        page.setRows((int) followService.findFollowerCount(ENTITY_TYPE_USER, userId));

        List<Map<String, Object>> userList = followService.findFollowers(userId, page.getOffset(), page.getLimit());
        if (userList != null) {
            for (Map<String, Object> map : userList) {
                User u = (User) map.get("user");
                map.put("hasFollowed", hasFollowed(u.getId()));
            }
        }
        model.addAttribute("users", userList);

        return "/site/follower";
    }

    //添加是否关注方法
    private boolean hasFollowed(int userId) {
        if (hostHolder.getUser() == null) {
            return false;
        }

        return followService.hasFollowed(hostHolder.getUser().getId(), ENTITY_TYPE_USER, userId);
    }
}

最后处理页面

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

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

相关文章

飞天使-docker知识点5-资源限制与容器的不同状态

文章目录 cpu和内存的限制内存限制的部分参数容器的不同状态docker images 的分层docker registry制作镜像 cpu和内存的限制 默认情况下&#xff0c;容器没有资源限制&#xff0c;可以使用主机内核调度程序允许的尽可能多的 给定资源&#xff0c;Docker 提供了控制容器可以限制…

wordpress 修改社交图标

要去掉标记的图标&#xff0c;死活找不到在那里配置。后来找到了&#xff0c;下图&#xff08;wordpress 小白&#xff0c;特此记录&#xff09;

【开源软件】最好的开源软件-2023-第17名 Gravite

自我介绍 做一个简单介绍&#xff0c;酒架年近48 &#xff0c;有20多年IT工作经历&#xff0c;目前在一家500强做企业架构&#xff0e;因为工作需要&#xff0c;另外也因为兴趣涉猎比较广&#xff0c;为了自己学习建立了三个博客&#xff0c;分别是【全球IT瞭望】&#xff0c;【…

事务--03---TCC空回滚、悬挂、幂等解决方案

提示&#xff1a;文章写完后&#xff0c;目录可以自动生成&#xff0c;如何生成可参考右边的帮助文档 文章目录 Seata TCC 模式设计思路TCC存在的问题1、空回滚以及解决方案解决方案&#xff1a; 2、幂等问题以及解决方案解决方案&#xff1a; 3、悬挂问题以及解决方案解决方案…

档案馆数字化建设实施方案

档案馆数字化建设实施方案主要包括以下几个方面的内容&#xff1a; 1. 目标与规划&#xff1a;明确数字化建设的目标和规划&#xff0c;确定数字化建设的优先领域和重点工作&#xff0c;制定长期和短期的发展规划。 2. 技术设施建设&#xff1a;建设专久智能数字化档案管理系统…

gradle-5.4.1-all下载时出现了Connect timed out

问题描述&#xff1a;最近在学习如何在手机端部署YOLO&#xff0c;出现了许多错误&#xff0c;其中之一的错误&#xff1a;gradle-5.4.1-all下载时出现了Connect timed out&#xff0c;大家都知道这是从国外网站下载网络问题导致的。 解决办法: 在我们创建项目中的一个路径下…

回溯热门问题

关卡名 回溯热门问题 我会了✔️ 内容 1.组合总和问题 ✔️ 2.分割回文串问题 ✔️ 3.子集问题 ✔️ 4.排列问题 ✔️ 5.字母全排列问题 ✔️ 6.单词搜索 ✔️ 1. 组合总和问题 LeetCode39题目要求&#xff1a;给你一个无重复元素的整数数组candidates和一个目标整数 ta…

【十】python复合模式

10.1 复合模式简介 在前面的栏目中我们了解了各种设计模式。正如我们所看到的&#xff0c;设计模式可分为三大类:结构型、创建型和行为型设计模式。同时&#xff0c;我们还给出了每种类型的相应示例。然而&#xff0c;在软件实现中&#xff0c;模式并是不孤立地工作的。对于所…

【c】数组元素移动

本题的难点之处就是不让你创建新的数组&#xff0c;而且移动的距离也没有给限制&#xff0c;比如有7个数&#xff0c;本题没有限制必须移动距离小于7&#xff0c;也可能移动的距离大于7&#xff0c;甚至更多&#xff0c;下面附上我的代码 #include<stdio.h>int main() {…

C++模板编程浅析

函数模板 声明与定义函数模板 #include <iostream> using namespace std; template <class T> void swap_new(T& a, T& b);int main() {int a 1, b 2;float c 1.5, d 3.6;swap_new(a, b);swap_new(c, d);cout << a << " " &…

【Qt5】ui文件最后会变成头文件

2023年12月14日&#xff0c;周四下午 我也是今天下午偶然间发现这个的 在使用Qt的uic&#xff08;User Interface Compiler&#xff09;工具编译ui文件时&#xff0c;会生成对应的头文件。 在Qt中&#xff0c;ui文件是用于描述用户界面的XML文件&#xff0c;而头文件是用于在…

binkw32.dll丢失怎么办?这5个方法都可以解决binkw32.dll丢失问题

binkw32.dll文件是什么&#xff1f; binkw32.dll是一个动态链接库文件&#xff0c;它是Windows操作系统中的一个重要组件。它包含了许多用于处理多媒体文件的函数和资源&#xff0c;如视频、音频等。当我们在电脑上打开或播放某些多媒体文件时&#xff0c;系统会调用binkw32.d…

刘家窑中医医院鲁卫星主任:冬季守护心脑血管,为社区居民送去健康关爱

随着冬季的来临&#xff0c;气温逐渐降低&#xff0c;心脑血管疾病的风险也随之增加。为了提高公众对心脑血管疾病的认知和预防意识&#xff0c;北京刘家窑中医医院于近日成功举办了冬季守护心脑血管公益义诊活动。 本次义诊活动主要针对社区居民中的中老年人&#xff0c;特别是…

利用闭包与高阶函数实现缓存函数的创建

缓存函数是一种用于存储和重复利用计算结果的机制。其基本思想是&#xff0c;当一个函数被调用并计算出结果时&#xff0c;将该结果存储在某种数据结构中 (通常是一个缓存对象)以备将来使用。当相同的输入参数再次传递给函数时&#xff0c;不再执行实际的计算&#xff0c;而是直…

SpringBoot的Starter自动化配置,自己编写配置maven依赖且使用及短信发送案例

目录 一、Starter机制 1. 是什么 2. 有什么用 3. 应用场景 二、短信发送案例 1. 创建 2. 配置 3. 编写 4. 形成依赖 6. 其他项目的使用 每篇一获 一、Starter机制 1. 是什么 SpringBoot中的starter是一种非常重要的机制(自动化配置)&#xff0c;能够抛弃以前繁杂…

JVM的五大分区

1.方法区 方法区主要用来存储已在虚拟机加载的类的信息、常量、静态变量以及即时编译器编译后的代码信息。该区域是被线程共享的。 2.虚拟机栈 虚拟机栈也就是我们平时说的栈内存&#xff0c;它是为java方法服务的。每个方法在执行的 时候都会创建一个栈帧&#xff0c;用于存…

SQL进阶理论篇(四):索引的结构原理(B树与B+树)

文章目录 简介如何评价索引的数据结构设计好坏二叉树的局限性什么是B树什么是B树总结参考文献 简介 我们在上一节中说过&#xff0c;索引其实是一种数据结构&#xff0c;那它到底是一种什么样的数据结构呢&#xff1f;本节将简单介绍一下几个问题&#xff1a; 什么样的数据结…

【开源Mongdb驱动】SpringBoot+Mybatis+Mongdb融合使用教程

#【开源Mongdb驱动】SpringBootMybatisMongdb无缝融合使用教程 介绍 本文介绍一款基于JAVA开源的mongodb jdbc驱动为基础的无缝与springbootmybatis融合使用案例 mongodb JDBC 使用案例 https://blog.csdn.net/gongbing798930123/article/details/135002530 《基于开源的JA…

鸿蒙原生应用/元服务开发-Stage模型能力接口(四)

一、说明 AbilityStage是HAP的运行时类。AbilityStage类提供在HAP加载的时候&#xff0c;通知开发者&#xff0c;可以在此进行该HAP的初始化&#xff08;如资源预加载&#xff0c;线程创建等&#xff09;能力。 本模块首批接口从API version 9 开始支持。后续版本的新增接口&…

Unity Web 浏览器-3D WebView中有关于CanvasWebViewPrefab

一、CanvasWebViewPrefab默认设置 这个是在2_CanvasWebViewDemo示例场景文件中可以可以查看得到&#xff0c;可以看出CanvasWebViewPrefab的默认配置如下。 二、Web 浏览器网页和Unity内置UI的渲染顺序 1、如果你勾选了以下这个Native 2D Mode选项的话&#xff0c;那么Unit…