【发布时间】:2019-05-10 15:15:45
【问题描述】:
对于一个简单的 webapp,我试图在 jsp 端打印 ArrayList 的值是非常不直观的。我很难把这件事拼凑起来。
这是一个 Spring Boot 应用程序,以下是我发送的响应 --
@GetMapping("/")
public String welcome(Map<String, Object> model) {
List<APojo> lis = new ArrayList<>();
APojo po = new APojo();
po.setName("Apple");
po.setName("Ball");
lis.add(po);
model.put("fruits", lis);
return "index";
}
index.jsp 页面 --
<html>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html lang="en">
<head>
<title>Title goes here</title>
</head>
<body>
<c:set var = "fruitVal" value = "${fruits[0].name}"/>
<h2>Value: ${fruitVal}</h2>
</body>
</html>
我希望它显示 Apple,但它一直在打印 Ball。为什么?
【问题讨论】: