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. python 装饰器,生成器,迭代器

    装饰器 作用:当我们想要增强原来已有函数的功能,但不想(无法)修改原函数,可以使用装饰器解决 使用: 先写一个装饰器,就是一个函数,该函数接受一个函数作为参数,返回一个闭包,而且闭包中执行传递进来的函 ...

  2. Jenkins 入门系列--jenkins 介绍

    第一章 Jenkins是什么? Jenkins 是一个可扩展的持续集成引擎. 主要用于: l 持续.自动地构建/测试软件项目. l 监控一些定时执行的任务. Jenkins拥有的特性包括: l 易于安 ...

  3. Cypress自动化测试系列之二

    本文技术难度★★★,如果前编内容顺利执行,请继续. 如果Selenium尚无法灵活运用的读者,本文可能难度较大. “理论联系实惠,密切联系领导,表扬和自我表扬”——我就是老司机,曾经写文章教各位怎么打 ...

  4. libusb读写

    https://blog.csdn.net/u012247418/article/details/83684980 https://github.com/crazybaoli/libusb-test ...

  5. CentOS系统下使用docker安装pinpoint

    准备:安装docker与docker-compose docker安装参考:https://www.cnblogs.com/zhi-leaf/p/10561501.html docker-compos ...

  6. linux cp复制目录所有文件

    mkdir gpio cp -r build/ /home/yl/gpio 这样就把build目录及所有文件都拷贝到gpio文件夹中.

  7. head&tail命令

    1.tail tail命令用途是按照要求将指定的文件的最后部分输出到标准设备, 一般是终端,通俗来讲,就是把某个档案文件的最后几行显示到终端上, 如果该档案有更新,tail会自动刷新,确保你看到最新的 ...

  8. 去掉我的电脑中WPS,百度云,360,爱奇艺盘符

    open regedit ,跳转到 HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\Na ...

  9. postman -- token全局变量

    var data = JSON.parse(responseBody);if (data.data.token) { tests["Body has token"] = true; ...

  10. (转)window.open和window.showModalDialog的区别

    window.open和window.showModalDialog区别: 1.都是在IE上打开新窗口,只不过前者是非阻塞式,也可以说非模态窗口.而后者是阻塞式模态窗口.阻塞或者模态窗口,只有你把当前 ...