锋哥原创的Springboot+Layui python222网站实战:
python222网站实战课程视频教程(SpringBoot+Python爬虫实战) ( 火爆连载更新中... )_哔哩哔哩_bilibilipython222网站实战课程视频教程(SpringBoot+Python爬虫实战) ( 火爆连载更新中... )共计23条视频,包括:python222网站实战课程视频教程(SpringBoot+Python爬虫实战) ( 火爆连载更新中... )、第2讲 架构搭建实现、第3讲 页面系统属性动态化设计实现等,UP主更多精彩视频,请关注UP账号。https://www.bilibili.com/video/BV1yX4y1a7qM/请求获取第一页数据;
/*** 首页** @return*/
@RequestMapping("/")
public ModelAndView index() {PageBean pageBean = new PageBean(1, 20);System.out.println("首页");ModelAndView mav = new ModelAndView();Page<Article> articlePage = articleService.page(new Page<>(pageBean.getPage(), pageBean.getPageSize()), new QueryWrapper<Article>().orderByDesc("publish_date"));mav.addObject("articleList", articlePage.getRecords());mav.setViewName("index");return mav;
}
网页上 显示数据:
<div class="post_list"><div class="post_item" th:each="article,status:${articleList}"><div class="post_item_text"><a class="post_item_title" th:href="'/article/'+${article.id}" target="_blank" th:text="${article.title}"></a><div class="post_item_summary"><a th:href="'/article/'+${article.id}" target="_blank"><img class="avatar" th:src="'/randomImages/'+${(status.index)%10+1}+'.png'"/></a><p th:text="${article.summary}"></p></div></div><div class="publishDate" th:text="${#dates.format(article.publishDate, 'yyyy-MM-dd HH:mm:ss')}"></div></div>
</div>
帖子随机小图标,映射路径:
randomImagesFilePath: D:\\randomImages\\
@Value("${randomImagesFilePath}")
private String randomImagesFilePath;
registry.addResourceHandler("/randomImages/**").addResourceLocations("file:"+randomImagesFilePath); // 随机头像图片映射
分页实现:
mav.addObject("pageCode", PageUtil.genPagination("/article/list", articlePage.getTotal(), 1, pageBean.getPageSize(), ""));
<div class="pageCode" th:utext="${pageCode}"></div>
package com.python222.controller;import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.python222.entity.Article;
import com.python222.entity.PageBean;
import com.python222.service.ArticleService;
import com.python222.util.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;/*** 帖子Controller控制器* @author python222小锋老师* @site www.python222.com*/
@Controller
@RequestMapping("/article")
public class ArticleController {@Autowiredprivate ArticleService articleService;/*** 分页查询帖子* @return*/@RequestMapping("/list/{page}")public ModelAndView list(@PathVariable(value = "page",required = false)Integer page){PageBean pageBean=new PageBean(page,20);ModelAndView mav=new ModelAndView();Page<Article> articlePage = articleService.page(new Page<>(pageBean.getPage(), pageBean.getPageSize()), new QueryWrapper<Article>().eq("status",2).orderByDesc("publish_date"));mav.addObject("articleList",articlePage.getRecords());mav.addObject("pageCode", PageUtil.genPagination("/article/list",articlePage.getTotal(),page,pageBean.getPageSize(),""));mav.setViewName("index");return mav;}
}