<
bean
class
=
"org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"
>
<
property
name
=
"messageConverters"
>
<
list
>
<
bean
class
=
"org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"
/>
<
st
>
</
property
>
</
bean
>
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(
"添加用户成功!"
);
}
});
然后请求也能正确返回一个json对象,测试正常
然后我换了spring+cxf的方式来开发restful接口,接口的定义如下:
@POST
@Path
(
"/hahaha"
)
@Produces
(
"application/json"
)
public
User regedit(User ut);
<
bean
id
=
"jsonProvider"
class
=
"org.codehaus.jackson.jaxrs.JacksonJsonProvider"
>
</
bean
>
<
jaxrs:providers
>
<
ref
bean
=
"jsonProvider"
/>
</
jaxrs:providers
>
原文:http://www.cnblogs.com/hudechun/p/5554871.html