使用websocket,注入依賴service的bean為null

問題:依賴注入失敗,service獲取不到,提示null

這是參考代碼

package com.shier.ws;import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.google.gson.Gson;
import com.shier.config.HttpSessionConfig;
import com.shier.model.domain.Chat;
import com.shier.model.domain.Team;
import com.shier.model.domain.User;
import com.shier.model.request.MessageRequest;
import com.shier.model.vo.ChatMessageVO;
import com.shier.model.vo.WebSocketVO;
import com.shier.service.ChatService;
import com.shier.service.TeamService;
import com.shier.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import javax.websocket.*;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;
import java.io.IOException;
import java.io.Serializable;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArraySet;import static com.shier.constants.ChatConstant.*;
import static com.shier.constants.UserConstants.ADMIN_ROLE;
import static com.shier.constants.UserConstants.USER_LOGIN_STATE;/*** WebSocket服務*/
@Component
@Slf4j
@ServerEndpoint(value = "/websocket/{userId}/{teamId}", configurator = HttpSessionConfig.class)
public class WebSocket {/*** 保存隊伍的連接信息*/private static final Map<String, ConcurrentHashMap<String, WebSocket>> ROOMS = new HashMap<>();/*** 線程安全的無序的集合*/private static final CopyOnWriteArraySet<Session> SESSIONS = new CopyOnWriteArraySet<>();/*** 會話池*/private static final Map<String, Session> SESSION_POOL = new HashMap<>(0);/*** 用戶服務*/private static UserService userService;/*** 聊天服務*/private static ChatService chatService;/*** 團隊服務*/private static TeamService teamService;/*** 房間在線人數*/private static int onlineCount = 0;/*** 當前信息*/private Session session;/*** http會話*/private HttpSession httpSession;/*** 上網數** @return int*/public static synchronized int getOnlineCount() {return onlineCount;}/*** 添加在線計數*/public static synchronized void addOnlineCount() {WebSocket.onlineCount++;}/*** 子在線計數*/public static synchronized void subOnlineCount() {WebSocket.onlineCount--;}/*** 集熱地圖服務** @param userService 用戶服務*/@Resourcepublic void setHeatMapService(UserService userService) {WebSocket.userService = userService;}/*** 集熱地圖服務** @param chatService 聊天服務*/@Resourcepublic void setHeatMapService(ChatService chatService) {WebSocket.chatService = chatService;}/*** 集熱地圖服務** @param teamService 團隊服務*/@Resourcepublic void setHeatMapService(TeamService teamService) {WebSocket.teamService = teamService;}/*** 隊伍內群發消息** @param teamId 團隊id* @param msg    消息*/public static void broadcast(String teamId, String msg) {ConcurrentHashMap<String, WebSocket> map = ROOMS.get(teamId);// keySet獲取map集合key的集合  然后在遍歷key即可for (String key : map.keySet()) {try {WebSocket webSocket = map.get(key);webSocket.sendMessage(msg);} catch (Exception e) {e.printStackTrace();}}}/*** 發送消息** @param message 消息* @throws IOException ioexception*/public void sendMessage(String message) throws IOException {this.session.getBasicRemote().sendText(message);}/*** 開放** @param session 會話* @param userId  用戶id* @param teamId  團隊id* @param config  配置*/@OnOpenpublic void onOpen(Session session, @PathParam(value = "userId") String userId, @PathParam(value = "teamId") String teamId, EndpointConfig config) {try {if (StringUtils.isBlank(userId) || "undefined".equals(userId)) {sendError(userId, "參數有誤");return;}HttpSession httpSession = (HttpSession) config.getUserProperties().get(HttpSession.class.getName());User user = (User) httpSession.getAttribute(USER_LOGIN_STATE);if (user != null) {this.session = session;this.httpSession = httpSession;}if (!"NaN".equals(teamId)) {if (!ROOMS.containsKey(teamId)) {ConcurrentHashMap<String, WebSocket> room = new ConcurrentHashMap<>(0);room.put(userId, this);ROOMS.put(String.valueOf(teamId), room);// 在線數加1addOnlineCount();} else {if (!ROOMS.get(teamId).containsKey(userId)) {ROOMS.get(teamId).put(userId, this);// 在線數加1addOnlineCount();}}} else {SESSIONS.add(session);SESSION_POOL.put(userId, session);sendAllUsers();}} catch (Exception e) {e.printStackTrace();}}/*** 關閉** @param userId  用戶id* @param teamId  團隊id* @param session 會話*/@OnClosepublic void onClose(@PathParam("userId") String userId, @PathParam(value = "teamId") String teamId, Session session) {try {if (!"NaN".equals(teamId)) {ROOMS.get(teamId).remove(userId);if (getOnlineCount() > 0) {subOnlineCount();}} else {if (!SESSION_POOL.isEmpty()) {SESSION_POOL.remove(userId);SESSIONS.remove(session);}sendAllUsers();}} catch (Exception e) {e.printStackTrace();}}/*** 消息** @param message 消息* @param userId  用戶id*/@OnMessagepublic void onMessage(String message, @PathParam("userId") String userId) {if ("PING".equals(message)) {sendOneMessage(userId, "pong");return;}MessageRequest messageRequest = new Gson().fromJson(message, MessageRequest.class);Long toId = messageRequest.getToId();Long teamId = messageRequest.getTeamId();String text = messageRequest.getText();Integer chatType = messageRequest.getChatType();User fromUser = userService.getById(userId);Team team = teamService.getById(teamId);if (chatType == PRIVATE_CHAT) {// 私聊privateChat(fromUser, toId, text, chatType);} else if (chatType == TEAM_CHAT) {// 隊伍內聊天teamChat(fromUser, text, team, chatType);} else {// 群聊hallChat(fromUser, text, chatType);}}/*** 隊伍聊天** @param user     用戶* @param text     文本* @param team     團隊* @param chatType 聊天類型*/private void teamChat(User user, String text, Team team, Integer chatType) {ChatMessageVO ChatMessageVO = new ChatMessageVO();WebSocketVO fromWebSocketVO = new WebSocketVO();BeanUtils.copyProperties(user, fromWebSocketVO);ChatMessageVO.setFormUser(fromWebSocketVO);ChatMessageVO.setText(text);ChatMessageVO.setTeamId(team.getId());ChatMessageVO.setChatType(chatType);ChatMessageVO.setCreateTime(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));if (user.getId() == team.getUserId() || user.getRole() == ADMIN_ROLE) {ChatMessageVO.setIsAdmin(true);}User loginUser = (User) this.httpSession.getAttribute(USER_LOGIN_STATE);if (loginUser.getId() == user.getId()) {ChatMessageVO.setIsMy(true);}String toJson = new Gson().toJson(ChatMessageVO);try {broadcast(String.valueOf(team.getId()), toJson);saveChat(user.getId(), null, text, team.getId(), chatType);chatService.deleteKey(CACHE_CHAT_TEAM, String.valueOf(team.getId()));} catch (Exception e) {throw new RuntimeException(e);}}/*** 大廳聊天** @param user     用戶* @param text     文本* @param chatType 聊天類型*/private void hallChat(User user, String text, Integer chatType) {ChatMessageVO ChatMessageVO = new ChatMessageVO();WebSocketVO fromWebSocketVO = new WebSocketVO();BeanUtils.copyProperties(user, fromWebSocketVO);ChatMessageVO.setFormUser(fromWebSocketVO);ChatMessageVO.setText(text);ChatMessageVO.setChatType(chatType);ChatMessageVO.setCreateTime(DateUtil.format(new Date(), "yyyy年MM月dd日 HH:mm:ss"));if (user.getRole() == ADMIN_ROLE) {ChatMessageVO.setIsAdmin(true);}User loginUser = (User) this.httpSession.getAttribute(USER_LOGIN_STATE);if (loginUser.getId() == user.getId()) {ChatMessageVO.setIsMy(true);}String toJson = new Gson().toJson(ChatMessageVO);sendAllMessage(toJson);saveChat(user.getId(), null, text, null, chatType);chatService.deleteKey(CACHE_CHAT_HALL, String.valueOf(user.getId()));}/*** 私聊** @param user     用戶* @param toId     為id* @param text     文本* @param chatType 聊天類型*/private void privateChat(User user, Long toId, String text, Integer chatType) {ChatMessageVO ChatMessageVO = chatService.chatResult(user.getId(), toId, text, chatType, DateUtil.date(System.currentTimeMillis()));User loginUser = (User) this.httpSession.getAttribute(USER_LOGIN_STATE);if (loginUser.getId() == user.getId()) {ChatMessageVO.setIsMy(true);}String toJson = new Gson().toJson(ChatMessageVO);sendOneMessage(toId.toString(), toJson);saveChat(user.getId(), toId, text, null, chatType);chatService.deleteKey(CACHE_CHAT_PRIVATE, user.getId() + "" + toId);chatService.deleteKey(CACHE_CHAT_PRIVATE, toId + "" + user.getId());}/*** 保存聊天** @param userId   用戶id* @param toId     為id* @param text     文本* @param teamId   團隊id* @param chatType 聊天類型*/private void saveChat(Long userId, Long toId, String text, Long teamId, Integer chatType) {
//        if (chatType == PRIVATE_CHAT) {
//            User user = userService.getById(userId);
//            Set<Long> userIds = stringJsonListToLongSet(user.getFriendIds());
//            if (!userIds.contains(toId)) {
//                sendError(String.valueOf(userId), "該用戶不是你的好友");
//                return;
//            }
//        }Chat chat = new Chat();chat.setFromId(userId);chat.setText(String.valueOf(text));chat.setChatType(chatType);chat.setCreateTime(new Date());if (toId != null && toId > 0) {chat.setToId(toId);}if (teamId != null && teamId > 0) {chat.setTeamId(teamId);}chatService.save(chat);}/*** 發送失敗** @param userId       用戶id* @param errorMessage 錯誤消息*/private void sendError(String userId, String errorMessage) {JSONObject obj = new JSONObject();obj.set("error", errorMessage);sendOneMessage(userId, obj.toString());}/*** 廣播消息** @param message 消息*/public void sendAllMessage(String message) {for (Session session : SESSIONS) {try {if (session.isOpen()) {synchronized (session) {session.getBasicRemote().sendText(message);}}} catch (Exception e) {e.printStackTrace();}}}/*** 發送一個消息** @param userId  用戶編號* @param message 消息*/public void sendOneMessage(String userId, String message) {Session session = SESSION_POOL.get(userId);if (session != null && session.isOpen()) {try {synchronized (session) {session.getBasicRemote().sendText(message);}} catch (Exception e) {e.printStackTrace();}}}/*** 給所有用戶*/public void sendAllUsers() {HashMap<String, List<WebSocketVO>> stringListHashMap = new HashMap<>(0);List<WebSocketVO> WebSocketVOs = new ArrayList<>();stringListHashMap.put("users", WebSocketVOs);for (Serializable key : SESSION_POOL.keySet()) {User user = userService.getById(key);WebSocketVO WebSocketVO = new WebSocketVO();BeanUtils.copyProperties(user, WebSocketVO);WebSocketVOs.add(WebSocketVO);}sendAllMessage(JSONUtil.toJsonStr(stringListHashMap));}
}

這是自己的代碼

package com.ruoyi.webSocket;import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.room.domain.Room;
import com.ruoyi.room.service.IRoomService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;import javax.websocket.*;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicInteger;@Component
@ServerEndpoint("/module/websocket/{userId}/{roomId}")
public class WebSocketServer implements ApplicationContextAware {private static IRoomService roomService;private static final Logger log = LoggerFactory.getLogger(WebSocketServer.class);// 保存隊伍的連接信息 - 新增private static final Map<String, ConcurrentHashMap<String, WebSocketServer>> ROOMS = new HashMap<>();//靜態變量,用來記錄當前在線連接數。應該把它設計成線程安全的。private static AtomicInteger onlineNum = new AtomicInteger();//concurrent包的線程安全Set,用來存放每個客戶端對應的WebSocketServer對象。private static ConcurrentHashMap<String, Session> sessionPools = new ConcurrentHashMap<>();// 線程安全list,用來存放 在線客戶端賬號public static List<String> userList = new CopyOnWriteArrayList<>();// 連接成功@OnOpenpublic void onOpen(Session session, @PathParam(value = "userId") String userId, @PathParam(value = "roomId") String roomId) {// 創建session給客戶sessionPools.put(userId, session);if (!userList.contains(userId)) {addOnlineCount();userList.add(userId);}try {if (StringUtils.isBlank(userId) || "undefined".equals(userId) ||StringUtils.isBlank(roomId) || "undefined".equals(roomId)) {sendError(userId, "參數有誤");return;}if (!ROOMS.containsKey(roomId)) {// 房間不存在 創建房間ConcurrentHashMap<String, WebSocketServer> room = new ConcurrentHashMap<>(0);room.put(userId, this);ROOMS.put(String.valueOf(roomId), room);} else {if (!ROOMS.get(roomId).containsKey(userId)) {// 房間存在 客戶不存在 房間加入客戶ROOMS.get(roomId).put(userId, this);}}log.debug("ID為【" + userId + "】的用戶加入websocket!當前在線人數為:" + onlineNum);log.debug("當前在線:" + userList);} catch (Exception e) {e.printStackTrace();}}/*** 關閉連接* @param userId*/@OnClosepublic void onClose(@PathParam(value = "userId") String userId) {sessionPools.remove(userId);if (userList.contains(userId)) {userList.remove(userId);subOnlineCount();}log.debug(userId + "斷開webSocket連接!當前人數為" + onlineNum);}/*** 消息監聽 接收客戶端消息* @param message* @throws IOException*/@OnMessagepublic void onMessage(String message) throws IOException {JSONObject jsonObject = JSONObject.parseObject(message);String userId = jsonObject.getString("userId");String roomId = jsonObject.getString("roomId");String type = jsonObject.getString("type");if (type.equals(MessageType.DETAIL.getType())) {log.debug("房間詳情");try {Room room = roomService.selectRoomById(Long.parseLong(roomId));jsonObject.put("roomInfo", room);ConcurrentHashMap<String, WebSocketServer> map = ROOMS.get(roomId);// 獲取玩家列表 keySet獲取map集合key的集合  然后在遍歷key即可for (String key : map.keySet()) {try {sendToUser(key, JSONObject.toJSONString(jsonObject));} catch (Exception e) {e.printStackTrace();}}} catch (NumberFormatException e) {System.out.println("轉換錯誤: " + e.getMessage());}}}/*** 連接錯誤* @param session* @param throwable* @throws IOException*/@OnErrorpublic void onError(Session session, Throwable throwable) throws IOException {log.error("websocket連接錯誤!");throwable.printStackTrace();}/*** 發送消息*/public void sendMessage(Session session, String message) throws IOException, EncodeException {if (session != null) {synchronized (session) {session.getBasicRemote().sendText(message);}}}/*** 給指定用戶發送信息*/public void sendToUser(String userId, String message) {Session session = sessionPools.get(userId);try {if (session != null) {sendMessage(session, message);}else {log.debug("推送用戶不在線");}} catch (Exception e) {e.printStackTrace();}}public static void addOnlineCount() {onlineNum.incrementAndGet();}public static void subOnlineCount() {onlineNum.decrementAndGet();}/*** 發送失敗** @param userId       用戶id* @param errorMessage 錯誤消息*/private void sendError(String userId, String errorMessage) {JSONObject obj = new JSONObject();obj.put("error", errorMessage);sendOneMessage(userId, obj.toString());}/*** 發送一個消息** @param userId  用戶編號* @param message 消息*/public void sendOneMessage(String userId, String message) {Session session = sessionPools.get(userId);if (session != null && session.isOpen()) {try {synchronized (session) {session.getBasicRemote().sendText(message);}} catch (Exception e) {e.printStackTrace();}}}
}

修改后的代碼

package com.ruoyi.webSocket;import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.room.domain.Room;
import com.ruoyi.room.service.IRoomService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;import javax.websocket.*;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicInteger;@Component
@ServerEndpoint("/module/websocket/{userId}/{roomId}")
public class WebSocketServer implements ApplicationContextAware {private static ApplicationContext context;@Overridepublic void setApplicationContext(ApplicationContext applicationContext) throws BeansException {context = applicationContext;}public static <roomService> roomService getBean(Class<roomService> beanClass) {return context.getBean(beanClass);}private static final Logger log = LoggerFactory.getLogger(WebSocketServer.class);// 保存隊伍的連接信息 - 新增private static final Map<String, ConcurrentHashMap<String, WebSocketServer>> ROOMS = new HashMap<>();//靜態變量,用來記錄當前在線連接數。應該把它設計成線程安全的。private static AtomicInteger onlineNum = new AtomicInteger();//concurrent包的線程安全Set,用來存放每個客戶端對應的WebSocketServer對象。private static ConcurrentHashMap<String, Session> sessionPools = new ConcurrentHashMap<>();// 線程安全list,用來存放 在線客戶端賬號public static List<String> userList = new CopyOnWriteArrayList<>();// 連接成功@OnOpenpublic void onOpen(Session session, @PathParam(value = "userId") String userId, @PathParam(value = "roomId") String roomId) {// 創建session給客戶sessionPools.put(userId, session);if (!userList.contains(userId)) {addOnlineCount();userList.add(userId);}try {if (StringUtils.isBlank(userId) || "undefined".equals(userId) ||StringUtils.isBlank(roomId) || "undefined".equals(roomId)) {sendError(userId, "參數有誤");return;}if (!ROOMS.containsKey(roomId)) {// 房間不存在 創建房間ConcurrentHashMap<String, WebSocketServer> room = new ConcurrentHashMap<>(0);room.put(userId, this);ROOMS.put(String.valueOf(roomId), room);} else {if (!ROOMS.get(roomId).containsKey(userId)) {// 房間存在 客戶不存在 房間加入客戶ROOMS.get(roomId).put(userId, this);}}log.debug("ID為【" + userId + "】的用戶加入websocket!當前在線人數為:" + onlineNum);log.debug("當前在線:" + userList);} catch (Exception e) {e.printStackTrace();}}/*** 關閉連接* @param userId*/@OnClosepublic void onClose(@PathParam(value = "userId") String userId) {sessionPools.remove(userId);if (userList.contains(userId)) {userList.remove(userId);subOnlineCount();}log.debug(userId + "斷開webSocket連接!當前人數為" + onlineNum);}/*** 消息監聽 接收客戶端消息* @param message* @throws IOException*/@OnMessagepublic void onMessage(String message) throws IOException {JSONObject jsonObject = JSONObject.parseObject(message);String userId = jsonObject.getString("userId");String roomId = jsonObject.getString("roomId");String type = jsonObject.getString("type");if (type.equals(MessageType.DETAIL.getType())) {log.debug("房間詳情");try {Room room = context.getBean(IRoomService.class).selectRoomById(Long.parseLong(roomId));jsonObject.put("roomInfo", room);ConcurrentHashMap<String, WebSocketServer> map = ROOMS.get(roomId);// 獲取玩家列表 keySet獲取map集合key的集合  然后在遍歷key即可for (String key : map.keySet()) {try {sendToUser(key, JSONObject.toJSONString(jsonObject));} catch (Exception e) {e.printStackTrace();}}} catch (NumberFormatException e) {System.out.println("轉換錯誤: " + e.getMessage());}}}/*** 連接錯誤* @param session* @param throwable* @throws IOException*/@OnErrorpublic void onError(Session session, Throwable throwable) throws IOException {log.error("websocket連接錯誤!");throwable.printStackTrace();}/*** 發送消息*/public void sendMessage(Session session, String message) throws IOException, EncodeException {if (session != null) {synchronized (session) {session.getBasicRemote().sendText(message);}}}/*** 給指定用戶發送信息*/public void sendToUser(String userId, String message) {Session session = sessionPools.get(userId);try {if (session != null) {sendMessage(session, message);}else {log.debug("推送用戶不在線");}} catch (Exception e) {e.printStackTrace();}}public static void addOnlineCount() {onlineNum.incrementAndGet();}public static void subOnlineCount() {onlineNum.decrementAndGet();}/*** 發送失敗** @param userId       用戶id* @param errorMessage 錯誤消息*/private void sendError(String userId, String errorMessage) {JSONObject obj = new JSONObject();obj.put("error", errorMessage);sendOneMessage(userId, obj.toString());}/*** 發送一個消息** @param userId  用戶編號* @param message 消息*/public void sendOneMessage(String userId, String message) {Session session = sessionPools.get(userId);if (session != null && session.isOpen()) {try {synchronized (session) {session.getBasicRemote().sendText(message);}} catch (Exception e) {e.printStackTrace();}}}
}

核心代碼

