zoukankan      html  css  js  c++  java
  • 实现文章上一篇下一篇

    文章上下翻页显示标题

    @GetMapping(value = "newsDetail")
    public String newsDetail(Model model, @RequestParam(value = "nId") String nId)
    {
    News n = newsService.findOne(Long.valueOf(nId.trim()));
    if (n != null) {
    List<News> newsList = newsService.findByNewsType(n.getNewsType());
    //判断元素是否存在 contains()
    if(newsList.size()!=0){
    Integer index = newsList.indexOf(n);
    n.setNextIndex(index);
    Integer upperIndex = index==0?newsList.size()-1:index-1;
    Integer lowerIndex = index==newsList.size()-1?0:index+1;
    //当前新闻为第一个时,上一篇为最后一篇
    News upperNews = newsList.get(upperIndex);
    upperNews.setNextIndex(upperIndex);
    //当前新闻为最后一个时,下一篇为第一篇
    News lowerNews = newsList.get(lowerIndex);
    lowerNews.setNextIndex(lowerIndex);
    model.addAttribute("upperNews",upperNews);
    model.addAttribute("lowerNews",lowerNews);
    model.addAttribute("news", n);
    return this.render("newsDetail");
    }
    }
    return this.render("index");
    }

     前端:

                    <div>
                        <span style="float: left"><a href="#"><<</a>上一篇: <a href="/az/newsDetail?nId=${upperNews.newsId?c}">${upperNews.newsTitle}</a></span>
                        <span style="float: right"><a href="#">>></a>下一篇: <a href="/az/newsDetail?nId=${upperNews.newsId?c}">${lowerNews.newsTitle}</a></span>
                    </div>
  • 相关阅读:
    C/C++多文件之间的变量定义
    PKU POJ 2186 Popular Cows 强连通分量
    重载函数
    ZOJ 2763 Prison Break
    201357 训练赛总结
    hdu 4467 Graph 构造
    201356 训练赛总结
    201353 NEERC 2012, Eastern subregional contest
    2013512 CF 183 总结
    一道动态规划
  • 原文地址:https://www.cnblogs.com/ssjf/p/11307818.html
Copyright © 2011-2022 走看看