07-springmvc-Json处理
发布日期:2021-05-10 18:27:55 浏览次数:21 分类:精选文章

本文共 2488 字,大约阅读时间需要 8 分钟。

��������������� JSON ������

��� Spring MVC ������������������ JSON ��������������� JSON ��������������������������������������������������������������� JSON ������������������������

������ JSON ������

��������� JSON ������������������������������������������������������������������������������������

@RequestMapping(value = "/param12")public String getValue12(@RequestBody Student student) {    System.out.println(student);    return "mmm";}

���������������������@RequestBody ������������ Spring MVC automatic ������ HTTP ������������������������������������������ Student ������������������������������������������ Student ��������������������������� deserializer ������������������������������������ JSON ���������������������������

������ JSON ������

��������� JSON ������������������������������ @RestController ��������������������� @ResponseBody ��� @Controller annotatins������������������ Java ��������������� JSON ������������������

��������������������� JSON ������������������

@RequestMapping("/param11")@ResponseBodypublic Student getValue11() {    Student student = new Student();    student.setsId(1);    student.setsName("wang");    student.setsAddress("������");    return student;}

������������ JSON ������������������������������������������ List Student���

@RequestMapping("/param11")@ResponseBodypublic List
getValue11() { List
list = new ArrayList<>(); Student student1 = new Student(1, "wang111", "������111"); Student student2 = new Student(2, "wang222", "������222"); list.add(student1); list.add(student2); return list;}

��������������������������������������������������������������� @RequestMapping ������������������������������������

@RequestMapping(value = "/param11", produces = "text/html;charset=utf-8")public String getValue11() {    return "������";}

������ JSON ������������

������������ JSON ������������������������������������������������������������������ JSON ��������������������������������������� Jackson ��������������� Maven ������������

com.fasterxml.jackson.core
jackson-databind
2.11.4

������������������������ JSON ������������������������������������ fastjson ���������������

com.alibaba
fastjson
1.2.75

������

��������������������������������������� Spring MVC ������������������ JSON ���������������������������������������������������������������������������������������������

上一篇:08-springmvc-异常解析器
下一篇:06-springmvc-静态资源

发表评论

最新留言

不错!
[***.144.177.141]2025年04月15日 20时55分01秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章