Cxf Receiving Object Parameters

Source: Internet
Author: User

At first I used SPRINGMVC to do the interface, the front end can be post a JSON-formatted string, to the backend automatically assembled into my desired Java object, need to set up a converter: < bean class = "org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" >      < property name = "messageConverters" >      < list >          < bean class = "org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />      < st >      </ property > </ bean >This allows the JSON data to be transmitted via JS: function addUser(){          var jsondata = { "username" : "hahaha" , "password" : "fsd" };          $.ajax({              type: "POST" ,              url: "/lotteryproject/services/rest/sample/hahaha" ,              dataType: "json" ,                   contentType: "application/json" ,                            data:jsondata,              success: function (data){                  alert( "添加用户成功!" );                                    }           });

The request can then return a JSON object correctly, and the test is normal

Then I changed the SPRING+CXF way to develop the RESTful interface, the interface is defined as follows:

@POST      @Path ( "/hahaha" )      @Produces ( "application/json" )      public User regedit(User ut);I set jsonprovider so that it can return a JSON-formatted data at response time and test successfully: < bean id = "jsonProvider" class = "org.codehaus.jackson.jaxrs.JacksonJsonProvider" > </ bean > < jaxrs:providers >     < ref bean = "jsonProvider" />                        </ jaxrs:providers >

Cxf Receiving Object Parameters

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.