zr实训7.30

SpringBoot项目实现分类和分标签显示

controller层
ArchivesController

@Controller
public class ArchivesController {
    @Autowired
    private NewsService newsService;

    @RequestMapping("archives")
    public String archives(Model model){
        HashMap<String, List<News>> map=newsService.archiveNews();
        Long count=newsService.countNews();
        model.addAttribute("newsCount",count);
        model.addAttribute("archiveMap",map);

        return "archives";
    }
}

TagShowController

@Controller
public class TagShowController {
    @Autowired
    private TagService tagService;
    @Autowired
    private NewsService newsService;


    @RequestMapping("/tags/{id}")
    public String tag(@PageableDefault(size = 5,sort = {"updateTime"},direction = Sort.Direction.DESC) Pageable pageable,
                      @PathVariable Long id, Model model){
        List<Tag> tags=tagService.findTop(7);
        if(id==-1){
            id=tags.get(0).getId();
        }
        Page<News> page=newsService.searchNews(pageable,id);
        model.addAttribute("page",page);
        model.addAttribute("tags",tags);
        return "tags";
    }
}

TypeShowController

@Controller
public class TypeShowController {
    @Autowired
    private TypeService typeService;
    @Autowired
    private NewsService newsService;

    @RequestMapping("/types/{id}")
    public String types(@PageableDefault(size = 5,sort = {"updateTime"},direction = Sort.Direction.DESC)Pageable pageable,
                        @PathVariable Long id, Model model){
        List<Type> types=typeService.findTop(7);
        if(id==-1){
            id=types.get(0).getId();
        }
        NewsQuery newsQuery=new NewsQuery();
        newsQuery.setTypeId(id.toString());
        Page<News> page=newsService.searchNews(pageable,newsQuery);
        model.addAttribute("page",page);
        model.addAttribute("types",types);

        return "types";
    }
}

dao层

public interface NewsDao extends JpaRepository<News,Long> , JpaSpecificationExecutor<News> {

    @Query("select function('date_format',n.updateTime,'%Y') as year from News n group by function('date_format',n.updateTime,'%Y') order by year desc")
    List<String> findGroupYear();

    @Query("select n from News n where function('date_format',n.updateTime,'%Y') = ?1")
    List<News> findByYear(String y);
}
public interface TagDao extends JpaRepository<Tag,Long> {
@Query("select t from Tag t")
    List<Tag> findTop(Pageable pageable);
}
public interface TypeDao extends JpaRepository<Type,Long> {

    @Query("select t from Type t")
    List<Type> findTop(Pageable pageable);
}

service层

 public HashMap<String, List<News>> archiveNews() {
        LinkedHashMap<String,List<News>> map=new LinkedHashMap<>();
        List<String> years=newsDao.findGroupYear();
        for(String y:years){
            List<News> news = newsDao.findByYear(y);
            map.put(y,news);
        }
        return map;
    }
 public List<Tag> findTop(int i) {
        Sort sort=Sort.by(Sort.Direction.DESC,"newsList.size");
        Pageable pageable= PageRequest.of(0,i,sort);
        return tagDao.findTop(pageable);
    }
  public List<Type> findTop(int i) {
        Sort sort=Sort.by(Sort.Direction.DESC,"newsList.size");
        Pageable pageable=PageRequest.of(0,i,sort);

        return typeDao.findTop(pageable);
    }    
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: Endpoint 7.30是指计算机网络中的终端,也叫做“终端节点7.30”。在网络架构中,终端节点是最终的数据接收和发送者。Endpoint 7.30则是指一个特定的终端节点,可能在某个时间点连接到网络中进行数据接收和传输。Endpoint 7.30可能是一个设备(如服务器、路由器等)或者是一个应用(如浏览器、邮件客户端等),根据网络的设计和用途不同,其角色也会有所不同。Endpoint 7.30的特定表述也可能是指该终端节点在某个时间节点发生的特定事件或者具有特定的功能。在网络安全方面,Endpoint 7.30也可能是指需要受到保护的终端节点,需要采用一系列策略和措施保护其安全性和完整性。终端节点在网络中的地位非常重要,其稳定性和安全性直接影响到整个网络的运行。因此,在进行网络架构设计和网络安全管理时,必须充分考虑Endpoint 7.30的存在和作用。 ### 回答2: Endpoint7.30是指7月30日的终端节点。在网络通信中,终端节点指的是网络中的最后一站,通常是设备或计算机。Endpoint7.30可以是一个特定的终端节点,例如一个服务器、一个路由器或一部移动设备。在数据传输过程中,数据会从起始节点经过网络传输,最终到达Endpoint7.30这一终端节点。 Endpoint7.30可以是一个重要的节点,因为它可能是数据交换的最终目的地,或者是数据流转中的临时存储点。在网络安全方面,Endpoint7.30也是一个值得关注的节点,因为攻击者可能会试图利用这个节点来入侵网络或盗取敏感数据。因此,需要采取措施来保障Endpoint7.30的安全,例如加密数据、设置访问权限、更新软件等。 总之,Endpoint7.30是指7月30日的终端节点,以及它在网络通信和安全方面的重要性。 ### 回答3: Endpoint 7.30 是指某个软件或系统中的某个具体节点或功能版本。在软件或系统开发过程中,会不断地更新和升级不同的节点和版本,Endpoint 7.30 就是这其中的一个版本号。一般来说,每个版本的更新都会修复一些已知的问题和漏洞,同时增强一些功能,提升系统的性能和稳定性。 Endpoint 7.30 可能是某个系统的最新版本,也可能只是一个过渡性的版本,在后续的更新中将被替换或淘汰。对于使用者来说,及时升级软件或系统的不同节点和版本,可以保证更好的使用体验,同时也能增强系统的安全性和稳定性。 总之,Endpoint 7.30 只是软件或系统中的一个版本号,代表着某个具体的节点或功能版本,其重要性和作用取决于具体的软件或系统。对于使用者来说,及时升级和更新不同的节点和版本,能够让系统运行得更加顺畅稳定,同时也能够保障数据的安全性和隐私性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值