BlogController.java
1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package com.bootdo.blog.controller;
import com.bootdo.blog.domain.ContentDO;
import com.bootdo.blog.service.ContentService;
import com.bootdo.common.utils.DateUtils;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author bootdo 1992lcg@163.com
*/
@RequestMapping("/blog")
@Controller
public class BlogController {
@Autowired
ContentService bContentService;
@GetMapping()
String blog() {
return "blog/index/main";
}
@ResponseBody
@GetMapping("/open/list")
public PageUtils opentList(@RequestParam Map<String, Object> params) {
Query query = new Query(params);
List<ContentDO> bContentList = bContentService.list(query);
int total = bContentService.count(query);
PageUtils pageUtils = new PageUtils(bContentList, total);
return pageUtils;
}
@GetMapping("/open/post/{cid}")
String post(@PathVariable("cid") Long cid, Model model) {
ContentDO bContentDO = bContentService.get(cid);
model.addAttribute("bContent", bContentDO);
model.addAttribute("gtmModified", DateUtils.format(bContentDO.getGtmModified()));
return "blog/index/post";
}
@GetMapping("/open/page/{categories}")
String about(@PathVariable("categories") String categories, Model model) {
Map<String, Object> map = new HashMap<>(16);
map.put("categories", categories);
ContentDO bContentDO =null;
if(bContentService.list(map).size()>0){
bContentDO = bContentService.list(map).get(0);
}
model.addAttribute("bContent", bContentDO);
return "blog/index/post";
}
}