嗨,我正在关注Spring MVC 中将参数从 JSP 传递到控制器,显然我错过了一些东西,因为我得到了
javax.el.PropertyNotFoundException:在类型 com.outbottle.hellospring.entities.Movie 上找不到属性“标题”
关于我缺少什么的任何想法?
我的控制器:
package com.outbottle.hellospring.controllers;
import com.outbottle.hellospring.entities.Movie;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.SessionAttributes;
@Controller
@SessionAttributes("Movie")
public class FormPractice{
//display the form
@RequestMapping(value="/form", method= RequestMethod.GET)
public String form(ModelMap map) {
map.addAttribute("Movie", new Movie());
//return new ModelAndView("form", "movie", new Movie());
return "form";
}
// Process the form
@RequestMapping(value="/showMovies", method = RequestMethod.POST)
public String processMovieRegistration(@ModelAttribute("Movie") Movie moviedata,
BindingResult result,
HttpServletRequest request,
Map<String, Object> map){
//System.out.print(moviedata.Title);
map.put("moviedata", moviedata);
//map.addAttribute("movie", moviedata);
map.put("date", request.getParameter("date"));
return "showMovies";
}
public Movie formBackingObject() {
return new Movie();
}
}
我的对象
package com.outbottle.hellospring.entities;
import java.util.Date;
public class Movie {
private String Title;
private Date ReleaseDate;
/**
* @return the ReleaseDate
*/
public Date getReleaseDate() {
return ReleaseDate;
}
/**
* @param ReleaseDate the ReleaseDate to set
*/
public void setReleaseDate(Date ReleaseDate) {
this.ReleaseDate = ReleaseDate;
}
/**
* @return the Title
*/
public String getTitle() {
return Title;
}
/**
* @param Title the Title to set
*/
public void setTitle(String Title) {
this.Title = Title;
}
}
表格
<form:form method="post" action="showMovies" modelAttribute="Movie" commandName="Movie">
<table>
<tr>
<td>Title</td>
<td><form:input path="Title" /></td>
</tr>
<tr>
<td>Date</td>
<!--Notice, this is normal html tag, will not be bound to an object -->
<td><input name="date" type="text"/></td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="send"/>
</td>
</tr>
</table>
</form:form>
风景:
<body>
<h3>Here are the list</h3>
<c:choose>
<c:when test="${not empty moviedata.Title}">
<b>${moviedata.Title}</b>
</c:when>
<c:otherwise>
<b>No Movie yet.</b>
</c:otherwise>
</c:choose>
<br />
<br />
<c:choose>
<c:when test="${not empty date}">
<b>${date}</b>
</c:when>
<c:otherwise>
<b>still nothing.</b>
</c:otherwise>
</c:choose>
</body>