ServiceImpl :
@Override public List<?> courseAd(String KEYNAME, String KEYCODE) { String str = "{‘courseAdUrl‘:‘http://xy.baoai.com/curriculum/detail/24‘,‘courseAdID‘:‘1001‘}"; String str1 = "{‘courseAdUrl‘:‘http://xy.baoai.com/curriculum/detail/22‘,‘courseAdID‘:‘1002‘}"; String str2 = "{‘courseAdUrl‘:‘http://xy.baoai.com/curriculum/detail/10‘,‘courseAdID‘:‘1003‘}"; List<Object> list = new ArrayList<>(); list.add(str); list.add(str1); list.add(str2); JSONArray jsonArray = JSONArray.fromObject(list); return jsonArray; }
Controller
@PostMapping("/courseAd") @ResponseBody public ResultModel courseAd(String KEYNAME, String KEYCODE){ List<?> list = courseService.courseAd(KEYNAME, KEYCODE); return ResultModel.build(1, "success", list); }
返回JSON数据
{"status":1,"msg":"success","data":[{"courseAdUrl":"http://xy.baoai.com/curriculum/detail/24","courseAdID":"1001"},{"courseAdUrl":"http://xy.baoai.com/curriculum/detail/22","courseAdID":"1002"},{"courseAdUrl":"http://xy.baoai.com/curriculum/detail/10","courseAdID":"1003"}],"success":null}
原文地址:http://15129824665.blog.51cto.com/10510385/1903139