import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
@Controller
public class TypeShowController {
@Autowired
private TypeService typeService;
@Autowired
private BlogService blogService;
// 分页查询分类
@GetMapping("/types/{id}")
public String types(@RequestParam(defaultValue = “1”,value = “pageNum”) Integer pageNum, @PathVariable Long id, Model model) {
List types = typeService.getAllTypeAndBlog();
//id为-1表示从首页导航栏点击进入分类页面
if (id == -1) {
id = types.get(0).getId();
}
model.addAttribute(“types”, types);
List blogs = blogService.getByTypeId(id);
PageHelper.startPage(pageNum, 10000);
PageInfo pageInfo = new PageInfo<>(blogs);
model.addAttribute(“pageInfo”, pageInfo);
model.addAttribute(“activeTypeId”, id);
return “types”;
}
}
讲解:
{id}:当id为-1时,表示从首页导航栏进入分类页面,默认第一个分类显示颜色
getAllTypeAndBlog:查询分类名称和博客信息,前端统计出该分类下博客数量
getByTypeId:查询博客列表
5. 前后端交互
- 分类统计
好文
22- 分类列表
大圣,此去欲何?
戴上金箍,没法爱你;放下金箍,没法保护你。我知道上天不会给我第二次机会,曾经我们说好的永远,原来也仅仅只有,十二画,而已。“大圣,此去欲何?”“踏南天,碎凌霄。”“若一去不回……”“便一去不回” 其实很多时候,我们都是有机会的,最后真正放弃的,是我们自己。......
oneStar2020-01-01
2222
2222
好文
- 分页显示
上一页
/
下一页
6. 运行访问
运行项目,访问 http://localhost:8080/ ,点击导航栏的分类,可以看到分类信息和分类博客列表
二、时间轴页面显示时间轴页面显示只要显示博客标题和时间,因此可以直接共用BlogDao中的持久层接口getAllBlog,只需要编写控制层代码即可,在controller包下创建ArchiveShowController类:
package com.star.controller;
import com.star.queryvo.BlogQuery;
import com.star.service.BlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import java.util.List;
@Controller
public class ArchiveShowController {
@Autowired
private BlogService blogService;
@GetMapping("/archives")
public String archive(Model model){
List blogs = blogService.getAllBlog();
model.addAttribute(“blogs”, blogs);
return “archives”;
}
}
- 前后端交互
-
文章标题
三、音乐盒页面显示- 运行访问 运行项目,访问 http://localhost:8080/ ,点击导航栏的时间轴,可以看到阶梯状左右分布、按照时间顺序排布的文章列表
音乐盒是一个静态页面,直接在控制器中返回页面就可以了
package com.star.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class MusicShowController {
@GetMapping("/music")
public String about() {
return “music”;
}
}
四、友人帐页面显示友人帐前端页面显示直接调用持久层的listFriendlink接口,只需编写
《一线大厂Java面试题解析+后端开发学习笔记+最新架构讲解视频+实战项目源码讲义》
【docs.qq.com/doc/DSmxTbFJ1cmN1R2dB】 完整内容开源分享
控制层代码就可以了,在controller包下创建FriendsShowController类:
package com.star.controller;
import com.star.service.FriendlinkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class FriendsShowController {
@Autowired
private FriendlinkService friendlinkService;
@GetMapping("/friends")
public String friends(Model model) {
model.addAttribute(“friendlinks”,friendlinkService.listFriendlink());
return “friends”;
}
}
- 前后端交互
onESTAR
- 运行访问
运行项目,访问 http://localhost:8080/ ,点击导航栏的友人帐,可以查看友链信息:
五、照片墙页面显示照片墙页面显示直接调用持久层的listPicture接口,只需编写控制层代码就可以了,在controller包下创建PictureShowController类:
package com.star.controller;
import com.star.service.PictureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class PictureShowController {
@Autowired
private PictureService pictureService;
@GetMapping("/picture")
public String friends(Model model) {
model.addAttribute(“pictures”,pictureService.listPicture());
return “picture”;
}
}
- 前后端交互



