【发布时间】:2017-09-05 01:43:24
【问题描述】:
我在spring boot中消费了一个web service(REST),数据是json,格式如下:
{
"id": 679,
"score": 3
},
{
"id": 682,
"score": 3
},
{
"id": 692,
"score": 3
}
使用完数据后,我必须生成一个 Web 服务,它以 JSON 格式提供数据,如下所示
{
status:{
"code":"OK",
"message":"success"
}
data:[
{
"id": 679,
"score": 3
},
{
"id": 682,
"score": 3
},
{
"id": 692,
"score": 3
}
]
}
所以目前我在控制器部分做的是
@RequestMapping(value="/data",produces={MediaType.APPLICATION_JSON_VALUE},method=RequestMethod.GET)
public ResponseEntity<List<Model>> getBooking(@RequestParam("lat")double latitude,@RequestParam("lon") double longitude,@RequestParam("id") int id){
list=getapi(latitude,longitude,id);
return new ResponseEntity<List<Model>>(list,HttpStatus.OK);
}
@ResponseBody
public List<Model> getapi(double latitude,double longitude,int id){
List<Model> list = Arrays.asList(restTemplatestreetapi.getForObject("http://dataurl, Model[].class));
return list;
}
我现在的模型类是这样的
public class Model {
int id;
int score;
public int getid() {
return id;
}
public void setid(int id) {
this.id = id;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
}
我使用该服务并直接生成它。但我想生成上述结果,而不是这个。感谢任何帮助。
【问题讨论】:
标签: java json web-services rest spring-boot