中软国际实训日记第十天-7.30

目录

1.首页

2.分类

3.标签

正文

1.首页

1.1控制层

 @RequestMapping
    public String index(@PageableDefault(size=5,sort={"updateTime"},direction = Sort.Direction.DESC) Pageable pageable
            , Model model){
        Page page=newsService.findByPageable(pageable);
        List types=typeService.findTop(5);
        List tags=tagService.findTop(5);
        model.addAttribute("page",page);
        model.addAttribute("types",types);
        model.addAttribute("tags",tags);
        return "index";
    }

1.2实现层

 @Override
      public List findTop(int i) {
            Sort sort=Sort.by(Sort.Direction.DESC,"updateTime");
            Pageable pageable= PageRequest.of(0,i,sort);
            return newsDao.findTop(pageable);
      }

1.3界面
中软国际实训日记第十天-7.30_第1张图片

2.分类

2.1控制层

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

2.2实现层

 @Override
    public List findTop(int i) {
        Sort sort=Sort.by(Sort.Direction.DESC,"newsList.size");
        Pageable pageable= PageRequest.of(0,i,sort);
        return typeDao.findTop(pageable);
    }

2.3界面
中软国际实训日记第十天-7.30_第2张图片

3.标签

3.1控制层


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

3.2实现层

@Override
    public List findTop(int i) {
        Sort sort=Sort.by(Sort.Direction.DESC,"newsList.size");
        Pageable pageable= PageRequest.of(0,i,sort);
        return tagDao.findTop(pageable);
    }

3.3界面
中软国际实训日记第十天-7.30_第3张图片

你可能感兴趣的:(实习日记)