http://zhidao.baidu.com/link?url=cOEy4uem4hxIWj5DLJvfboHt5p_nBSTTyF82G1tRGRLvCRavQhuxznzgHMLSroweQ9ZGI0ih4paSWVjjbs1OhWqA4EbULpXLhMxlXIQi8mC
这个很简单可以使用spring mvc自带的jackson
1、web工程lib中加入jackson所需jar包:jackson-core-asl-1.9.9.jar、jackson-mapper-asl-1.9.9.jar
2、在applicationContext.xml中加入jackson的配置
1
2
3
4
|
<!-- json转换器 -->
<
bean
id
=
"jsonConverter"
class
=
"org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"
> <
property
name
=
"supportedMediaTypes"
value
=
"application/json"
/>
</
bean
>
|
3、在你的action中直接使用注解的方式"@ResponseBody"自动将返回值转化成json格式
1
2
3
4
5
6
7
8
9
|
@Controller
@RequestMapping
(
"task"
)
public
class
TaskControl {
@RequestMapping
(
"getUserById"
)
@ResponseBody
public
List getUserById(Integer id) {
return
this
.taskService.getUserById(id);
}
}
|
4、jsp页面的js写法跟普通ajax格式一样
1
2
3
4
5
|
functon getUserById(id){
$.getJSON(
"task/getUserById"
,{id:id},
function
(data){
});
}
|