mirror of
https://github.com/201206030/novel.git
synced 2025-04-27 07:30:50 +00:00
首页优化
This commit is contained in:
parent
5465eae791
commit
c37e539cb4
@ -2,8 +2,6 @@ package xyz.zinglizingli.books.web;
|
||||
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
@ -13,7 +11,6 @@ import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import xyz.zinglizingli.books.constant.CacheKeyConstans;
|
||||
import xyz.zinglizingli.books.po.Book;
|
||||
import xyz.zinglizingli.books.po.BookContent;
|
||||
import xyz.zinglizingli.books.po.BookIndex;
|
||||
@ -21,7 +18,6 @@ import xyz.zinglizingli.books.po.ScreenBullet;
|
||||
import xyz.zinglizingli.books.service.BookService;
|
||||
import xyz.zinglizingli.books.vo.BookVO;
|
||||
import xyz.zinglizingli.common.cache.CommonCacheUtil;
|
||||
import xyz.zinglizingli.common.config.IndexRecBooksConfig;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@ -41,44 +37,8 @@ public class BookController {
|
||||
@Autowired
|
||||
private CommonCacheUtil commonCacheUtil;
|
||||
|
||||
@Autowired
|
||||
private IndexRecBooksConfig indexRecBooksConfig;
|
||||
|
||||
|
||||
private Logger log = LoggerFactory.getLogger(BookController.class);
|
||||
|
||||
|
||||
@RequestMapping("index.html")
|
||||
public String index(ModelMap modelMap) {
|
||||
|
||||
List<Book> recBooks = (List<Book>) commonCacheUtil.getObject(CacheKeyConstans.REC_BOOK_LIST_KEY);
|
||||
if (!indexRecBooksConfig.isRead() || recBooks == null) {
|
||||
List<Map<String,String>> configMap = indexRecBooksConfig.getRecBooks();
|
||||
//查询推荐书籍数据
|
||||
recBooks = bookService.queryRecBooks(configMap);
|
||||
commonCacheUtil.setObject(CacheKeyConstans.REC_BOOK_LIST_KEY, recBooks, 60 * 60 * 24 * 10);
|
||||
indexRecBooksConfig.setRead(true);
|
||||
}
|
||||
|
||||
|
||||
List<Book> hotBooks = (List<Book>) commonCacheUtil.getObject(CacheKeyConstans.HOT_BOOK_LIST_KEY);
|
||||
if (hotBooks == null) {
|
||||
//查询热点数据
|
||||
hotBooks = bookService.search(1, 9, null, null, null, null, null, null, null, "visit_count DESC,score ", "DESC");
|
||||
commonCacheUtil.setObject(CacheKeyConstans.HOT_BOOK_LIST_KEY, hotBooks, 60 * 60 * 24);
|
||||
}
|
||||
List<Book> newBooks = (List<Book>) commonCacheUtil.getObject(CacheKeyConstans.NEWST_BOOK_LIST_KEY);
|
||||
if (newBooks == null) {
|
||||
//查询最近更新数据
|
||||
newBooks = bookService.search(1, 20, null, null, null, null, null, null, null, "update_time", "DESC");
|
||||
commonCacheUtil.setObject(CacheKeyConstans.NEWST_BOOK_LIST_KEY, newBooks, 60 * 30);
|
||||
}
|
||||
modelMap.put("recBooks", recBooks);
|
||||
modelMap.put("hotBooks", hotBooks);
|
||||
modelMap.put("newBooks", newBooks);
|
||||
return "books/index";
|
||||
}
|
||||
|
||||
@RequestMapping("search")
|
||||
public String search(@RequestParam(value = "curr", defaultValue = "1") int page, @RequestParam(value = "limit", defaultValue = "20") int pageSize,
|
||||
@RequestParam(value = "keyword", required = false) String keyword, @RequestParam(value = "catId", required = false) Integer catId,
|
||||
|
@ -1,17 +1,64 @@
|
||||
package xyz.zinglizingli.common.web;
|
||||
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import xyz.zinglizingli.books.constant.CacheKeyConstans;
|
||||
import xyz.zinglizingli.books.po.Book;
|
||||
import xyz.zinglizingli.books.service.BookService;
|
||||
import xyz.zinglizingli.common.cache.CommonCacheUtil;
|
||||
import xyz.zinglizingli.common.config.IndexRecBooksConfig;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Controller
|
||||
@RequestMapping
|
||||
public class IndexController {
|
||||
|
||||
|
||||
@Autowired
|
||||
private BookService bookService;
|
||||
|
||||
@RequestMapping(value = {"/index.html","/"})
|
||||
public String index(){
|
||||
return "redirect:/books";
|
||||
@Autowired
|
||||
private CommonCacheUtil commonCacheUtil;
|
||||
|
||||
@Autowired
|
||||
private IndexRecBooksConfig indexRecBooksConfig;
|
||||
|
||||
|
||||
|
||||
|
||||
@RequestMapping(value = {"/index.html","/","/books","/books/index.html"})
|
||||
public String index(ModelMap modelMap){
|
||||
List<Book> recBooks = (List<Book>) commonCacheUtil.getObject(CacheKeyConstans.REC_BOOK_LIST_KEY);
|
||||
if (!indexRecBooksConfig.isRead() || recBooks == null) {
|
||||
List<Map<String,String>> configMap = indexRecBooksConfig.getRecBooks();
|
||||
//查询推荐书籍数据
|
||||
recBooks = bookService.queryRecBooks(configMap);
|
||||
commonCacheUtil.setObject(CacheKeyConstans.REC_BOOK_LIST_KEY, recBooks, 60 * 60 * 24 * 10);
|
||||
indexRecBooksConfig.setRead(true);
|
||||
}
|
||||
|
||||
|
||||
List<Book> hotBooks = (List<Book>) commonCacheUtil.getObject(CacheKeyConstans.HOT_BOOK_LIST_KEY);
|
||||
if (hotBooks == null) {
|
||||
//查询热点数据
|
||||
hotBooks = bookService.search(1, 9, null, null, null, null, null, null, null, "visit_count DESC,score ", "DESC");
|
||||
commonCacheUtil.setObject(CacheKeyConstans.HOT_BOOK_LIST_KEY, hotBooks, 60 * 60 * 24);
|
||||
}
|
||||
List<Book> newBooks = (List<Book>) commonCacheUtil.getObject(CacheKeyConstans.NEWST_BOOK_LIST_KEY);
|
||||
if (newBooks == null) {
|
||||
//查询最近更新数据
|
||||
newBooks = bookService.search(1, 20, null, null, null, null, null, null, null, "update_time", "DESC");
|
||||
commonCacheUtil.setObject(CacheKeyConstans.NEWST_BOOK_LIST_KEY, newBooks, 60 * 30);
|
||||
}
|
||||
modelMap.put("recBooks", recBooks);
|
||||
modelMap.put("hotBooks", hotBooks);
|
||||
modelMap.put("newBooks", newBooks);
|
||||
|
||||
return "books/index";
|
||||
}
|
||||
}
|
||||
|
@ -3,9 +3,6 @@ server:
|
||||
|
||||
spring:
|
||||
datasource:
|
||||
# url: jdbc:mysql://148.70.59.92:3306/books?useUnicode=true&characterEncoding=utf-8&useSSL=false
|
||||
# username: xiongxiaoyang
|
||||
# password: Lzslov123!
|
||||
url: jdbc:mysql://148.70.59.92:3306/books?useUnicode=true&characterEncoding=utf-8&useSSL=false
|
||||
username: xiongxiaoyang
|
||||
password: Lzslov123!
|
||||
@ -17,7 +14,7 @@ spring:
|
||||
config: classpath:ehcache.xml
|
||||
thymeleaf:
|
||||
mode: LEGACYHTML5 #去除thymeleaf的html严格校验thymeleaf.mode=LEGACYHTML5
|
||||
cache: true # 是否开启模板缓存,默认true,建议在开发时关闭缓存,不然没法看到实时页面
|
||||
cache: true # 是否开启模板缓存,默认true,建议在开发时关闭缓存,不然没法看到实时
|
||||
freemarker:
|
||||
template-loader-path: classpath:/templates #设定freemarker文件路径 默认为src/main/resources/templatestemplate-loader-path=classpath:/templates
|
||||
charset: UTF-8 # 模板编码
|
||||
|
Loading…
x
Reference in New Issue
Block a user