当前位置: 首页 > news >正文

一个静态网页多少钱网站怎么优化搜索

一个静态网页多少钱,网站怎么优化搜索,武汉网站优化方案,阿里云备案网站备案系列文章目录 一、SpringBoot连接MySQL数据库实例【tk.mybatis连接mysql数据库】 二、SpringBoot连接Redis与Redisson【代码】 三、SpringBoot整合WebSocket【代码】 四、SpringBoot整合ElasticEearch【代码示例】 文章目录 系列文章目录代码下载地址一、效果演示二、引入依赖…

系列文章目录

一、SpringBoot连接MySQL数据库实例【tk.mybatis连接mysql数据库】
二、SpringBoot连接Redis与Redisson【代码】
三、SpringBoot整合WebSocket【代码】
四、SpringBoot整合ElasticEearch【代码示例】


文章目录

  • 系列文章目录
  • 代码下载地址
  • 一、效果演示
  • 二、引入依赖
  • 三、WebSocketConfig
  • 四、SessionWrap
  • 五、WebSocketServer


代码下载地址

SpringBoot整合WebSocket【代码】


一、效果演示

测试链接
在这里插入图片描述

在这里插入图片描述

二、引入依赖

<!--    websocket    -->
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-websocket</artifactId><version>2.1.1.RELEASE</version>
</dependency>

三、WebSocketConfig

@Configuration
public class WebSocketConfig {@Beanpublic ServerEndpointExporter serverEndpointExporter() {return new ServerEndpointExporter();}
}

四、SessionWrap

SessionWrap 可根据具体需求自定义

@Data
public class SessionWrap {private String from;	// 连接Idprivate String type;	// 来凝结类型private Session session;private Date lastTime;
}

五、WebSocketServer

@Slf4j
@Component
@ServerEndpoint(value = "/api/websocket/{from}/{type}")
public class WebSocketServer {@Autowiredprivate MessageService messageService;public static WebSocketServer webSocketServer;// 所有的连接会话private static CopyOnWriteArraySet<SessionWrap> sessionList = new CopyOnWriteArraySet<>();private String from;private String type;@PostConstructpublic void init() {webSocketServer = this;webSocketServer.messageService = this.messageService;}/*** @author Lee* @date 2023/7/18 13:57* @description 创建连接*/@OnOpenpublic void onOpen(Session session, @PathParam(value = "from") String from, @PathParam(value = "type") String type) {this.from = from;this.type = type;try {// 遍历list,如果有会话,更新,如果没有,创建一个新的for (SessionWrap item : sessionList) {if (item.getFrom().equals(from) && item.getType().equals(type)) {item.setSession(session);item.setLastTime(new Date());log.info("【websocket消息】更新连接,总数为:" + sessionList.size());return;}}SessionWrap sessionWrap = new SessionWrap();sessionWrap.setFrom(from);sessionWrap.setType(type);sessionWrap.setSession(session);sessionWrap.setLastTime(new Date());sessionList.add(sessionWrap);log.info("【websocket消息】有新的连接,总数为:" + sessionList.size());} catch (Exception e) {log.info("【websocket消息】连接失败!错误信息:" + e.getMessage());}}/*** @author Lee* @date 2023/7/18 13:57* @description 关闭连接*/@OnClosepublic void onClose() {try {sessionList.removeIf(item -> item.getFrom().equals(from) && item.getType().equals(type));log.info("【websocket消息】连接断开,总数为:" + sessionList.size());} catch (Exception e) {log.info("【websocket消息】连接断开失败!错误信息:" + e.getMessage());}}/*** @author Lee* @date 2023/7/18 14:04* @description 发送消息*/@OnMessagepublic void onMessage(String message, Session session) {try {// 对消息进行处理JSONObject r = webSocketServer.messageService.insertMessage(message);String userId = r.getString("userId");for (SessionWrap item : sessionList) {// 发送消息的判断逻辑可根据需求修改if (item.getFrom().equals(userId) && item.getType().equals("test")) {item.getSession().getBasicRemote().sendText(r.toJSONString());log.info("【websocket消息】发送消息成功:" + r.toJSONString());}}} catch (Exception e) {log.info("【websocket消息】发送消息失败!错误信息:" + e.getMessage());}}@OnErrorpublic void onError(Session session, Throwable error) {log.error("用户错误,原因:"+error.getMessage());error.printStackTrace();}}
http://www.wangmingla.cn/news/125380.html

相关文章:

  • 产品互联网做推广做什么网站好网络推广与网络营销的区别
  • 浙江天奥建设集团网站2020年度关键词有哪些
  • 做网站销售怎么样搜索指数查询平台
  • 建设网站论文范文查询网站备案信息
  • 做众筹网站有哪些百度搜索引擎优化方式
  • 网站开发技术文档seo营销服务
  • 陕西专业网站开发公司手机网站自助建站系统
  • 郑州网站排名优化公司常州seo关键词排名
  • wordpress 曲线表seo排名是什么意思
  • 网站空间怎么续费太原网站建设制作
  • 山西网站建设免费国内可访问的海外网站和应用
  • 单页销售网站制作制作衡阳有实力seo优化
  • wordpress主题 直接拖拽式建站国外免费ip地址
  • 黑色网站后台文明seo
  • 东莞网站策划如何网上免费做推广
  • 南通做网站的公司平台推广是什么工作
  • 做色情网站牟利200万判刑怎么建立一个网站
  • 顶呱呱集团 网站建设seo顾问服务
  • 025网站建设网站排名点击工具
  • 如何建设简易网站南京百度竞价推广公司排名
  • 新洲城乡建设局网站学生网页制作成品
  • 做网站爬闪杭州百度快照优化公司
  • 花钱做网站不给源码宁德市是哪个省
  • 如何给别人做网站赚钱独立站seo是什么
  • wordpress 付款查看优质的seo快速排名优化
  • 免费域名网站建设今日头条郑州头条新闻
  • 深圳网络科技公司排名10seo排名平台
  • 上海网站制作开发公司寻找郑州网站优化公司
  • 手机网站可以做商城吗贵州网站seo
  • 装修网站有哪些免费b站软件推广网站2023