Netty+SpringBoot+FastDFS+Html5實(shí)現(xiàn)聊天App,項(xiàng)目介紹。
Netty+SpringBoot+FastDFS+Html5實(shí)現(xiàn)聊天App,項(xiàng)目github鏈接。
本章完整代碼鏈接。
/** * @Description: 查詢我的好友列表 */ @PostMapping("/myFriends") public IMoocJSONResult myFriends(String userId) { // 0. userId 判斷不能為空 if (StringUtils.isBlank(userId)) { return IMoocJSONResult.errorMsg(""); } // 1. 數(shù)據(jù)庫(kù)查詢好友列表 List通過(guò)或忽略好友請(qǐng)求的接口myFirends = userService.queryMyFriends(userId); return IMoocJSONResult.ok(myFirends); }
定義枚舉類型
/** * * @Description: 忽略或者通過(guò) 好友請(qǐng)求的枚舉 */ public enum OperatorFriendRequestTypeEnum { IGNORE(0, "忽略"), PASS(1, "通過(guò)"); 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中提供通過(guò)或忽略好友請(qǐng)求的接口
/** * @Description: 接受方 通過(guò)或者忽略朋友請(qǐng)求 */ @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 沒(méi)有對(duì)應(yīng)的枚舉值,則直接拋出空錯(cuò)誤信息 if (StringUtils.isBlank(OperatorFriendRequestTypeEnum.getMsgByType(operType))) { return IMoocJSONResult.errorMsg(""); } if (operType == OperatorFriendRequestTypeEnum.IGNORE.type) { // 2. 判斷如果忽略好友請(qǐng)求,則直接刪除好友請(qǐng)求的數(shù)據(jù)庫(kù)表記錄 userService.deleteFriendRequest(sendUserId, acceptUserId); } else if (operType == OperatorFriendRequestTypeEnum.PASS.type) { // 3. 判斷如果是通過(guò)好友請(qǐng)求,則互相增加好友記錄到數(shù)據(jù)庫(kù)對(duì)應(yīng)的表 // 然后刪除好友請(qǐng)求的數(shù)據(jù)庫(kù)表記錄 userService.passFriendRequest(sendUserId, acceptUserId); } // 4. 數(shù)據(jù)庫(kù)查詢好友列表 List添加好友功展示 通過(guò)搜索好友姓名添加好友myFirends = userService.queryMyFriends(acceptUserId); // 5. 將查詢到的好友列表返回給前端 return IMoocJSONResult.ok(myFirends); }
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/73288.html
摘要:實(shí)現(xiàn)聊天,項(xiàng)目介紹。首先根據(jù)搜索的用戶的名稱查找是否存在這個(gè)用戶。如果搜索前置條件為成功,則向前端返回搜索用戶的信息。發(fā)送添加好友的請(qǐng)求判斷不能為空查詢用戶接受到的朋友申請(qǐng)最終實(shí)現(xiàn)效果 Netty+SpringBoot+FastDFS+Html5實(shí)現(xiàn)聊天App,項(xiàng)目介紹。Netty+SpringBoot+FastDFS+Html5實(shí)現(xiàn)聊天App,項(xiàng)目github鏈接。本章完整代碼鏈接。...
閱讀 2809·2021-11-19 11:30
閱讀 3086·2021-11-15 11:39
閱讀 1835·2021-08-03 14:03
閱讀 2017·2019-08-30 14:18
閱讀 2071·2019-08-30 11:16
閱讀 2225·2019-08-29 17:23
閱讀 2631·2019-08-28 18:06
閱讀 2563·2019-08-26 12:22