Fil*_*son 0 java spring json spring-boot
我正在创建一个spring-boot应用程序,我希望能够将一个hashmap的全部内容作为json字符串返回.我怎么做?
我的hashmap如下所示:
private static final Map<String,Animal> animalMap= new HashMap<String,Animal>();
Run Code Online (Sandbox Code Playgroud)
功能
@RequestMapping(value="/animals", method=RequestMethod.GET)
public String showAllAnimals() {
// In here I want to return the content of my hashmap as a Json String
}
Run Code Online (Sandbox Code Playgroud)
Dav*_*yer 11
@RequestMapping(value="/animals", method=RequestMethod.GET)
@ResponseBody
public Map<String,Animal> showAllAnimals() {
return animalMap;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6049 次 |
| 最近记录: |