Java Bean 属性不可读或具有无效的 getter 方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27784836/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Bean property is not readable or has an invalid getter method
提问by Padmelina
So, I have a task to write a simple web-application for registry routes. Using Spring MVC. So I have class "Route", where I want to keep start point, finish point and list of intermediate points. But I don't understand, how to put values to list from jsp (e.g. using jstl). So I decide to parse a string.
所以,我有一个任务来为注册表路由编写一个简单的 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);
}
}
}
and follow JSP:
并遵循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>
If it's nessesary I can post Controller code. And I have an error:
如果是必要的,我可以发布控制器代码。我有一个错误:
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?
Can anyone, please, to explain what I do principaly wrong?
任何人都可以,请解释我做错了什么?
采纳答案by Reimeus
Add the form's getter method to the bean as indicated by the error message
将表单的 getter 方法添加到 bean 中,如错误消息所示
public String getForm() {
return form;
}
setForm
should have a corresponding method
setForm
应该有对应的方法
public void setForm(String form) {
this.form = form;
}
回答by Rutul Patel
add following
添加以下
public String getForm(){
return form;
}
public void setForm(String form){
this.form = form;
this.toList();
}