7-30java实训日记

7-30日Java实训感受

  1. 7-30,是java实训的第十一天,在昨天已经实现了新闻系统的后台开发,今天实训老师带我们实现了新闻系统的前台项=项目,这个部分主要是实现对数据的查询和显示,主要实现了新闻系统的首页、分类和标签管理。
  2. 此外,在老师讲完课后,自己在中午通过亲自实现老师早上讲的功能,对老师所讲的知识有了一个更加深刻的学习和体会
  3. 其次,今天是小组项目开发的第三天,我今天主要实现后台登录和路由跳转功能。

springboot框架新闻系统前台实现流程

  1. 控制层
@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";
    }
}

@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";
    }
}

@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";
    }
}

  1. 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 TagDao extends JpaRepository<Tag,Long> {
@Query("select t from Tag t")
    List<Tag> findTop(Pageable pageable);
}

  1. server层
    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;
    }

springboot框架新闻系统前台实现效果

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

springboot小组项目登录

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值