日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

将查询到的数据库数据显示到html页面

發(fā)布時間:2024/5/14 数据库 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 将查询到的数据库数据显示到html页面 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

我這里用的是springboot、thymeleaf和mybatis-plus。
首先要在pom文件中加入相應(yīng)依賴,如thymeleaf依賴,數(shù)據(jù)庫驅(qū)動依賴等。
html文件中要將html標簽改為

<html xmlns:th="http://www.thymeleaf.org"></html>

表示要使用thymeleaf

html主要代碼:

<table class="table"><thead><tr><th>序號</th><th>ip</th><th>visitorName</th><th>state</th><th>visitTime</th><th>customerServiceId</th></tr></thead><tbody><!--/*@thymesVar id="visitor_list" type=""*/--><tr th:each="cs,rowInfo : ${visitor_list}"><th>[[${rowInfo.count}]]</th><td>[[${cs.ip}]]</td><td>[[${cs.visitorname}]]</td><td>[[${cs.state}]]</td><td>[[${cs.visittime}]]</td><td>[[${cs.customerserviceid}]]</td></tr></tbody> </table>

controller下對應(yīng)的代碼

@Controller @RequestMapping("/visitorInfo") public class VisitorInfoController {@Autowiredprivate IVisitorInfoService iVisitorInfoService;@RequestMapping("/visitor")public String visitor(Model m){// 查詢所有 // List<T> list();ArrayList<VisitorInfo> arrayList= new ArrayList<>();arrayList= (ArrayList<VisitorInfo>) iVisitorInfoService.list();m.addAttribute("visitor_list",arrayList);//將arrayList隱藏到visitor_list中return "forward:/tables";}}

pojo下的實體類

@Data @EqualsAndHashCode(callSuper = false) public class VisitorInfo implements Serializable {private static final long serialVersionUID = 1L;private String ip;@TableField("visitorName")private String visitorname;private String terminal;private String browser;@TableField("screenSize")private String screensize;private String device;@TableField("customerServiceId")private Integer customerserviceid;private String state;@TableField("visitDuration")private Integer visitduration;@TableField("visitTime")private LocalDateTime visittime;}

注意:html頁面下的變量名要與實體類對應(yīng),而不是與數(shù)據(jù)庫屬性名對應(yīng)。

總結(jié)

以上是生活随笔為你收集整理的将查询到的数据库数据显示到html页面的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。