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:functionaddUser(){ varjsondata = {"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