Let a mthod in RestControl return a json string
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的更多相关文章
- Array(数组)与Json String (Json字符串) 的相互转换
1.Array转换成Json String function jsonToString(arr) { var s = ""; ...
- json string 与object 之间的转化
1.将json string转化成object 1: public static T GetObjectFromJson<T>(string jsonString) 2: { 3: Dat ...
- Jackson将json string转为Object,org.json读取json数组
从json文件读取json string或者自定义json string,将其转为object.下面采用的object为map,根据map读取json的某个数据,可以读取第一级的数据name,后来发现 ...
- Convert List<Entity> to Json String.
public static string ToJson(this object obj, string datetimeformats) { var timeConverter = new I ...
- 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' = ...
- 解决 Jackson反序列化 Unexpected token ... , expected VALUE_STRING: need JSON String that contains type id (for subtype of ...)
首先检查是否是 objectMapper.enableDefaultTyping(); 的受害者.优先考虑删除该配置. 使用Jackson把数组的json字符串反序列化为List时候报了个JsonMa ...
- You're trying to decode an invalid JSON String JSON返回有解析问题
SpringMVC架构的web程序,通常用map返回消息在浏览器中显示,但是实际中报下列错误“”You're trying to decode an invalid JSON String“返回的字符 ...
- function $(id) { return typeof id === "string" ? document.getElementById(id) : id; }
function $(id) { return typeof id === "string" ? document.getElementById(id) : id; } 这句代 ...
- .net backend return json string , used by frontend
伪代码: backend: public string GetJson() { var lst = xxxLst; var obj = Json(lst);return new JavaScriptS ...
随机推荐
- 误删除/dec/zero,/dev/null
误删除/dev/zero [root@MYSQL-MONGO145 dev]# mknod /dev/zero c 1 5[root@MYSQL-MONGO145 dev]# chmod 666 /d ...
- 两个实体类 复制 copy 工具类
import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.Date; public class ...
- Mac下的LDAP客户端 ApacheDirectoryStudio
mac下的ldap browser,最开始下载的最新版本的 地址 http://directory.apache.org/studio/downloads.html 使用的时候经常卡死,尝试下载老版本 ...
- SQL Server里面如何导出包含数据的SQL脚本
通常情况下,SQL Server里面的生成SQL脚本,只会包含数据库及表的字段结构,而不会包含表的数据,也就是SQL脚本里面只有Create database,Create table 这样的语句,没 ...
- DeepFM: A Factorization-Machine based Neural Network for CTR Prediction (2017)论文要点
论文链接: https://arxiv.org/pdf/1703.04247.pdf FM原理参考: Factorization Machines with libFM 论文阅读 https://w ...
- tomcat访问日志
* %a - Remote IP address # 远程ip地址 * %A - Local IP address # 本地ip地址 * %b - Bytes sent, excluding HTTP ...
- python广度遍历文件夹
import os from collections import deque path = r"E:\Python" queue = deque([])#队列 queue.app ...
- Vue学习搭建(基础)
空项目:https://github.com/ElementUI/element-starter.git 参考教程:https://blog.csdn.net/xuehu837769474/artic ...
- CSS3的2D 转换——旋转,缩放,translate(),skew(),matrix()
2D转换方法:在平面对元素进行旋转,缩放,移动,拉伸. ㈠浏览器支持 ⑴2D转换效果有以下的浏览器支持: ⑵在编辑代码的时候要注明用哪种浏览器打开,在前面加上前缀,下面是编辑器的简写形式,以及前缀 ...
- PDFtk:PDF文件处理
造冰箱的大熊猫@cnblogs 2018/9/12 使用PDFtk很多年了,今天得空把相关内容整理总结一下. 1.PDFtk能干什么 - 是否想把两个PDF文档合并到一起 - 是否想从PDF文档中摘出 ...