我正在尝试使用websocket并使用sock.js在spring中实现推送通知.
这些是代码片段:
public class NotifyController {
@MessageMapping("/notifications")
@SendTo("/get/notifications")
public Greeting greeting(HelloMessage message) throws Exception {
new Greeting("Hello, " + message.getName() + "!");
}
}
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
@Override
public void configureMessageBroker(MessageBrokerRegistry config) {
config.enableSimpleBroker("/get/notifications");
config.setApplicationDestinationPrefixes("/gssocket");
}
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/notifications").withSockJS();
}
}
Run Code Online (Sandbox Code Playgroud)
这是前面的代码..
function connect() {
var notificationSocket = new SockJS('/notifications');
stompNotificationClient = Stomp.over(notificationSocket);
stompNotificationClient.connect({}, function(frame) {
console.log('Connected: ' + frame);
stompNotificationClient.subscribe('/get/notifications', function(greeting){
showGreeting(JSON.parse(greeting.body).content);
});
});
}
function sendNotification() {
var name = "test" …Run Code Online (Sandbox Code Playgroud) 检查在控制器中传递的值的最佳方法是什么?
是断言还是如果?
如果这是示例网址....
我想检查 1 和 2 是否为数字以及是否为空。就像用户将 url 更改为http://example.com/read/1asdf/2asdfqwer 一样
我们在我们公司使用断言。我只是在想如果它已经处于生产模式并且断言被禁用会发生什么。
有人给我一个洞察力。