使用websocket的初衷是,要实时更新mysql中的报警信息到web页面显示
没怎么碰过web,代码写的是真烂,不过也算是功能实现了,放在这里也是鞭策自己,web也要多下些功夫
准备
引入依赖
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
先看看mysql中数据的格式
数据封装
public class AlarmMessage {
private String fanNo;
private String time;
private String description;
public AlarmMessage(String fanNo, String time, String description) {
this.fanNo = fanNo;
this.time = time;
this.description = description;
}
public String getFanNo() {
return fanNo;
}
public String getTime() {
return time;
}
public String getDescription() {
return description;
}
}
jdbc从数据库中读取数据
public class DBUtil {
public