@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. Sprite Kit教程:初学者

    作者:Ray Wenderlich 原文出处:点击打开链接 http://www.raywenderlich.com/42699/spritekit-tutorial-for-beginners 转自 ...

  2. Adapter 模式

    在实际软件系统设计和开发中,会经常遇到这种问题:我们为了完成某项工作购买了一个第三方的库来加快开发. 这就带来了一个问题: 我们在应用程序中已经设计好了接口,与这个第三方提供的接口不一致,为了使得这些 ...

  3. 翻译-让ng的$http服务与jQuerr.ajax()一样易用

    Make AngularJS $http service behave like jQuery.ajax() 让ng的$http服务与jQuerr.ajax()一样易用 作者zeke There is ...

  4. Python Tutorial 学习(二)--Using the Python Interpreter

    Using the Python Interpreter 2.1. Invoking the Interpreter The Python interpreter is usually install ...

  5. WebApi Gzip(Deflate) 压缩请求数据

    由于不能直接访问指定数据库,只能通过跳板机查询Oracle数据,所以要做一个数据中转接口, 查询数据就要压缩,于是就找资料,代码如下,其中要注意的是Response.Headers.Remove(&q ...

  6. Java线程生命模型

    一. 线程状态类型1. 新建状态(New):新创建了一个线程对象.2. 就绪状态(Runnable):线程对象创建后,其他线程调用了该对象的start()方法.该状态的线程位于可运行线程池中,变得可运 ...

  7. Web.config总结

    %windir%/Microsoft.NET/Framework/v2.0.50727/CONFIG目录下machine.config定义了针对当前机器的WinForm程序和asp.net应用程序的配 ...

  8. A Statistical View of Deep Learning (V): Generalisation and Regularisation

    A Statistical View of Deep Learning (V): Generalisation and Regularisation We now routinely build co ...

  9. how to optimize javascript performance

    https://developers.google.com/speed/articles/optimizing-javascript http://developer.yahoo.com/perfor ...

  10. [转]Aggregate tasks i Sharepoint 2013

    from http://sharepoint247.com/mysite/aggregate-tasks-i-sharepoint-2013/ Aggregate tasks i Sharepoint ...