@RestController 用于返回对象,会自动格式化为JSON

    @RequestMapping("/user2")
    public User2 user2(Model model){
        model.addAttribute("content", hello + "(第二种)");
        User2 user=new User2();
        user.setId(1);
        user.setName("tomas");
        user.setPwd("pwd");
        return user;
    }

@Control会默认返回jsp页面

想返回对象的话还需要加上@ResponseBody注解

@RequestMapping("/user2")

    @ResponseBody
    public User2 user2(Model model){
        model.addAttribute("content", hello + "(第二种)");
        User2 user=new User2();
        user.setId(1);
        user.setName("tomas");
        user.setPwd("pwd");
        return user;
    }

返回结果一致:

{

  • id: 1,
  • name: "tomas",
  • pwd: "pwd"

}

Spring MVC返回对象JSON的更多相关文章

  1. Spring MVC 返回 xml json pdf 数据的配置方法

    <!-- Spring MVC 返回 xml 数据的配置方法 -->     <bean class="org.springframework.web.servlet.vi ...

  2. Spring MVC返回的json如何去除根节点名称

    spring xml中配置视图如果是如下 <property name="defaultViews"> <list> <bean class=&quo ...

  3. spring mvc返回json字符串数据,只需要返回一个java bean对象就行,只要这个java bean 对象实现了序列化serializeable

    1.spring mvc返回json数据,只需要返回一个java bean对象就行,只要这个java bean 对象实现了序列化serializeable 2. @RequestMapping(val ...

  4. spring mvc返回json字符串的方式

    spring mvc返回json字符串的方式 方案一:使用@ResponseBody 注解返回响应体 直接将返回值序列化json            优点:不需要自己再处理 步骤一:在spring- ...

  5. IntelliJ IDEA:Getting Started with Spring MVC, Hibernate and JSON实践

    原文:IntelliJ IDEA:Getting Started with Spring MVC, Hibernate and JSON实践 最近把编辑器换成IntelliJ IDEA,主要是Ecli ...

  6. IntelliJIDEA Getting+Started+with+Spring+MVC,+Hibernate+and+JSON

    https://confluence.jetbrains.com/display/IntelliJIDEA/Getting+Started+with+Spring+MVC,+Hibernate+and ...

  7. Spring MVC 返回NULL时客户端用$.getJSON的问题

    如果Spring MVC返回是NULL,那么客户端的$.getJSON就不会触发: 必须返回点什么东西: 如果返回的是一个字符串,客户端的$.getJSON也不会触发:把字符串 包装成List< ...

  8. Spring MVC返回json数据给Android端

    原先做Android项目时,服务端接口一直是别人写的,自己拿来调用一下,但下个项目,接口也要自己搞定了,我想用Spring MVC框架来提供接口,这两天便抽空浅学了一下该框架以及该框架如何返回json ...

  9. Spring mvc 返回json格式 - 龙企阁 - 博客频道 - CSDN.NET

    第一次使用spring mvc ,在此也算是记录一下以防忘记,希望有经验的朋友指出不足的地方 一.使用maven管理jar. <dependency> <groupId>org ...

随机推荐

  1. C#入门经典(第五版)学习笔记(三)

    ---------------面向对象编程简介--------------- UML表示方法: 1)方框上中下三分 2)上框写类名 3)中框写属性和字段,例如:+Description:string  ...

  2. Java Swing 使用总结(转载)

    随笔转载自:此去经年ぢ 地址:http://www.cnblogs.com/FLFL/p/5369756.html 1.     GUI编程引言 以前的学习当中,我们都使用的是命令交互方式: 例如:在 ...

  3. 【POJ2352】【树状数组】Stars

    Description Astronomers often examine star maps where stars are represented by points on a plane and ...

  4. struts2文件上传,文件类型 allowedTypes

    struts2文件上传,文件类型 allowedTypes 1 '.a' : 'application/octet-stream', 2 '.ai' : 'application/postscript ...

  5. 用css3实现鼠标移进去当前亮其他变灰

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...

  6. PAT - 基础 - 龟兔赛跑

    题目: 乌龟与兔子进行赛跑,跑场是一个矩型跑道,跑道边可以随地进行休息.乌龟每分钟可以前进3米,兔子每分钟前进9米:兔子嫌乌龟跑得慢,觉得肯定能跑赢乌龟,于是,每跑10分钟回头看一下乌龟,若发现自己超 ...

  7. Android扫描二维码 实现 登录网页

    工程代码:ScanQRcode.zip ------------------------------------------------------------------ 1. 扫描二维码登录的实现 ...

  8. wndows常用命令

    1. 远程桌面 mstsc (Microsoft terminal services client)

  9. jquery的笔记

    1. 基本选择器 基本的  #id      .class     element(元素)     *(全部元素) $("#id")   $(".class") ...

  10. A Statistical View of Deep Learning (III): Memory and Kernels

    A Statistical View of Deep Learning (III): Memory and Kernels Memory, the ways in which we remember ...