简体   繁体   中英

Wrong form binding in Thymeleaf and Spring MVC

I am beginning with Thymeleaf. I just copied an example and adjusted it to my needs. However it does not work. I appreciate any help.

Label

@Entity 
public class Label {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "label_id")
private Long labelId;

private String label;

public Label() {
}

public Label(Long labelId, String label) {

    this.labelId = labelId;
    this.label = label;
}

public Label(String label) {

    this.labelId = null;
    this.label = label;
}


public Long getLabelId() {
    return labelId;
}

public void setLabelId(Long labelId) {
    this.labelId = labelId;
}

public String getLabel() {
    return label;
}

public void setLabel(String label) {
    this.label = label;
}

@Override
public boolean equals(Object o) {
    if (this == o) return true;
    if (!(o instanceof Label)) return false;

    Label label1 = (Label) o;

    return getLabel().equals(label1.getLabel());
}

@Override
public int hashCode() {

    return Objects.hash(getLabel());
}

@Override
public String toString() {
    return "Label{" +
            "labelId=" + labelId +
            ", label='" + label + '\'' +
            '}';
} }

Controller

@Controller
public class LabelController {


private NoteHandler handler;

@Autowired
public LabelController(NoteHandler handler) {
    this.handler = handler;
}

@RequestMapping(value = "/savelabel", method = RequestMethod.GET)
public String showSaveLabelForm(Model model) {
    model.addAttribute("labelentity", new Label());
    return "labelform";
}

@RequestMapping(value = "/savelabel", method = RequestMethod.POST)
public String submitLabel(@ModelAttribute Label labelentity) {
    return "result";
}    }

labelform.html

> <!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org"> <head>
>     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
>     <title>Save a New Label</title> </head> <body> <h1>Form</h1> 
><form action="#" th:action="@{/savelabel}" th:object="${labelentity}" method="post">
>     <p>Id: <input type="text" th:field="*{labelId}" /></p>
>     <p>Label: <input type="text" th:field="*{label}" /></p>
>     <p><input type="submit" value="Submit" /> <input type="reset" 
>value="Reset" /></p> </form> </body> </html>

result.html

<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>Saved Label</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<h1>Result</h1>
<p th:text="'id: ' + ${labelentity.labelId}" />
<p th:text="'label: ' + ${labelentity.label}" />
<a href="/savelabel">Save another label</a>
</body>
</html>

The problem: I go to labelform page, fill 1 into ID field, abc to label , I submit, it gives me error

There was an unexpected error (type=Bad Request, status=400). Failed to convert value of type 'java.lang.String' to required type 'krystof.business.Label'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [java.lang.Long] for value 'abc'; nested exception is java.lang.NumberFormatException: For input string: "abc"

I guess that label is incorrectly being bound to labelId . Why? Thanks for help.

The console output:

...

