使用springboot框架进行数据库信息的读取并且展示在页面上。Springboot框架相对来说比较简单,直接在pom文件中加入依赖就可以直接使用服务器,不需要再搭建tomcat。
- 定义映射实体类,类中的属性和类型要和数据库表中的字段相对应
@Entity
public class ExceptionOutput {
@Id
@GeneratedValue(strategy= GenerationType.AUTO)
private int id;
private String fan_no;
private String call_time;
private int call_count;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public void setFan_no(String fan_no) {
this.fan_no = fan_no;
}
@Override
public String toString() {
return "ExceptionOutput{" +
"id=" + id +
", fan_no='" + fan_no + '\'' +
", call_time='" + call_time + '\'' +
", call_count=" + call_count +
'}';
}
public void setCall_time(String call_time) {
this.call_time = call_time;
}
public void setCall_count(int call_count) {
this.call_count = call_count;
}
public String getFan_no() {
return fan_no;
}
public int getCall_count() {
return call_count;
}
public String getCall_time() {
return call_time;
}
}
- 定义数据访问层
public interface ExceptionInfoRepository extends JpaRepository<ExceptionOutput, Long> {
}
- 定义Controller类
@Controller
public class InforController {
@Autowired
private ExceptionInfoRepository info;
@RequestMapping("/query")
@ResponseBody
public List queryAll(){
return info.findAll();
}
@RequestMapping("/hat")
public String Show(Model model){
model.addAttribute("info",info.findAll());
return "blank";
}
- 进行数据访问并输出到表格中
</div>
<div class="row">
<div class="col-md-12">
<div class="alert alert-success">
<table border="2" align="center">
<tr>
<td>序号</td>
<td>风机编号</td>
<td>报警时间</td>
<td>30s内温度高于80度次数</td>
</tr>
<tr th:each ="i:${info}">
<td th:text = "${i.id}"></td>
<td th:text = "${i.fan_no}"></td>
<td th:text = "${i.call_time}"></td>
<td th:text = "${i.call_count}"></td>
</tr>
</table>
</div>
</div>
</div>
工程源码
注解需要注意几个相应的类对应要明确