【发布时间】:2019-02-23 07:00:32
【问题描述】:
我最近才开始学习 Spring 框架。在我的控制器中,我写了
@GetMapping("/users/{username}")
public String getUserByUsername(@PathVariable(value = "username") String username, ModelMap model) {
User founduser = userRepository.findById(username)
.orElseThrow(() -> new ResourceNotFoundException("User", "username", username));
model.addAttribute("founduser",founduser);
return "redirect:/profile";
}
然后,我尝试获取模型属性并将其打印到我的 JSP 中。
<c:when test="${not empty founduser}">
<table style="border: 1px solid;">
<c:forEach var="one" items="${founduser}">
<tr>
<td>${one.username}</td>
<td>${one.createdAt}</td>
</tr>
</c:forEach>
</table>
</c:when>
但是我发现test="${not empty founduser}总是false,说明我的founduser属性为null,调试的时候显示模型添加founduser成功。
谁能告诉我为什么会出错?非常感谢!
【问题讨论】:
标签: spring spring-boot jsp jstl