因此,我有一项任务是为注册表路由编写一个简单的Web应用程序。使用Spring MVC。所以我有课程"路线",我想保留起点,终点和中间点列表。但我不明白,如何将值放到jsp列表中(例如使用jstl)。所以我决定解析一个字符串。
public class Route {
private String start;
private String finish;
private String form;
private List<String> list;
public Route() {
}
public Route(String start, String finish, String route) {
this.start = start;
this.finish = finish;
this.form = route;
this.toList();
}
public Route(String start, String finish) {
this.start = start;
this.finish = finish;
this.list = new ArrayList<>();
}
public void addTown(String town){
list.add(town);
}
public String getStart() {
return start;
}
public void setStart(String start) {
this.start = start;
}
public String getFinish() {
return finish;
}
public void setFinish(String finish) {
this.finish = finish;
}
public List<String> getRoute() {
return list;
}
public void setFormRoute(String route) {
this.form = route;
this.toList();
}
private void toList()
{
String[] temp = form.split(",");
for(String temp1 : temp) {
list.add(temp1);
}
}
}
并遵循JSP:
<h2><a href="find.htm">Найти существующий маршрут</a><br/><br/>
Добавить маршрут</h2>
<h3>
<spring:nestedPath path="route">
<form modelAttribute="routeAttribute" method="POST" action="${add}">
Пункт отправления:
<spring:bind path="start">
<input type="text" name="${status.expression}" value="${status.value}">
</spring:bind><br/><br/>
Пункт прибытия:
<spring:bind path="finish">
<input type="text" name="${status.expression}" value="${status.value}">
</spring:bind><br/><br/>
Промежуточные пункты (через запятую):
<spring:bind path="form">
<input type="text" name="${status.expression}" value="${status.value}">
</spring:bind><br/><br/>
<input type="submit" value="Сохранить">
</form>
</spring:nestedPath>
如果它是必要的,我可以发布控制器代码。 我有一个错误:
Bean property 'form' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
请允许任何人解释我做错的原因吗?
答案 0 :(得分:5)
将表单的getter方法添加到bean中,如错误消息
所示public String getForm() {
return form;
}
setForm
应该有相应的方法
public void setForm(String form) {
this.form = form;
}
答案 1 :(得分:2)
添加以下
public String getForm(){
return form;
}
public void setForm(String form){
this.form = form;
this.toList();
}