@Test public void getTagNameAndCount() throws Exception { mockMvc.perform(get("/tags/nac")).andDo(result -> { JSONObject object = JSONObject.fromObject(result.getResponse().getContentAsString()); assertEquals(SUCCESS.getCode(), object.getInt(Code)); JSONArray jsonArray = object.getJSONArray(Result); assertNotNull(jsonArray); jsonArray.forEach(o -> { JSONObject json = JSONObject.fromObject(o); assertTrue(json.containsKey("size")); assertTrue(json.containsKey("name")); }); }); }
@GetMapping("/tags/nac") public Response getTagNameAndCount() { List<JSONObject> nameAndCount = new ArrayList<>(); List<Tag> all = tagService.findAll(); for (Tag t : all) { JSONObject jsonObject = new JSONObject(); jsonObject.put("name", t.getName()); String articles = t.getArticles(); jsonObject.put("size", articles == null ? 0 : articles.split(",").length); nameAndCount.add(jsonObject); } return ResponseUtil.success(nameAndCount); }
TagController { @GetMapping("/tags/nac") public Response getTagNameAndCount() { List<JSONObject> nameAndCount = new ArrayList<>(); List<Tag> all = tagService.findAll(); for (Tag t : all) { JSONObject jsonObject = new JSONObject(); jsonObject.put("name", t.getName()); String articles = t.getArticles(); jsonObject.put("size", articles == null ? 0 : articles.split(",").length); nameAndCount.add(jsonObject); } return ResponseUtil.success(nameAndCount); } }
TagController { @GetMapping("/tags/nac") public Response getTagNameAndCount() { List<JSONObject> nameAndCount = new ArrayList<>(); List<Tag> all = tagService.findAll(); for (Tag t : all) { JSONObject jsonObject = new JSONObject(); jsonObject.put("name", t.getName()); String articles = t.getArticles(); jsonObject.put("size", articles == null ? 0 : articles.split(",").length); nameAndCount.add(jsonObject); } return ResponseUtil.success(nameAndCount); }  }
TagController { @GetMapping("/tags/nac") public Response getTagNameAndCount() { List<JSONObject> nameAndCount = new ArrayList<>(); List<Tag> all = tagService.findAll(); for (Tag t : all) { JSONObject jsonObject = new JSONObject(); jsonObject.put("name", t.getName()); String articles = t.getArticles(); jsonObject.put("size", articles == null ? 0 : articles.split(",").length); nameAndCount.add(jsonObject); } return ResponseUtil.success(nameAndCount); }  @PostMapping("/admin/tag/create") Response addOne(@RequestParam("name") String name); @DeleteMapping("/admin/tag/del") Response delOne(@RequestParam("id") long id); @PutMapping("/admin/tag/update") Response updateOne(@RequestParam("id") Long id, @RequestParam("name") String name); @GetMapping("/tag/id/{id}") Response retrieveOneById(@PathVariable("id") long id); @GetMapping("/tag/name/{name}") Response retrieveOneByName(@PathVariable("name") String name); @GetMapping("/tags") Response getPage(@RequestParam(required = false, defaultValue = "10", value = "count") int count,
                            @RequestParam(required = false, defaultValue = "1", value = "page") int page); @GetMapping("/tags/nac") Response getTagNameAndCount(); }
TagController { @GetMapping("/tags/nac") public Response getTagNameAndCount() { List<JSONObject> nameAndCount = new ArrayList<>(); List<Tag> all = tagService.findAll(); for (Tag t : all) { JSONObject jsonObject = new JSONObject(); jsonObject.put("name", t.getName()); String articles = t.getArticles(); jsonObject.put("size", articles == null ? 0 : articles.split(",").length); nameAndCount.add(jsonObject); } return ResponseUtil.success(nameAndCount); }  @PostMapping("/admin/tag/create") Response addOne(@RequestParam("name") String name); @DeleteMapping("/admin/tag/del") Response delOne(@RequestParam("id") long id); @PutMapping("/admin/tag/update") Response updateOne(@RequestParam("id") Long id, @RequestParam("name") String name); @GetMapping("/tag/id/{id}") Response retrieveOneById(@PathVariable("id") long id); @GetMapping("/tag/name/{name}") Response retrieveOneByName(@PathVariable("name") String name); @GetMapping("/tags") Response getPage(@RequestParam(required = false, defaultValue = "10", value = "count") int count,
                            @RequestParam(required = false, defaultValue = "1", value = "page") int page); @GetMapping("/tags/nac") Response getTagNameAndCount();  }