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

我这里用的是springboot、thymeleaf和mybatis-plus。
首先要在pom文件中加入相应依赖,如thymeleaf依赖,数据库驱动依赖等。
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下对应的代码

@Controller
@RequestMapping("/visitorInfo")
public class VisitorInfoController {
    @Autowired
    private 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页面下的变量名要与实体类对应,而不是与数据库属性名对应。

  • 2
    点赞
  • 45
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值