我正在制作一个webapp,其中一个页面需要显示用户在注册页面中选择的日期。现在,日期根本不打印。
以下是我试图打印该值的方法。
<c:out value="${showDate}"></c:out>
这是控制器
@RequestMapping(value = "/done", method = RequestMethod.GET)
public ModelAndView done(User user) {
ModelAndView model = new ModelAndView();
String showDate = user.getInstallationDate();
model.addObject("showDate", showDate);
model.setViewName("done");
return model;
}
以下是如何制作installationDate()
@Column(name = "installation_date")
private String installationDate;
public String getInstallationDate() {
return installationDate;
}
public void setInstallationDate(String installationDate) {
this.installationDate = installationDate;
}
有人能告诉我这里我做错了什么吗?如果需要更多代码或解释,请告诉我。
答案 0 :(得分:0)
我解决了我的问题。我不完全确定为什么这样做有效,所以如果有人想在评论中详细说明,以便其他人可以看到,感觉自由。
现在是我的代码。
@RequestMapping(value = "/done**", method = RequestMethod.GET)
public ModelAndView done(@ModelAttribute("user") User user) {
ModelAndView model = new ModelAndView();
String installationDate = user.getInstallationDate();
model.addObject("installationDate", installationDate);
model.setViewName("done");
return model;
}
我按照这样打印
${user.installationDate}
我在jsp中添加了这个
<form:form method="POST" modelAttribute="user" commandName="user">
我在body标记后面添加了form标记,并在body的结束标记旁边添加了结束标记。
我没有更改getter和setter