大家好,感谢您帮助世界各地的许多人。
过去两天我尝试的人只是简单地在我的控制器中的请求方法之间传递属性,尝试了很多不同的方式,但没有任何反应。我有 bean CreationDate,我需要填写该 bean 中的表单属性,然后在我的第二页上简单地呈现它们。我在浏览器的 url 栏中看到它正在传递(因为我使用 GET 方法进行传递),但它没有出现在第二页上,只是空白列表。
我的控制器类:
@Controller
public class HomeController{
private static final long serialVersionUID = 4825408935018763217L;
@SuppressWarnings("unused")
private static final Logger logger = LoggerFactory.getLogger(HomeController.class);
@Autowired
private ControllerSupportClass controllerSupportClass;
public void setControllerSupportClass(
ControllerSupportClass controllerSupportClass) {
this.controllerSupportClass = controllerSupportClass;
}
@RequestMapping(value ="/index", method=RequestMethod.GET)
public String index(Model model) {
CreationDate creationDate = new CreationDate();
model.addAttribute("creationD", creationDate);
return "index";
}
@RequestMapping(value="/add", method=RequestMethod.GET)
public String addingData(@ModelAttribute("creationD") CreationDate creationDate, BindingResult result, Model model) {
model.addAttribute("creationD", creationDate);
return "add";
}
}
我的豆子:
public class CreationDate implements Serializable {
private static final long serialVersionUID = 1648102358397071136L;
private int dateId;
@Id
@GeneratedValue(strategy=IDENTITY)
@Column(name="DATE_ID")
public int getDateId() {
return dateId;
}
public void setDateId(int dateId) {
this.dateId = dateId;
}
private Date particularDate;
@Column(name="PARTICULAR_DATE")
public Date getParticularDate() {
return particularDate;
}
public void setParticularDate(Date particularDate) {
this.particularDate = particularDate;
}
private int version;
@Version
@Column(name="VERSION")
public int getVersion() {
return version;
}
public void setVersion(int version) {
this.version = version;
}
private Date childGoSchoolDate;
@Temporal(TemporalType.DATE)
@Column(name="CHILD_GO_SCHOOL_DATE")
public Date getChildGoSchoolDate() {
return childGoSchoolDate;
}
public void setChildGoSchoolDate(Date childGoSchoolDate) {
this.childGoSchoolDate = childGoSchoolDate;
}
private Date childAdmissionDate;
@Temporal(TemporalType.DATE)
@Column(name="CHILD_ADMISSION_DATE")
public Date getChildAdmissionDate() {
return childAdmissionDate;
}
public void setChildAdmissionDate(Date childAdmissionDate) {
this.childAdmissionDate = childAdmissionDate;
}
}
我的表单页面:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="utf-8"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Страница выборки</title>
</head>
<body>
<h3>Вставка данных:</h3>
<form:form modelAttribute="creationD" method="GET" action="add">
<form:label path="particularDate">Particular Date</form:label>
<form:input path="particularDate" /> <br>
<form:label path="childGoSchoolDate">Child go to School</form:label>
<form:input path="childGoSchoolDate"/> <br>
<form:label path="childAdmissionDate">Child admission Date</form:label>
<form:input path="childAdmissionDate"/> <br>
<input type="submit" value="Save"/>
</form:form>
</body>
</html>
我需要从表单中租用数据的第二页:
<?xml version="1.0" encoding="UTF-8" ?>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Insert title here</title>
</head>
<body>
<h1>Result:</h1>
Attribute 1:<c:out value="${creationD.particularDate}"/>
Attribute 2:<c:out value="${creationD.childGoSchoolDate}"/>
Attribute 3:<c:out value="${creationD.childAdmissionDate}"/>
</body>
</html>