: Found resource handler mapping: URL pattern="/webjars/ ", locations=[class path resource [META-INF/resources/webjars/]], resolvers=[org.springframework.web.servlet.resource.PathResourceResolver@349312d5] 2017-12-29 14:58:30.488 DEBUG 5492 --- [ main] oswsresource.ResourceUrlProvider : Found resource handler mapping: URL pattern="/ ", locations=[ServletContext resource [/], class path resource [META-INF/resources/], class path resource [resources/], class path resource [static/], class path resource [public/]], resolvers=[org.springframework.web.servlet.resource.PathResourceResolver@5885e231] 2017-12-29 14:58:30.573 INFO 5492 --- [ main] sbcetTomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http) 2017-12-29 14:58:30.574 DEBUG 5492 --- [ main] oswcsStandardServletEnvironment : Adding PropertySource 'server.ports' with highest search precedence 2017-12-29 14:58:30.579 INFO 5492 --- [ main] krystof.App
: Started App in 8.625 seconds (JVM running for 9.133) 2017-12-29 14:58:39.455 DEBUG 5492 --- [nio-8080-exec-2] osweb.servlet.DispatcherServlet : Initializing servlet 'dispatcherServlet' 2017-12-29 14:58:39.460 INFO 5492 --- [nio-8080-exec-2] oaccC[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet' 2017-12-29 14:58:39.460 INFO 5492 --- [nio-8080-exec-2] osweb.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started 2017-12-29 14:58:39.460 DEBUG 5492 --- [nio-8080-exec-2] osweb.servlet.DispatcherServlet
: Using MultipartResolver [org.springframework.web.multipart.support.StandardServletMultipartResolver@6ad6ae45] 2017-12-29 14:58:39.464 DEBUG 5492 --- [nio-8080-exec-2] osweb.servlet.DispatcherServlet : Unable to locate LocaleResolver with name 'localeResolver': using default [org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver@19ac22ef] 2017-12-29 14:58:39.477 DEBUG 5492 --- [nio-8080-exec-2] osweb.servlet.DispatcherServlet : Unable to locate ThemeResolver with name 'themeResolver': using default [org.springframework.web.servlet.theme.FixedThemeResolver@2ba12e19] 2017-12-29 14:58:39.484 DEBUG 5492 --- [nio-8080-exec-2] osweb.servlet.DispatcherServlet : Unable to locate RequestToViewNameTranslator with name 'viewNameTranslator': using default [org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator@4aca5c03] 2017-12-29 14:58:39.493 DEBUG 5492 --- [nio-8080-exec-2] osweb.servlet.DispatcherServlet : Unable to locate FlashMapManager with name 'flashMapManager': using default [org.springframework.web.servlet.support.SessionFlashMapManager@6434e440] 2017-12-29 14:58:39.494 DEBUG 5492 --- [nio-8080-exec-2] osweb.servlet.DispatcherServlet : Published WebApplicationContext of servlet 'dispatcherServlet' as ServletContext attribute with name [org.springframework.web.servlet.FrameworkServlet.CONTEXT.dispatcherServlet] 2017-12-29 14:58:39.494 INFO 5492 --- [nio-8080-exec-2] osweb.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 34 ms 2017-12-29 14:58:39.494 DEBUG 5492 --- [nio-8080-exec-2] osweb.servlet.DispatcherServlet : Servlet 'dispatcherServlet' configured successfully 2017-12-29 14:58:39.512 DEBUG 5492 --- [nio-8080-exec-2] osweb.servlet.DispatcherServlet : DispatcherServlet with name 'dispatcherServlet' processing POST request for [/savelabel] 2017-12-29 14:58:39.517 DEBUG 5492 --- [nio-8080-exec-2] swsmmaRequestMappingHandlerMapping : Looking up handler method for path /savelabel 2017-12-29 14:58: 39.520 DEBUG 5492 --- [nio-8080-exec-2] swsmmaRequestMappingHandlerMapping : Returning handler method [public java.lang.String krystof.Controller.LabelController.submitLabel(krystof.business.Label)] 2017-12-29 14:58:39.542 DEBUG 5492 --- [nio-8080-exec-2] osweb.cors.DefaultCorsProcessor : Skip CORS processing: request is from same origin 2017-12-29 14:58:39.578 DEBUG 5492 --- [nio-8080-exec-2] .wsmmaServletInvocableHandlerMethod : Failed to resolve argument 0 of type 'krystof.business.Label'

org.springframework.beans.TypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'krystof.business.Label'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [java.lang.Long] for value 'abc'; nested exception is java.lang.NumberFormatException: For input string: "abc" at org.springframework.beans.TypeConverterSupport.doConvert(TypeConverterSupport.java:71) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.beans.TypeConverterSupport.convertIfNecessary(TypeConverterSupport.java:47) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.validation.DataBinder.convertIfNecessary(DataBinder.java:713) ~[spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.ServletModelAttributeMethodProcessor.createAttributeFromRequestValue(ServletModelAttributeMethodProcessor.java:137) ~[spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.ServletModelAttributeMethodProcessor.createAttribute(ServletModelAttributeMethodProcessor.java:75) ~[spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.web.method.annotation.ModelAttributeMethodP rocessor.resolveArgument(ModelAttributeMethodProcessor.java:106) ~[spring-web-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:121) ~[spring-web-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:158) [spring-web-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:128) [spring-web-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97) [spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827) [spring-webmvc-4.3.13.REL EASE.jar:4.3.13.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) [spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) [spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967) [spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901) [spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) [spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872) [spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE] at javax.servlet.http.HttpServlet.service(HttpServle t.java:661) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) [spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE] at javax.servlet.http.HttpServlet.service(HttpServlet.java:742) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) [tomcat-embed-websocket-8.5.23.jar:8.5.23] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.springframework.web.filter.RequestContextFilter .doFilterInternal(RequestContextFilter.java:99) [spring-web-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:108) [spring-web-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.catalina.core.ApplicationFilterChain.doF ilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81) [spring-web-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197) [spring-web-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalD oFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.catalina.connector.CoyoteAdapter.service (CoyoteAdapter.java:342) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459) [tomcat-embed-core-8.5.23.jar:8.5.23] at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-8.5.23.jar:8.5.23] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_131] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_131] at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.5.23.jar:8.5.23] at j ava.lang.Thread.run(Thread.java:748) [na:1.8.0_131] Caused by: org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [java.lang.Long] for value 'abc'; nested exception is java.lang.NumberFormatException: For input string: "abc" at org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:43) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:203) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:187) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.data.repository.support.DomainClassConverter$ToEntityConverter.convert(DomainClassConverter.java:157) ~[spring-data-commons-1.13.9.RELEASE.jar:na] at org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:37) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:203) ~[spring-core-4.3.1 3.RELEASE.jar:4.3.13.RELEASE] at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:173) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:108) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.beans.TypeConverterSupport.doConvert(TypeConverterSupport.java:64) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE] ... 56 common frames omitted Caused by: java.lang.NumberFormatException: For input string: "abc" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) ~[na:1.8.0_131] at java.lang.Long.parseLong(Long.java:589) ~[na:1.8.0_131] at java.lang.Long.valueOf(Long.java:803) ~[na:1.8.0_131] at org.springframework.util.NumberUtils.parseNumber(NumberUtils.java:211) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.core.convert.support.StringToNumberConverterFactory$StringToNumber.con vert(StringToNumberConverterFactory.java:62) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.core.convert.support.StringToNumberConverterFactory$StringToNumber.convert(StringToNumberConverterFactory.java:49) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.core.convert.support.GenericConversionService$ConverterFactoryAdapter.convert(GenericConversionService.java:436) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE] at org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:37) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE] ... 64 common frames omitted

