Netty+SpringBoot+FastDFS+Html5实现聊天App,项目介绍。
Netty+SpringBoot+FastDFS+Html5实现聊天App,项目github链接。
本章完整代码链接。
</>复制代码
/**
* @Description: 查询我的好友列表
*/
@PostMapping("/myFriends")
public IMoocJSONResult myFriends(String userId) {
// 0. userId 判断不能为空
if (StringUtils.isBlank(userId)) {
return IMoocJSONResult.errorMsg("");
}
// 1. 数据库查询好友列表
List myFirends = userService.queryMyFriends(userId);
return IMoocJSONResult.ok(myFirends);
}
通过或忽略好友请求的接口
定义枚举类型
</>复制代码
/**
*
* @Description: 忽略或者通过 好友请求的枚举
*/
public enum OperatorFriendRequestTypeEnum {
IGNORE(0, "忽略"),
PASS(1, "通过");
public final Integer type;
public final String msg;
OperatorFriendRequestTypeEnum(Integer type, String msg){
this.type = type;
this.msg = msg;
}
public Integer getType() {
return type;
}
public static String getMsgByType(Integer type) {
for (OperatorFriendRequestTypeEnum operType : OperatorFriendRequestTypeEnum.values()) {
if (operType.getType() == type) {
return operType.msg;
}
}
return null;
}
}
controller中提供通过或忽略好友请求的接口
</>复制代码
/**
* @Description: 接受方 通过或者忽略朋友请求
*/
@PostMapping("/operFriendRequest")
public IMoocJSONResult operFriendRequest(String acceptUserId, String sendUserId,
Integer operType) {
// 0. acceptUserId sendUserId operType 判断不能为空
if (StringUtils.isBlank(acceptUserId)
|| StringUtils.isBlank(sendUserId)
|| operType == null) {
return IMoocJSONResult.errorMsg("");
}
// 1. 如果operType 没有对应的枚举值,则直接抛出空错误信息
if (StringUtils.isBlank(OperatorFriendRequestTypeEnum.getMsgByType(operType))) {
return IMoocJSONResult.errorMsg("");
}
if (operType == OperatorFriendRequestTypeEnum.IGNORE.type) {
// 2. 判断如果忽略好友请求,则直接删除好友请求的数据库表记录
userService.deleteFriendRequest(sendUserId, acceptUserId);
} else if (operType == OperatorFriendRequestTypeEnum.PASS.type) {
// 3. 判断如果是通过好友请求,则互相增加好友记录到数据库对应的表
// 然后删除好友请求的数据库表记录
userService.passFriendRequest(sendUserId, acceptUserId);
}
// 4. 数据库查询好友列表
List myFirends = userService.queryMyFriends(acceptUserId);
// 5. 将查询到的好友列表返回给前端
return IMoocJSONResult.ok(myFirends);
}
添加好友功展示
通过搜索好友姓名添加好友
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/73288.html
摘要:实现聊天,项目介绍。首先根据搜索的用户的名称查找是否存在这个用户。如果搜索前置条件为成功,则向前端返回搜索用户的信息。发送添加好友的请求判断不能为空查询用户接受到的朋友申请最终实现效果 Netty+SpringBoot+FastDFS+Html5实现聊天App,项目介绍。Netty+SpringBoot+FastDFS+Html5实现聊天App,项目github链接。本章完整代码链接。...
摘要:实现聊天,项目介绍。若该用户不存在则记性注册,根据前端传入的信息构建对象,通过的将其保存入数据库中。注意密码需要使用工具类进行加密后再保存到数据库中。对返回的路径进行切割后得到缩略图的路径。通过的方法将二维码图片上传到文件服务器中。 Netty+SpringBoot+FastDFS+Html5实现聊天App,项目介绍。Netty+SpringBoot+FastDFS+Html5实现聊天...
阅读 2863·2021-11-19 11:30
阅读 3129·2021-11-15 11:39
阅读 1900·2021-08-03 14:03
阅读 2076·2019-08-30 14:18
阅读 2132·2019-08-30 11:16
阅读 2286·2019-08-29 17:23
阅读 2678·2019-08-28 18:06
阅读 2615·2019-08-26 12:22