diff --git a/springboot-websocket/src/main/java/com/xncoding/jwt/handler/SocketHandler.java b/springboot-websocket/src/main/java/com/xncoding/jwt/handler/SocketHandler.java index b5ccef5..cab0da5 100644 --- a/springboot-websocket/src/main/java/com/xncoding/jwt/handler/SocketHandler.java +++ b/springboot-websocket/src/main/java/com/xncoding/jwt/handler/SocketHandler.java @@ -38,10 +38,10 @@ public class SocketHandler extends TextWebSocketHandler { // 我这儿并没有做处理,消息的封装格式一般有{from:xxxx,to:xxxxx,msg:xxxxx},来自哪里,发送给谁,什么消息等等 String msg = message.getPayload(); logger.info("msg = " + msg); - WsParam wsParam = JacksonUtil.json2Bean(msg, new TypeReference(){}); + WsParam wsParam = JacksonUtil.json2Bean(msg, new TypeReference>(){}); if ("list".equals(wsParam.getMethod())) { logger.info("call list method..."); - WsResponse response = new WsResponse(); + WsResponse response = new WsResponse<>(); response.setResult("hello list"); sendMessageToUser(session, new TextMessage(JacksonUtil.bean2Json(response))); } diff --git a/springboot-websocket/src/main/java/com/xncoding/jwt/model/WsParam.java b/springboot-websocket/src/main/java/com/xncoding/jwt/model/WsParam.java index 2b1e098..758920c 100644 --- a/springboot-websocket/src/main/java/com/xncoding/jwt/model/WsParam.java +++ b/springboot-websocket/src/main/java/com/xncoding/jwt/model/WsParam.java @@ -7,9 +7,9 @@ package com.xncoding.jwt.model; * @version 1.0 * @since 2018/3/22 */ -public class WsParam { +public class WsParam { private String method; - private Object param; + private T param; public String getMethod() { return method; @@ -19,11 +19,11 @@ public class WsParam { this.method = method; } - public Object getParam() { + public T getParam() { return param; } - public void setParam(Object param) { + public void setParam(T param) { this.param = param; } } diff --git a/springboot-websocket/src/main/java/com/xncoding/jwt/model/WsResponse.java b/springboot-websocket/src/main/java/com/xncoding/jwt/model/WsResponse.java index 42d8cc1..113ce02 100644 --- a/springboot-websocket/src/main/java/com/xncoding/jwt/model/WsResponse.java +++ b/springboot-websocket/src/main/java/com/xncoding/jwt/model/WsResponse.java @@ -7,14 +7,14 @@ package com.xncoding.jwt.model; * @version 1.0 * @since 2018/3/22 */ -public class WsResponse { - private Object result; +public class WsResponse { + private T result; - public Object getResult() { + public T getResult() { return result; } - public void setResult(Object result) { + public void setResult(T result) { this.result = result; } } diff --git a/springboot-websocket/src/test/java/com/xncoding/jwt/socket/client/html/index1.html b/springboot-websocket/src/test/java/com/xncoding/jwt/socket/client/html/index1.html index d33752a..db347be 100644 --- a/springboot-websocket/src/test/java/com/xncoding/jwt/socket/client/html/index1.html +++ b/springboot-websocket/src/test/java/com/xncoding/jwt/socket/client/html/index1.html @@ -3,10 +3,9 @@ 广播式WebSocket - - +
@@ -22,12 +21,50 @@