html页面显示java后台传递的对象

#html页面获取java后台传递的对象
springboot+themleaf
######使用EL表达式
在前台el表达式中,获取后台传的实体对象集合的值 例如:th:text=${entity.id}
是先通过取实体类的id成员 如果成员是private 继续通过getID()方法取id值
所以entity.id的名称不能随便乱取,要按照id成员的get方法取
######前台代码

<th th:text="${ofd.id}">订单编号</th>
<th th:text="${ofd.ywType}">业务类型</th>
<th th:text="${ofd.orderType}">订单类型</th> 
<th th:text="${ofd.price}">订单金额</th> 

######定义的类的部分代码

	private int id;//订单编号
	private String ywType;//业务类型
	private String orderType;//订单类型
	private float price;//订单金额
	/**
	省略其它代码
	*/
	public int getId(){
		return this.id;
	}
	public String getYwType(){
		return this.ywType;
	}
	public String getOrderType() { 
		return orderType;
	}
	public float getPrice(){
		return this.price;
	}
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 9
    评论
这里给出一个简单的例子,假设你已经有了一个能够查询数据的 Java 后台程序,并且查询结果已经存储在一个 List 对象,接下来我们可以通过 JSP 页面将数据以 HTML 表格的形式展示出来。 1. 在 JSP 页面引入 JSTL 标签库和样式表 ```jsp <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>查询结果</title> <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.5.3/css/bootstrap.min.css"> </head> <body> ``` 2. 在 JSP 页面使用 JSTL 遍历 List 对象,生成 HTML 表格 ```jsp <div class="container"> <table class="table"> <thead> <tr> <th>ID</th> <th>姓名</th> <th>年龄</th> </tr> </thead> <tbody> <c:forEach var="user" items="${users}"> <tr> <td>${user.id}</td> <td>${user.name}</td> <td>${user.age}</td> </tr> </c:forEach> </tbody> </table> </div> ``` 3. 在 Java 后台程序将查询结果存储在 List 对象,并将该对象传递给 JSP 页面 ```java List<User> userList = userService.queryUsers(); request.setAttribute("users", userList); request.getRequestDispatcher("result.jsp").forward(request, response); ``` 完整的 JSP 页面代码如下: ```jsp <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>查询结果</title> <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.5.3/css/bootstrap.min.css"> </head> <body> <div class="container"> <table class="table"> <thead> <tr> <th>ID</th> <th>姓名</th> <th>年龄</th> </tr> </thead> <tbody> <c:forEach var="user" items="${users}"> <tr> <td>${user.id}</td> <td>${user.name}</td> <td>${user.age}</td> </tr> </c:forEach> </tbody> </table> </div> </body> </html> ``` 需要注意的是,这只是一个简单的例子,实际情况还需要考虑数据的分页、筛选、排序等功能,以及数据安全性等问题。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值