发表于: 2018-01-08 22:52:50
1 639
今天完成的事情
写了用户进入收藏文章列表的接口
@RequestMapping(value = "a/u/collection/article/list",method = RequestMethod.GET)
public String getConlectionArticle(HttpServletRequest request, Model model){
//获取用户id
HttpSession session = request.getSession();
Long uid = (Long) session.getAttribute("userId");
String page0 = request.getParameter("page");
if (null == page0 || page0.equals("")){ //还有其他情况,,,之后写
page0 = "0";
}
Integer page = Integer.valueOf(page0);
//状态码
Integer code = -1;
//获取文章id,根据uid,从文章收藏表,获取用户收藏的文章id,按收藏时间降序排列,
List<Long> articleIds = null;
try {
articleIds = alikeService.getArticleIdsByAlike(uid);
} catch (ServiceException e) {
e.printStackTrace();
code = -100000;
} catch (ServiceDaoException e) {
e.printStackTrace();
code = -100000;
}
//定页数,
int size = articleIds.size();
int begin = page <= size ? page : size;
int end = page+10 <= size ? page+10 : size;
//子集,根据页数,获取,分页
List<Long> subIds0 = articleIds.subList(begin,end);
//直接用subIds0,会报错,
List<Long> subIds = new ArrayList<>(subIds0);
//查询,按输入的id顺序排列,---->按最新收藏时间排序
List<Article> articlePage = null;
try {
articlePage = articleService.getObjectsByIds(subIds);
code = 0;
} catch (ServiceException e) {
e.printStackTrace();
code = -100000;
} catch (ServiceDaoException e) {
e.printStackTrace();
code = -100000;
}
//返回数据
model.addAttribute("articleList",articlePage);
model.addAttribute("code",code);
return "article/json/articleListJson";
}
根据用户id,收藏状态,获取收藏文章id,并根据收藏时间降序排列
明天的计划
完成视频收藏列表部分
遇到的问题
直接用
List<Long> subIds0 = articleIds.subList(begin,end);
会报错,需要再转化为list才行
收获
使用联表查询
评论