Commit e6035b0d3f5c0bb79a73ae04f14487c062e4abaf

Authored by landong2015
1 parent de17a27a4d
Exists in master

提交代码

Showing 2 changed files with 33 additions and 6 deletions

mainData/src/main/java/com/lymsh/yimiao/main/data/util/ArticleUtil.java View file @ e6035b0
... ... @@ -25,9 +25,9 @@
25 25 return null;
26 26 }
27 27  
28   - public static String getCategoryArticle(){
  28 + public static String getCategory(){
29 29 HttpClient client = new HttpClient();
30   - GetMethod get = new MessageUtil.UTF8GetMethod("http://ams.api.stage.healthbaby.com.cn/v1/yiMiaoArticles.action");
  30 + GetMethod get = new MessageUtil.UTF8GetMethod("http://ams.api.stage.healthbaby.com.cn/v1/category.action");
31 31 try {
32 32 client.executeMethod(get);
33 33 String result = new String(get.getResponseBodyAsString());
... ... @@ -42,6 +42,22 @@
42 42 return null;
43 43 }
44 44  
  45 + public static String getArticle(Integer categoryId,Integer page,Integer limit){
  46 + HttpClient client = new HttpClient();
  47 + GetMethod get = new MessageUtil.UTF8GetMethod("http://ams.api.stage.healthbaby.com.cn/v1/yiMiaoArticles.action?categoryId="+categoryId+"&page="+page+"&limit="+limit);
  48 + try {
  49 + client.executeMethod(get);
  50 + String result = new String(get.getResponseBodyAsString());
  51 + int statusCode = get.getStatusCode();
  52 + if (statusCode==200){
  53 + return result;
  54 + }
  55 + get.releaseConnection();
  56 + }catch (Exception e){
  57 + e.printStackTrace();
  58 + }
  59 + return null;
  60 + }
45 61  
46 62 }
webApi/src/main/java/com/lyms/yimiao/web/controller/v1/ArticleController.java View file @ e6035b0
... ... @@ -7,6 +7,7 @@
7 7 import org.springframework.stereotype.Controller;
8 8 import org.springframework.web.bind.annotation.RequestMapping;
9 9 import org.springframework.web.bind.annotation.RequestMethod;
  10 +import org.springframework.web.bind.annotation.RequestParam;
10 11  
11 12 import javax.servlet.http.HttpServletResponse;
12 13  
13 14  
... ... @@ -25,11 +26,21 @@
25 26 writeJson(response, JsonUtil.obj2JsonString(ArticleUtil.getArticlesImages()));
26 27 }
27 28  
28   - //获取育儿课堂
29   - @RequestMapping(value = "/category/article", method = RequestMethod.GET)
  29 + //获取育儿课堂栏目
  30 + @RequestMapping(value = "/category", method = RequestMethod.GET)
30 31 @TokenRequired
31   - public void getColumn(HttpServletResponse response){
32   - writeJson(response, JsonUtil.obj2JsonString(ArticleUtil.getCategoryArticle()));
  32 + public void getCategory(HttpServletResponse response){
  33 + writeJson(response, JsonUtil.obj2JsonString(ArticleUtil.getCategory()));
  34 + }
  35 +
  36 + //获取文章
  37 + @RequestMapping(value = "/article", method = RequestMethod.GET)
  38 + @TokenRequired
  39 + public void get(HttpServletResponse response,
  40 + @RequestParam("categoryId")Integer categoryId,
  41 + @RequestParam("page")Integer page,
  42 + @RequestParam("limit")Integer limit){
  43 + writeJson(response, JsonUtil.obj2JsonString(ArticleUtil.getArticle(categoryId,page,limit)));
33 44 }
34 45  
35 46 }