 private static ApplicationContext context;@Overridepublic void setApplicationContext(ApplicationContext applicationContext) throws BeansException {context = applicationContext;}public static <roomService> roomService getBean(Class<roomService> beanClass) {return context.getBean(beanClass);}
Room room = context.getBean(IRoomService.class).selectRoomById(Long.parseLong(roomId));

原因:執行的先后順序吧,具體還沒仔細了解

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/web/71701.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/71701.shtml
英文地址,請注明出處:http://en.pswp.cn/web/71701.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

《A++ 敏捷開發》- 18 軟件需求

需求并不是關于需求 (Requirements are not really about requirements) 大家去公共圖書館寄存物品&#xff0c;以前都是掃二維碼開箱&#xff0c;有些圖書館升級了使用指紋識別。 “是否新方法比以前好&#xff1f;”我問年輕的開發人員。 “當然用指紋識別好。新技術&#x…

基于AMD AU15P FPGA的SLVS-EC橋PCIe設計方案分享

作者&#xff1a;Hello,Panda 各位FPGAer周末愉快&#xff0c;今天熊貓君分享一個基于AMD AU15P FPGA的SLVS-EC橋PCIe設計方案。 一、方案背景 先說方案的應用背景&#xff1a;眾所周知&#xff0c;較為上層的如基于AI的機器視覺應用&#xff0c;大多基于高端的專用SoC、AI專…

Redis|Springboot集成Redis

文章目錄 總體概述本地Java連接Redis常見問題集成Jedis集成lettuce集成RedisTemplate——推薦使用連接單機連接集群 總體概述 jedis-lettuce-RedisTemplate三者的聯系 jedis第一代lettuce承上啟下redistemplate著重使用 本地Java連接Redis常見問題 bind配置請注釋掉保護模式…

機器學習(六)

一&#xff0c;決策樹&#xff1a; 簡介&#xff1a; 決策樹是一種通過構建類似樹狀的結構&#xff08;顛倒的樹&#xff09;&#xff0c;從根節點開始逐步對數據進行劃分&#xff0c;最終在葉子節點做出預測結果的模型。 結構組成&#xff1a; 根節點&#xff1a;初始的數據集…

恢復IDEA的Load Maven Changes按鈕

寫代碼的時候不知道點到什么東西了&#xff0c;pom文件上的這個彈窗就是不出來了&#xff0c;重啟IDEA&#xff0c;reset windos都沒用&#xff0c;網上搜也沒收到解決方案 然后開打開其他項目窗口時&#xff0c;看到那個的功能名叫 Hide This Notification 于是跑到Setting里…

怎么使用Sam Helper修改手機屏幕分辨率,使得游戲視野變廣?

1.準備Shizuku 和Sam Helper軟件 2.打開設置&#xff0c;找到關于本機&#xff0c;連續點擊版本號五次打開開發者選項 3.找到開發者選項&#xff0c;打開USB調試和無線調試 4.返回桌面&#xff0c;我們接著打開shizuku,點擊配對&#xff0c;這里打開開發者選項&#xff0c;找…

【招聘精英】

我們公司是一個位于石家莊的一個科技型新型技術公司。主要做人力資源、用工、科技等方面。 有意向回石家莊的或者已經在石家莊的技術大咖、軟件大牛、產品大佬、UI大神可以來了解一下。 現在招聘 高級前端開發 高級java開發 其他崗位也可以聯系。 有意向的朋友可以私信我。 -…

大模型信息整理

1. Benchmarks Reasoning, conversation, Q&A benchmarks HellaSwagBIG-Bench HardSQuADIFEvalMuSRMMLU-PROMT-BenchDomain-specific benchmarks GPQAMedQAPubMedQAMath benchmarks GSM8KMATHMathEvalSecurity-related benchmarks PyRITPurple Llama CyberSecEval2. 國內外…

Redis-限流方案

在實際業務中&#xff0c;可能會遇到瞬時流量劇增的情況&#xff0c;大量的請求可能會導致服務器過載和宕機。為了保護系統自身和上下游服務&#xff0c;需要采用限流的方式&#xff0c;拒絕部分請求。 限流就是對請求的頻率進行控制&#xff0c;迅速拒絕超過請求閾值的請求。 …

無感方波開環強拖總結

一、強拖階段的核心原理與設計要點 開環換相邏輯 固定頻率斜坡&#xff1a;以預設斜率逐步提升換相頻率&#xff08;如0.5-5Hz/ms&#xff09;&#xff0c;強制電機跟隨磁場旋轉。電壓-頻率協調控制&#xff1a;初始階段施加高電壓&#xff08;80%-100%額定&#xff09;克服靜摩…

Java虛擬機之垃圾收集(一)

目錄 一、如何判定對象“生死”&#xff1f; 1. 引用計數算法&#xff08;理論參考&#xff09; 2. 可達性分析算法&#xff08;JVM 實際使用&#xff09; 3. 對象的“緩刑”機制 二、引用類型與回收策略 三、何時觸發垃圾回收&#xff1f; 1. 分代回收策略 2. 手動觸發…

代碼隨想錄算法訓練營第22天 | 組合 組合總和 電話號碼的字母組合

77. 組合 77. 組合 - 力扣&#xff08;LeetCode&#xff09; class Solution {List<Integer> path new ArrayList<>();List<List<Integer>> result new ArrayList<>();public void backTracking(int n,int k,int startIndex){if(path.size() …

#UVM# 關于field automation機制中的標志位及if的使用

通過前面文章的復習,我們知道了 uvm_field 機制帶來的好處,確實方便了我們很多代碼的coding 時間,但是會不會有一種情況呢? 比如,我們不想將實例中的某一些成員進行打包、復制、比較操作,怎么辦呢? 如果只執行 比較但不進行打包操作呢?是不是很復雜呢 ? 一 標志位…

RK3588 安裝ffmpeg6.1.2

在安裝 ffmpeg 在 RK3588 開發板上時,你需要確保你的開發環境(例如 Ubuntu、Debian 或其他 Linux 發行版)已經設置好了交叉編譯工具鏈,以便能夠針對 RK3588 架構編譯軟件。以下是一些步驟和指導,幫助你安裝 FFmpeg: 1. 安裝依賴項 首先,確保你的系統上安裝了所有必要的…

leetcode day25 28 KMP算法

28找出字符串中第一個匹配項的下標 給你兩個字符串 haystack 和 needle &#xff0c;請你在 haystack 字符串中找出 needle 字符串的第一個匹配項的下標&#xff08;下標從 0 開始&#xff09;。如果 needle 不是 haystack 的一部分&#xff0c;則返回 -1 。 示例 1&#xff…

編程語言介紹:Rust

什么是Rust Rust是由Mozilla研究院開發的一種系統級編程語言&#xff0c;旨在提供更好的內存安全保證&#xff0c;同時保持高性能&#xff0c;自2010年首次發布以來&#xff0c;Rust以其安全性、并發性和實用性迅速獲得了廣泛的關注。Rust最獨特的特性之一是其所有權模型&#…

Java Spring MVC (2)

常見的Request Controller 和 Response Controller 的區別 用餐廳點餐來理解 想象你去一家餐廳吃飯&#xff1a; Request Controller&#xff08;接單員&#xff09;&#xff1a;負責處理你的點餐請求&#xff0c;記錄你的口味、桌號等信息。Response Controller&#xff08…

Oracle 字符類型對比

本文以 Oracle12c 為例 1.主要區別對比 類型存儲方式最大長度字符集支持適用場景備注?CHAR(M)固定長度空格填充2000 字節&#xff0c;M 代表字節長度默認字符集固定長度編碼實際存儲長度固定為定義長度&#xff08;如 CHAR(10) 始終占 10 字節&#xff09;?VARCHAR2(M)可變長…

Linux系列:如何用heaptrack跟蹤.NET程序的非托管內存泄露

一&#xff1a;背景 1. 講故事 前面跟大家分享過一篇 C# 調用 C代碼引發非托管內存泄露 的文章&#xff0c;這是一個故意引發的正向泄露&#xff0c;這一篇我們從逆向的角度去洞察引發泄露的禍根代碼&#xff0c;這東西如果在 windows 上還是很好處理的&#xff0c;很多人知道開…

vite.config.js 是Vite 項目的配置文件,分析具體用法

vite.config.js 是 Vite 項目的配置文件&#xff0c;用于定義項目的構建、開發服務器、插件等配置選項。以下是示例代碼中各部分的作用分析&#xff1a; 1. 導入模塊 import { fileURLToPath, URL } from node:url import { defineConfig } from vite import vue from vitejs…