2017-12-29 14:58:39.579 DEBUG 5492 --- [nio-8080-exec-2] .mmaExceptionHandlerExceptionResolver : Resolving exception from handler [public java.lang.String krystof.Controller.LabelController.submitLabel(krystof.business.Label)]: org.springframework.beans.TypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'krystof.business.Label'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [java.lang.Long] for value 'abc'; nested exception is java.lang.NumberFormatException: For input string: "abc" 2017-12-29 14:58:39.581 DEBUG 5492 --- [nio-8080-exec-2] .wsmaResponseStatusExceptionResolver : Resolving exception from handler [public java.lang.String krystof.Controller.LabelController.submitLabel(krystof.business.Label)]: org.springframework.beans.TypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'krystof.business.Label'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [java.lang.Long] for value 'abc'; nested exception is java.lang.NumberFormatException: For input string: "abc" 2017-12-29 14:58:39.592 DEBUG 5492 --- [nio-8080-exec-2] .wsmsDefaultHandlerExceptionResolver : Resolving exception from handler [public java.lang.String krystof.Controller.LabelController.submitLabel(krystof.business.Label)]: org.springframework.beans.TypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'krystof.business.Label'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [java.lang.Long] for value 'abc'; nested exception is java.lang.NumberFormatException: For input string: "abc" 2017-12-29 14:58:39.593 WARN 5492 --- [nio-8080-exec-2] .wsmsDefaultHandlerExceptionResolver : Failed to bind request element: org.springframework.beans.TypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'krystof.business.Label'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [java.lang.Long] for value 'abc'; nested exception is java.lang.NumberFormatException: For input string: "abc" 2017-12-29 14:58:39.593 DEBUG 5492 --- [nio-8080-exec-2] osweb.servlet.DispatcherServlet : Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling 2017-12-29 14:58:39.594 DEBUG 5492 --- [nio-8080-exec-2] osweb.servlet.DispatcherServlet : Successfully completed request 2017-12-29 14:58:39.606 DEBUG 5492 --- [nio-8080-exec-2] osweb.servlet.DispatcherServlet : DispatcherServlet with name 'dispatcherServlet' processing POST request for [/error] 2017-12-29 14:58:39.607 DEBUG 5492 --- [nio-8080-exec-2] swsmmaRequestMappingHandlerMapping : Looking up handler method for path /error 2017-12-29 14:58:39.610 DEBUG 5492 --- [nio-8080-exec-2] swsmmaRequestMappingHandlerMapping : Returning handler method [public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.Htt pServletRequest,javax.servlet.http.HttpServletResponse)] 2017-12-29 14:58:39.611 DEBUG 5492 --- [nio-8080-exec-2] osweb.cors.DefaultCorsProcessor : Skip CORS processing: request is from same origin 2017-12-29 14:58:39.638 DEBUG 5492 --- [nio-8080-exec-2] oswsvContentNegotiatingViewResolver : Requested media types are [text/html, text/html;q=0.8] based on Accept header types and producible media types [text/html]) 2017-12-29 14:58:39.654 DEBUG 5492 --- [nio-8080-exec-2] oswsvContentNegotiatingViewResolver : Returning [org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration$SpelView@2b999ee8] based on requested media type 'text/html' 2017-12-29 14:58:39.654 DEBUG 5492 --- [nio-8080-exec-2] osweb.servlet.DispatcherServlet
: Rendering view [org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration$SpelView@2b999ee8] in DispatcherServlet with name 'dispatcherServlet' 2017-12-29 14:58:39.694 DEBUG 5492 --- [nio-8080-exec-2] osweb.servlet.DispatcherServlet : Successfully completed request

It is a little unclear to me exactly why you see the error that you do since when I've tried your code I get

org.springframework.expression.spel.SpelEvaluationException: EL1007E: Property or field 'labelId' cannot be found on null

I suspect that the difference is down to some code you might have redacted in your listings.

However the issue is related to the fact that in your post request controller method you have the following @ModelAttribute Label labelentity , this means spring will have added an attribute with the name label to the model map, however your template refers to labelentity so you need to change this to be

@ModelAttribute(name = "labelentity")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM