我正在尝试获取键和值对的列表,并尝试通过表单保存值。
这是前端代码
<form:form id="update-user-form"
action="${pageContext.request.contextPath}/add-app-settings"
commandName="appTypeSettings" class="form-horizontal">
<c:forEach var="key" items="${appTypeSettingsKey}">
<%-- <a href="#panelDecription" style="cursor: pointer;">${key.setting_key}</a> --%>
<div class="form-group">
<label class="col-md-3 control-label"></label>
<div class="col-md-9">
<form:errors path="setting_key" cssClass="error" />
<form:label path="setting_key" id="setting_key_error"
cssClass="error"></form:label>
</div>
<label class="col-md-3 control-label">${key.setting_key}</label>
<div class="col-md-9">
<form:input path="setting_value" cssClass="form-control" id=""
maxlength="50" />
</div>
</div>
</c:forEach>
<c:if test="${not empty appTypeSettingsKey}">
<div class="form-group">
<label class="col-md-3 control-label"></label>
<div class="col-md-9">
<div>
<!-- <a class="btn btn-primary m-r-5" style="float: right"
href="#modal-dialog" >Save</a> -->
<form:button>submit</form:button>
</div>
</div>
</div>
</c:if>
</form:form>
然而,当我尝试保存值时,我收到错误。在执行以下requestmapping方法的主体之前,我得到一个例外。
@RequestMapping(value = "/add-app-settings", method = RequestMethod.POST)
public ModelAndView addSettings(Model model, final HttpServletRequest request, BindResult result,@ModelAttribute("appTypeSettings") TVAppsForm settings) {
ModelAndView addapp = new ModelAndView("add-app");
//System.out.println("");
return addapp;
}
以下是例外,
2016-01-12 11:06:01 ERROR AppErrorHandler:57 - The following Exception was thrown
org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.unboundid.ldap.sdk.BindResult]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.unboundid.ldap.sdk.BindResult.<init>()
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:107)
at org.springframework.web.method.annotation.ModelAttributeMethodProcessor.createAttribute(ModelAttributeMethodProcessor.java:138)
at org.springframework.web.servlet.mvc.method.annotation.ServletModelAttributeMethodProcessor.createAttribute(ServletModelAttributeMethodProcessor.java:81)
at org.springframework.web.method.annotation.ModelAttributeMethodProcessor.resolveArgument(ModelAttributeMethodProcessor.java:104)
at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:79)
at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:157)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:124)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:781)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:721)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:217)
at org.apache.catalina.core.StandardContextValve.__invoke(StandardContextValve.java:106)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.__invoke(StandardHostValve.java:142)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NoSuchMethodException: com.unboundid.ldap.sdk.BindResult.<init>()
at java.lang.Class.getConstructor0(Class.java:2892)
at java.lang.Class.getDeclaredConstructor(Class.java:2058)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:104)
... 40 more
2016-01-12 11:06:01 INFO AppErrorHandler:63 - Exited : ModelAndView handleException(Exception ex)
我假设,一个问题是我尝试绑定一个对象,但我得到了一个对象列表。有人可以帮我找到发行吗?
答案 0 :(得分:0)
异常说NoDefaultConstructor意味着它没有不带参数的构造函数。一般来说,如果你得到这个意味着某些东西试图实例化该类以便使用它来做其他事情,但是试图实例化它的东西依赖于有一个没有参数的构造函数,所以它可以创建对象,因为它我不知道论据应该是什么。这是休眠方面的一个重大问题,但我猜这是无关紧要的。
无论如何,看看你的BindResult类实例化的内容和其他人建议的那样,检查它是否真的是正确的类开始,或者你是否错误地导入了其他东西。