【发布时间】:2017-12-23 13:57:31
【问题描述】:
我有一个带有以下签名的端点
@RequestMapping(method = RequestMethod.GET, value = "/{id}", produces = {"application/json; charset=UTF-8"})
@Transactional(readOnly = true)
@ResponseBody
public HashMap<String, Object> myMethod(@PathVariable("id") Long id) {...}`
我想用 RestTemplate 进行单元测试。我怎么能做到这一点,因为在方法 getForObject 中我不能将集合作为 responseType。
有什么想法吗?
【问题讨论】:
-
你能解释一下你的意思吗:“我不能把一个集合作为一个 responseType”?当然可以使用集合(或地图)作为响应类型,例如
restTemplate.getForEntity(url, Map.class).getBody(),restTemplate.getForObject(url, Map.class)。或许您有可以向我们展示的堆栈跟踪信息?
标签: java spring resttemplate endpoint