xml <dependency>
<groupId>org.java-websocket</groupId>
<artifactId>Java-WebSocket</artifactId>
<version>1.5.3</version> <!-- 使用最新版本 -->
</dependency>
目的是项目启动的时候自动去连接webSocket地址
javaimport com.lhw.WsRobClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
import java.net.URI;
import java.net.URISyntaxException;
@Configuration
public class WebSocketConfig {
@Value("${websocket.url}")
private String url;
@Bean
public WsRobClient wsClient() throws URISyntaxException {
WsRobClient client=new WsRobClient(new URI(url));
client.connect();
return client;
}
}
WebSocketServer的目的是为了实时推送数据到客户端,才使用webSocket的双全工的方式
spring简单实现有两种方式
在Spring框架中配置WebSocket服务器时,您可以选择使用WebSocketConfigurer接口或者通过@ServerEndpoint注解配合ServerEndpointExporter bean来配置WebSocket端点。这两种方式各有优缺点,适用于不同的场景。
优点:
缺点:
学习曲线: 需要熟悉Spring WebSocket的配置和使用方式。
优点:
缺点:
然而,如果您的项目比较简单,或者您更熟悉Java EE WebSocket API的标准实现方式,并且不需要与Spring框架进行深度集成,那么使用@ServerEndpoint注解和ServerEndpointExporter也是一种可行的选择。
springBoot项目需要引入spring的webSocket依赖
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-websocket</artifactId> </dependency>
配置类
java
@Configuration
public class WebSocketConfig {
@Bean
public ServerEndpointExporter serverEndpointExporter(){
return new ServerEndpointExporter();
}
}
前端获取不到header里面的文件名 后端代码
java
try (OutputStream outputStream = res.getOutputStream()) {
res.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode((String) fileList.get(0).get("fileName"), "utf-8"));
res.setHeader("Content-Type", "application/vnd.openxmlformats-officedocument.wordprocessingml.document");
// 将字节数组写入输出流
outputStream.write((byte[]) fileList.get(0).get("bytes"));
// 刷新输出流,确保所有数据都被发送出去
outputStream.flush();
} catch (IOException e) {
// 异常处理
throw new SystemException(500, "导出word文件失败!");
}
加上
java res.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
当我们给一个继承了父类的子类上使用@Data、@ToString、@EqualsAndHashCode 注解时,IDEA 会发出警告,大概内容如下:
Generating equals/hashCode implementation but without a call to superclass, even though this class does not extend java.lang.Object. If this is intentional, add ‘(callSuper=false)’ to your type.
在项目根目录下创建lombok.config文件
configconfig.stopBubbling = true lombok.tostring.callsuper=CALL lombok.equalsandhashcode.callsuper=CALL lombok.accessors.chain=true
nvm是管理node的工具,支持多版本的切换使用,github官网
在系统设置中卸载原来node.js
下载地址,选择nvm-setup.exe 一键安装
进入nvm安装目录找到settings文件,打开文件另起一行,粘贴内容
node_mirror: https://npmmirror.com/mirrors/node/ npm_mirror: https://npmmirror.com/mirrors/npm/
在终端输入 nvm list available, 查看网络可以安装的版本
找到合适的版本之后输入
nvm install 20.12.2
等待下载完成后输入
nvm use 20.12.2
查看node版本和npm版本
输入node -v 和 npm -v
nvm list