The get method of EmpControl

package com.hy.empcloud;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class EmpControl {
    @Autowired
    EmpService service;

    @Autowired
    RestTemplate restTemplate;

    @GetMapping("/test")
    public String test() {
        return "Hello";
    }

    @GetMapping("/emp/{id}")
    public Emp get(@PathVariable Long id) throws Exception{
        return this.service.find(id);
    }

    @RequestMapping(value="/all",method=RequestMethod.GET,produces=MediaType.APPLICATION_JSON_VALUE)
    public List<Emp> get() {
        return this.service.getAll();
    }
}

Visit url and it's returned value

[{"id":1,"name":"Andy","age":41},{"id":2,"name":"刘德华","age":42},{"id":3,"name":"Bill","age":43},{"id":4,"name":"比尔","age":44}]

--END--

2019年8月24日21点09分

Let a mthod in RestControl return a json string的更多相关文章

  1. Array(数组)与Json String (Json字符串) 的相互转换

    1.Array转换成Json String             function jsonToString(arr) {             var s = "";     ...

  2. json string 与object 之间的转化

    1.将json string转化成object 1: public static T GetObjectFromJson<T>(string jsonString) 2: { 3: Dat ...

  3. Jackson将json string转为Object,org.json读取json数组

    从json文件读取json string或者自定义json string,将其转为object.下面采用的object为map,根据map读取json的某个数据,可以读取第一级的数据name,后来发现 ...

  4. Convert List<Entity> to Json String.

    public static string ToJson(this object obj, string datetimeformats) {     var timeConverter = new I ...

  5. perl malformed JSON string, neither tag, array, object, number, string or atom, at character offset

    [root@wx03 ~]# cat a17.pl use JSON qw/encode_json decode_json/ ; use Encode; my $data = [ { 'name' = ...

  6. 解决 Jackson反序列化 Unexpected token ... , expected VALUE_STRING: need JSON String that contains type id (for subtype of ...)

    首先检查是否是 objectMapper.enableDefaultTyping(); 的受害者.优先考虑删除该配置. 使用Jackson把数组的json字符串反序列化为List时候报了个JsonMa ...

  7. You're trying to decode an invalid JSON String JSON返回有解析问题

    SpringMVC架构的web程序,通常用map返回消息在浏览器中显示,但是实际中报下列错误“”You're trying to decode an invalid JSON String“返回的字符 ...

  8. function $(id) { return typeof id === "string" ? document.getElementById(id) : id; }

    function $(id) {   return typeof id === "string" ? document.getElementById(id) : id; } 这句代 ...

  9. .net backend return json string , used by frontend

    伪代码: backend: public string GetJson() { var lst = xxxLst; var obj = Json(lst);return new JavaScriptS ...

随机推荐

  1. Date对象中的方法

    特殊说明:设置时间的方法,虽然W3C说明传参的范围,在开发过程中,传入的参数不在该范围也是可以的.例如: var t = new Date(), d = t.getDate(); //当天时间往前推2 ...

  2. CentOS 7系统时间与实际时间差8个小时

    1.查看系统时间: [root@localhost sysconfig]# timedatectl Local time: 一 2017-11-06 21:13:19 CST Universal ti ...

  3. ThinkPHP依赖注入

    D:\wamp64\www\thinkphp5.1\tp5.1\application\index\controller\Demo1.php文件 <?php namespace app\inde ...

  4. Linux--Shell 编程-bash,命令替换,if分支嵌套,运算,输入输出

    SHELL 编程     shell 是一个命令解释器,侦听用户指令.启动这些指令.将结果返回给用户(交互式的shell)     shell 也是一种简单的程序设计语言.利用它可以编写一些系统脚本. ...

  5. 第二篇.2、python基础之字符编码

    一 了解字符编码的知识储备 一 计算机基础知识 二 文本编辑器存取文件的原理(nodepad++,pycharm,word) #1.打开编辑器就打开了启动了一个进程,是在内存中的,所以,用编辑器编写的 ...

  6. 自学Python-基于tcp协议的socket

    自学Python之路-Python基础+模块+面向对象自学Python之路-Python网络编程自学Python之路-Python并发编程+数据库+前端自学Python之路-django 自学Pyth ...

  7. libcyusb

    https://github.com/hmaarrfk/libcyusb/blob/master/include/cyusb.h

  8. java 集合数组排序

    //数组排序Integer arr[] = {3,4,2};Arrays.sort(arr);//默认升序Arrays.sort(arr,Comparator.reverseOrder());//传一 ...

  9. es6的Map结构

    es6的Map结构主要解决Object的键名只能是单一属性的问题.它可以是字符串,对象,数组,等等 其中有个问题要注意一下,就是 var map = new Map(); map.set(['a'], ...

  10. TOP K和Partition对比

    TOP k算法适用于海量数据,不用一批装入内存.. partition算法需要全部装入内存排序,需要修改原数据..