"Spring annotations Error" using controller as background to the foreground Ajax interaction data error

Source: Internet
Author: User

Controller as the background and the foreground of the Ajax interaction, the back-end method processing completed return a Boolean value, want to pass to the foreground to determine whether the execution succeeds, but, the problem comes:

1 Critical: Servlet.service () for Servlet rest threw exception2 java.lang.IllegalArgumentException:Unknown return value type [Java.lang.Boolean]3 At org.springframework.util.Assert.notNull (assert.java:112)4 At Org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue ( HANDLERMETHODRETURNVALUEHANDLERCOMPOSITE.JAVA:70)5 At Org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle ( servletinvocablehandlermethod.java:126)6 At Org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod ( requestmappinghandleradapter.java:777)7 At org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal ( requestmappinghandleradapter.java:706)8 At Org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle ( abstracthandlermethodadapter.java:85)9 At Org.springframework.web.servlet.DispatcherServlet.doDispatch (dispatcherservlet.java:943)Ten At Org.springframework.web.servlet.DispatcherServlet.doService (dispatcherservlet.java:877) One At org.springframework.web.servlet.FrameworkServlet.processRequest (frameworkservlet.java:966) A At org.springframework.web.servlet.FrameworkServlet.doPost (frameworkservlet.java:868) - At Javax.servlet.http.HttpServlet.service (httpservlet.java:643) - At Org.springframework.web.servlet.FrameworkServlet.service (frameworkservlet.java:842) the At Javax.servlet.http.HttpServlet.service (httpservlet.java:723) - At Org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (applicationfilterchain.java:290) - At Org.apache.catalina.core.ApplicationFilterChain.doFilter (applicationfilterchain.java:206) - At Com.agen.util.LoginFilter.doFilter (loginfilter.java:58) + At Org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (applicationfilterchain.java:235) - At Org.apache.catalina.core.ApplicationFilterChain.doFilter (applicationfilterchain.java:206) + At org.springframework.orm.hibernate4.support.OpenSessionInViewFilter.doFilterInternal ( opensessioninviewfilter.java:150) A At Org.springframework.web.filter.OncePerRequestFilter.doFilter (onceperrequestfilter.java:107) at At Org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (applicationfilterchain.java:235) - At Org.apache.catalina.core.ApplicationFilterChain.doFilter (applicationfilterchain.java:206) - At org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal (characterencodingfilter.java:88)  - At Org.springframework.web.filter.OncePerRequestFilter.doFilter (onceperrequestfilter.java:107) - At Org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (applicationfilterchain.java:235) - At Org.apache.catalina.core.ApplicationFilterChain.doFilter (applicationfilterchain.java:206) in At Org.apache.catalina.core.StandardWrapperValve.invoke (standardwrappervalve.java:233) - At Org.apache.catalina.core.StandardContextValve.invoke (standardcontextvalve.java:191) to At Org.apache.catalina.core.StandardHostValve.invoke (standardhostvalve.java:127) + At Org.apache.catalina.valves.ErrorReportValve.invoke (errorreportvalve.java:103) - At Org.apache.catalina.core.StandardEngineValve.invoke (standardenginevalve.java:109) the At Org.apache.catalina.connector.CoyoteAdapter.service (coyoteadapter.java:293) * At org.apache.coyote.http11.Http11AprProcessor.process (http11aprprocessor.java:879) $ At org.apache.coyote.http11.http11aprprotocol$http11connectionhandler.process (http11aprprotocol.java:617) Panax Notoginseng At Org.apache.tomcat.util.net.aprendpoint$worker.run (aprendpoint.java:1778) -At Java.lang.Thread.run (Unknown Source)
View Code

The controller code for the moment is this:

1@RequestMapping ("/productadd")2     3      Public BooleanProductadd (product product) {4 Product.setproductid (Uuid.randomuuid (). toString ());5Criteria = Getcurrentsession (). Createcriteria (Product.class);6Criteria.setprojection (Projections.max ("Productorder"));7Integer ProductOrder2 =Productservice.uniqueresultint (criteria);8Integer procuctorder=1;9         if(ProductOrder2 = =NULL){Ten Product.setproductorder (procuctorder); One}Else{ Aproductorder2++; - Product.setproductorder (productOrder2); -         } the Productservice.save (product); -         return true; -}
View Code

Problem:

Now the controller can only recognize the return of true as a string, that is, the URL to find the corresponding page, but where there are URLs like this.

Analyze the problem:

And we want this to be true as the return value to the foreground of the Ajax to judge, if true to insert a successful prompt and so on, so we do not want this true as a URL to return, but as the JSON format of the data back to the foreground

Workaround :

We need to add a spring annotation to this method and let the method return a JSON data to the foreground this annotation is: @ResponseBody

1@RequestMapping ("/productadd")2 @ResponseBody3      Public BooleanProductadd (product product) {4 Product.setproductid (Uuid.randomuuid (). toString ());5Criteria = Getcurrentsession (). Createcriteria (Product.class);6Criteria.setprojection (Projections.max ("Productorder"));7Integer ProductOrder2 =Productservice.uniqueresultint (criteria);8Integer procuctorder=1;9         if(ProductOrder2 = =NULL){Ten Product.setproductorder (procuctorder); One}Else{ Aproductorder2++; - Product.setproductorder (productOrder2); -         } the Productservice.save (product); -         return true; -}
View Code

This allows you to return true as JSON data to the foreground.

"Spring annotations Error" using controller as background to the foreground Ajax interaction data error

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.