简体   繁体   English

Spring MVC:Bean属性不可读或具有无效的getter方法getter的返回类型是否与setter的参数类型匹配

[英]Spring MVC: Bean property is not readable or has an invalid getter method Does the return type of the getter match the parameter type of the setter

I am new to Spring MVC and I am having a problem in my application, I have been trying to populate a dropdown box with information from my database but I keep getting an error in the JSP, I get all the information in the controller but I cannot show it in the view, I have found similar cases in the site but none has an answer that I can use. 我是Spring MVC的新手,我的应用程序有问题,我一直在尝试用数据库中的信息填充下拉框,但在JSP中我一直遇到错误,我在控制器中获取了所有信息,但我无法在视图中显示它,我在网站上发现了类似的案例,但是没有一个可以使用的答案。

I keep getting the same error no matter what I try, the exception is the following: 无论尝试如何,我都会收到相同的错误,但以下情况除外:

org.springframework.beans.NotReadablePropertyException: Invalid property 'nombreEstado' of bean class [java.util.ArrayList]: Bean property 'nombreEstado' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:725)
org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:716)
org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:149)
org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:168)
org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:188)
org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getName(AbstractDataBoundFormElementTag.java:154)
org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.writeDefaultAttributes(AbstractDataBoundFormElementTag.java:117)
org.springframework.web.servlet.tags.form.AbstractHtmlElementTag.writeDefaultAttributes(AbstractHtmlElementTag.java:422)
org.springframework.web.servlet.tags.form.SelectTag.writeTagContent(SelectTag.java:194)
org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:84)
org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:80)
org.apache.jsp.WEB_002dINF.views.home_jsp._jspService(home_jsp.java:141)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:209)
org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:267)
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1225)
org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1012)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:876)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52

Right now I have this method in my controller: 现在,我的控制器中有以下方法:

@ModelAttribute("estados")
public List<Estado> obtenerEstados(){
    logger.debug("buscando todos los estados");

    for (int i = 0; i < this.estadoBo.obtenerEstados().size(); i++) {
        System.out.println(this.estadoBo.obtenerEstados().get(i).getNombreEstado());
    }

    return this.estadoBo.obtenerEstados();
}

I used the cycle just to see if the values were coming right from the database 我用这个周期只是看这些值是否来自数据库

And the JSP 和JSP

<form:form modelAttribute="estados">
    <form:select path="nombreEstado" id="nombreEstado">
        <form:option value="">Estado: </form:option>
        <c:forEach items="${estados.getNombreEstado}" var="estado">
            <form:option value="${estado}">${estado}</form:option>
        </c:forEach>
    </form:select>

I get the error in the line of the select path = "nombreEstado" 我在选择路径的行中得到了错误=“ nombreEstado”

I don't know what I am doing wrong, any help will be welcomed 我不知道自己在做什么错,欢迎任何帮助

Thanks in Advance 提前致谢

The jsp stayed like this: jsp像这样保持:

<form:form modelAttribute="searchForm">
                <form:select path="nombreEstado" id="nombreEstado">
                    <form:option value="">Estado: </form:option>
                    <c:forEach items="${estados}" var="estado">
                        <form:option value="${estado}">${estado}</form:option>
                    </c:forEach>
                </form:select>

I removed from items the getEstado property and from the controller I did the following changes: 我从项目中删除了getEstado属性,并从控制器中进行了以下更改:

@ModelAttribute("estados")
public List<String> obtenerEstados(){
    logger.debug("buscando todos los estados");

    int cantidadEstados = this.estadoBo.obtenerEstados().size();        
    ArrayList<String> estadoLista = new ArrayList<String>();

    for (int i = 0; i < cantidadEstados; i++) {
        estadoLista.add(this.estadoBo.obtenerEstados().get(i).getNombreEstado());           
    }               
    return estadoLista;             
}

and this is where I had the problem: 这就是我遇到的问题:

@ModelAttribute("estados")
public List<String> obtenerEstados(){
    logger.debug("buscando todos los estados");

    int cantidadEstados = this.estadoBo.obtenerEstados().size();        
    ArrayList<String> estadoLista = new ArrayList<String>();

    for (int i = 0; i < cantidadEstados; i++) {
        estadoLista.add(this.estadoBo.obtenerEstados().get(i).getNombreEstado());           
    }               
    return estadoLista;             
}

I added the attribute searchForm to the model with the new bean object and now it works fine 我使用新的bean对象将属性searchForm添加到模型中,现在可以正常工作了

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Bean属性“ cmpcode”不可读或具有无效的getter方法:getter的返回类型是否与setter的参数类型匹配? - Bean property 'cmpcode' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter? Bean属性&#39;xxxx不可读或具有无效的getter方法:getter的返回类型是否与setter的参数类型匹配 - Bean property 'xxxx is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter Bean 属性 &#39;xxx&#39; 不可读或具有无效的 getter 方法:getter 的返回类型是否与 setter 的参数类型匹配? - Bean property 'xxx' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter? Bean属性不可读或具有无效的getter方法:getter的返回类型是否与setter的参数类型匹配? 春季批 - Bean property is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter? Spring Batch Bean属性“ trustStore”不可写或具有无效的setter方法。 setter的参数类型是否与getter的返回类型匹配? - Bean property 'trustStore' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter? Bean 属性 'sakilaDao' 不可写或具有无效的 setter 方法。 setter 的参数类型是否与 getter 的返回类型匹配? - Bean property 'sakilaDao' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter? Bean类的无效属性&#39;id&#39;:Bean属性&#39;id&#39;不可读或具有无效的getter方法:getter的返回类型是否匹配 - Invalid property 'id' of bean class: Bean property 'id' is not readable or has an invalid getter method: Does the return type of the getter match 在 Thymeleaf 模板中使用 @ManyToOne 值 - 属性 '' 不可读或具有无效的 getter 方法 - Using @ManyToOne value in Thymeleaf template - property '' is not readable or has an invalid getter method Does the return type of the getter Spring MVC 3.0:Bean类的无效属性Bean属性不可读或具有无效的getter方法 - Spring mvc 3.0: Invalid property of bean class Bean property is not readable or has an invalid getter method Bean属性不可读或具有无效的getter方法 - Bean property is not readable or has an invalid getter method
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM