首页 文章

bean类的属性'fields[0]'无效

提问于
浏览
2

我正在和 Spring 天一起工作,我的实体是

myEntity.java

@Entity
public class Ecran {
...
@OneToMany(fetch=FetchType.EAGER, cascade = { CascadeType.ALL } , mappedBy="ecran")
public Set<Fields> fields = new HashSet<>();

...
}

而我正在尝试更改这样的字段的属性

myPage.html

<div th:each="field, itemStat : *{fields}" >

                <div class="row table-responsive-xl mt-3" >
                    <label class="font-weight-medium h5 black-text"  th:text="${field.nom}" for="${field.idJira}"></label>
                    <input type="text" id="${field.id}" class="form-control mb-6" th:field="*{fields[__${itemStat.index}__].value}">
                </div>

            </div>

但它告诉我这个错误

2018-08-20 09:09:36.000 ERROR 13144 --- [nio-8092-exec-1] oaccC [ . [ . [/] . [dispatcherServlet]:Servlet中的Servlet.service()[dispatcherServlet] with path []抛出异常[请求处理失败;嵌套异常是org.springframework.beans.InvalidPropertyException:bean类的无效属性'fields [0]'[com.kepler.skeleton.domain.model.Ecran]:非法尝试获取属性'fields'引发异常;嵌套异常是org.springframework.beans.InvalidPropertyException:bean类的无效属性'fields [0]'[com.kepler.skeleton.domain.model.Ecran]:无法从大小为0的Set中获取索引为0的元素,使用属性路径'fields [0]']带有根本原因org.springframework.beans.InvalidPropertyException:bean类的无效属性'fields [0]'[com.kepler.skeleton.domain.model.Ecran]:无法获取带索引的元素来自0的Set 0,使用org.springframework.beans.AbstractNestablePropertyAccessor.getPropertyValue(AbstractNestablePropertyAccessor.java:664)〜[spring-beans-5.0.8.RELEASE.jar:5.0]中的属性路径'fields [0]'访问 . 8.RELEASE]在org.springframework.beans.AbstractNestablePropertyAccessor的org.springframework.beans.AbstractNestablePropertyAccessor.getNestedPropertyAccessor(AbstractNestablePropertyAccessor.java:839)〜[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE] . getPropertyAccessorForPropertyPath(AbstractNestablePropertyAccessor.java:816)~ [spring-beans -5.0.8.RELEASE.jar:5.0.8.RELEASE]在org.springframework.beans.AbstractNestablePropertyAccessor.setPropertyValue(AbstractNestablePropertyAccessor.java:256)〜[spring-beans-5.0.8.RELEASE.jar:5.0.8 . 发布org.springframework.valid.EringProperty.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:97)〜[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE] org.springframework.validation.DataBinder.applyPropertyValues(在org.springframework.validation.DataBinder.doBind(DataBinder.java:735)〜[spring-context-5.0]的DataBinder.java:839)~ [spring-context-5.0.8.RELEASE.jar:5.0.8.RELEASE] .8.RELEASE.jar:5.0.8.RELEASE]在org.springframework.web.bind.WebDataBinder.doBind(WebDataBinder.java:197)〜[spring-web-5.0.8.RELEASE.jar:5.0.8 . 发布在org.springframework.web.servlet上的org.springframework.web.bind.ServletRequestDataBinder.bind(ServletRequestDataBinder.java:107)〜[spring-web-5.0.8.RELEASE.jar:5.0.8.RELEASE] . mvc.method.annotation.ServletModelAttributeMethodProcessor.bindRequestParameters(S ervletModelAttributeMethodProcessor.java:157)~ [spring-webmvc-5.0.8.RELEASE.jar:5.0.8.RELEASE] org.springframework.web.method.annotation.ModelAttributeMethodProcessor.resolveArgument(ModelAttributeMethodProcessor.java:152)~ [spring -web-5.0.8.RELEASE.jar:5.0.8.RELEASE] at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:124)~ [spring-web-5.0.8.RELEASE . jar:5.0.8.RELEASE] at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:161)~ [spring-web-5.0.8.RELEASE.jar:5.0.8.RELEASE] at at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:131)〜[spring-web-5.0.8.RELEASE.jar:5.0.8.RELEASE] org.springframework.web.servlet.mvc org.springfr中的.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)〜[spring-webmvc-5.0.8.RELEASE.jar:5.0.8.RELEASE] org.springframework.web.servlet上的amework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:877)~ [spring-webmvc-5.0.8.RELEASE.jar:5.0.8.RELEASE] org.springframework.web.servlet.mvc.method上的.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:783)~ [spring-webmvc-5.0.8.RELEASE.jar:5.0.8.RELEASE] . 在org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991)的AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)〜[spring-webmvc-5.0.8.RELEASE.jar:5.0.8.RELEASE]〜 [spring-webmvc-5.0.8.RELEASE.jar:5.0.8.RELEASE]在org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925)~ [spring-webmvc-5.0.8.RELEASE . jar:5.0.8.RELEASE] atorg.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:974)〜[spring-webmvc-5.0.8.RELEASE.jar:5.0.8.RELEASE] org.springframework.web.servlet.FrameworkServlet.doPost (FrameworkServlet.java:877)〜[spring-webmvc-5.0.8.RELEASE.jar:5.0.8.RELEASE]在javax.servlet.http.HttpServlet.service(HttpServlet.java:661)〜[tomcat-embed- core-8.5.32.jar:8.5.32] at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:851)〜[spring-webmvc-5.0.8.RELEASE.jar:5.0.8.RELEASE ]在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain)的javax.servlet.http.HttpServlet.service(HttpServlet.java:742)〜[tomcat-embed-core-8.5.32.jar:8.5.32] .java:231)〜[tomcat-embed-core-8.5.32.jar:8.5.32]在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)〜[tomcat-embed-core- 8.5.32.jar:8.5.32] at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)〜[tomcat-embed-websocket-8.5.32.jar:8 .5.32] org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)〜[tomcat-embed-core-8.5.32.jar:8.5.32] at org.apache.catalina.core.ApplicationFilterChain ordo.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:320)〜[[ . ] spring-security-web-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:127)~ [spring-security-web -5.0.7.RELEASE.jar:5.0.7.RELEASE]在org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91)〜[spring-security-web-5.0.7 . RELEASE.jar:5.0.7.RELEASE]在org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:334)〜[spring-security-web-5.0.7.RELEASE.jar:5.0.7 .RELEASE]在org.springframework.security.web.acce在org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy)的ss.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:119)〜[spring-security-web-5.0.7.RELEASE.jar:5.0.7.RELEASE] .java:334)〜[spring-security-web-5.0.7.RELEASE.jar:5.0.7.RELEASE] org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:137)~ [ spring-security-web-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:334)〜[spring-security-web-5.0 .7.RELEASE.jar:5.0.7.RELEASE]在org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111)〜[spring-security-web-5.0.7.RELEASE.jar: 5.0.7.RELEASE]在org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:334)〜[spring-security-web-5.0.7.RELEASE.jar:5.0.7.RELEASE] at at org.springframework.securi org.springframework.security.web.FilterChainProxy上的ty.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:150)〜[spring-security-web-5.0.7.RELEASE.jar:5.0.7.RELEASE] $ VirtualFilterChain.doFilter(FilterChainProxy.java:334)〜[spring-security-web-5.0.7.RELEASE.jar:5.0.7.RELEASE] org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter . java:170)〜[spring-security-web-5.0.7.RELEASE.jar:5.0.7.RELEASE]在org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:334)〜[spring -security-web-5.0.7.RELEASE.jar:5.0.7.RELEASE]在org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63)〜[spring-security-web-5.0 . 7.RELEASE.jar:5.0.7.RELEASE]在org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:334)〜[spring-security-web-5.0 . 7.RELEASE.jar:5.0.7.RELEASE]在org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:200)〜[spring-security-web-5.0.7.RELEASE.jar:5.0 .7.RELEASE] org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:334)〜[spring-security-web-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org .springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:116)org.springframework.security.web.FilterChainProxy $ [VirtualFilterChain.doFilter]([...] - [spring-security-web] -5.0.7.RELEASE.jar:5.0.7.RELEASE]在org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:66)〜[spring-security-web-5.0.7.RELEASE . jar:5.0.7.RELEASE] org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)〜[spring-web-5.0.8.RELEASE.jar:5.0.8.RELEASE] at org . orframe.springframework.security.web.context上的springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:334)~ [spring-security-web-5.0.7.RELEASE.jar:5.0.7.RELEASE] .SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105)〜[spring-security-web-5.0.7.RELEASE.jar:5.0.7.RELEASE]在org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy . java:334)〜[spring-security-web-5 . 0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56)〜[spring-security-web-5.0.7.RELEASE .jar:5.0.7.RELEASE] org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)〜[spring-web-5.0.8.RELEASE.jar:5.0.8.RELEASE] at org org.springframework.security.web上的.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:334)~ [spring-security-web-5.0.7.RELEASE.jar:5.0.7.RELEASE] . 在org.springframework.security.web.FilterChainProxy.doFilter的FilterChainProxy.doFilterInternal(FilterChainProxy.java:215)〜[spring-security-web-5.0.7.RELEASE.jar:5.0.7.RELEASE](FilterChainProxy.java:178 )〜[spring-security-web-5.0.7.RELEASE.jar:5.0.7.RELEASE]在org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:357)〜[spring-web-5.0 . 8.RELEASE.jar:5.0.8.RELEASE]在org.springfr orme.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain)中的amework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:270)~ [spring-web-5.0.8.RELEASE.jar:5.0.8.RELEASE] .java:193)〜[tomcat-embed-core-8.5.32.jar:8.5.32]在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)〜[tomcat-embed-core- 8.5.32.jar:8.5.32]在org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)〜[spring-web-5.0.8.RELEASE.jar:5.0.8.RELEASE] at at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)〜[spring-web-5.0.8.RELEASE.jar:5.0.8.RELEASE] org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (ApplicationFilterChain.java:193)〜[tomcat-embed-core-8.5.32.jar:8.5.32]在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)〜[tomcat-embed- core-8.5.32.jar:8.5.32] at org.springframework.web.filter.HttpP在org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)的utFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:109)〜[spring-web-5.0.8.RELEASE.jar:5.0.8.RELEASE]〜 [spring-web-5.0.8.RELEASE.jar:5.0.8.RELEASE]在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)〜[tomcat-embed-core-8.5.32 . jar:8.5.32] org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)〜[tomcat-embed-core-8.5.32.jar:8.5.32] org.springframework.web . org.springframework.web.filter.OncePerRequestFilter.doFilter上的filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93)〜[spring-web-5.0.8.RELEASE.jar:5.0.8.RELEASE](OncePerRequestFilter.java:107 )〜[spring-web-5.0.8.RELEASE.jar:5.0.8.RELEASE]在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)〜[tomcat-embed-core-8.5 . 32.jar:8.5.32]在org.apache.catalina.core.Applicat ionFilterChain.doFilter(ApplicationFilterChain.java:166)~ [tomcat-embed-core-8.5.32.jar:8.5.32] at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)〜[spring -web-5.0.8.RELEASE.jar:5.0.8.RELEASE]在org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)〜[spring-web-5.0.8.RELEASE.jar: 5.0.8.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)〜[tomcat-embed-core-8.5.32.jar:8.5.32]在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)〜[tomcat-embed-core-8.5.32.jar :8.5.32] org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)〜[tomcat-embed-core-8.5.32.jar:8.5.32] org.apache.catalina.core .standardContextValve.invoke(StandardContextValve.java:96)[tomcat-embed-core-8.5.32.jar:8.5.32] at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493)[tomcat- embed-core-8.5.32.jar:8.5.32] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)[tomcat-embed-core-8.5.32.jar:8.5.32] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)[tomcat-embed-core-8.5.32.jar:8.5.32] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve) .java:87)[tomcat-embed-core-8.5.32.jar:8.5.32] org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)[tomcat-embed -core-8.5.32.jar:8.5.32]在org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:800)[tomcat-embed-core-8.5.32.jar:8.5.32] at at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)[tomcat-embed-core-8.5.32.jar:8.5.32] at org.apache.coyote.AbstractProtocol $ ConnectionHandler.process(AbstractProtocol.java: 800)[tomcat-embed-core-8.5.32.jar:8.5.32] at org.apache.tomcat.util.net.NioEndpoint $ SocketProcessor.doRun(NioEndpoint.java:1471)[tomcat-embed-core-8.5 .32.jar:8.5.32]在java的org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)[tomcat-embed-core-8.5.32.jar:8.5.32] . util.concurrent.ThreadPoolExecutor.runWorker(未知来源)[na:1.8.0_111] at java.util.concurrent.ThreadPoolExecutor $ Worker.run(未知来源)[na:1.8.0_111] at org.apache.tomcat.util . threads.TaskThread $ WrappingRunnable.run(TaskThread.java:61)[tomcat-embed-core-8.5.32.jar:8.5.32] at java.lang.Thread.run(Unknown Source)[na:1.8.0_111]

1 回答

  • 1

    通过查看您的例外情况:

    ...无法从大小为0的Set中获取索引为0的元素,使用具有根本原因的属性路径“fields [0]”进行访问 .

    你可以看到问题 . Set没有元素0.那是因为HashSet没有顺序 . 您需要索引集合 - 数组或列表 . 将Set传递给前端并以有序方式修改它时,这实际上是很常见的问题 . 一个简单的解决方案是使用List而不是Set .

    如果你不想重复,那么只需在你的HashSet周围包装一个ArrayList - 将它传递给前端,然后将其传递回hashset以摆脱重复的元素 .

相关问题