SpringBoot实现MySQL数据前端显示

使用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>  

这里写图片描述
工程源码
注解需要注意几个相应的类对应要明确

  • 7
    点赞
  • 48
    收藏
    觉得还不错? 一键收藏
  • 7
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值