mirror of
https://github.com/201206030/novel-plus.git
synced 2025-04-27 01:30:51 +00:00
bug修复
This commit is contained in:
parent
daa38c0df9
commit
ca798314e3
@ -1,6 +1,7 @@
|
|||||||
package com.java2nb.novel.controller;
|
package com.java2nb.novel.controller;
|
||||||
|
|
||||||
import com.java2nb.novel.core.bean.UserDetails;
|
import com.java2nb.novel.core.bean.UserDetails;
|
||||||
|
import com.java2nb.novel.core.utils.CookieUtil;
|
||||||
import com.java2nb.novel.core.utils.JwtTokenUtil;
|
import com.java2nb.novel.core.utils.JwtTokenUtil;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@ -17,13 +18,9 @@ public class BaseController {
|
|||||||
|
|
||||||
|
|
||||||
protected String getToken(HttpServletRequest request){
|
protected String getToken(HttpServletRequest request){
|
||||||
Cookie[] cookies = request.getCookies();
|
String token = CookieUtil.getCookie(request,"Authorization");
|
||||||
if(cookies != null) {
|
if(token != null){
|
||||||
for (Cookie cookie : cookies) {
|
return token;
|
||||||
if (cookie.getName().equals("Authorization")) {
|
|
||||||
return cookie.getValue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return request.getHeader("Authorization");
|
return request.getHeader("Authorization");
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.java2nb.novel.controller;
|
package com.java2nb.novel.controller;
|
||||||
|
|
||||||
import com.java2nb.novel.core.utils.TemplateUtil;
|
import com.java2nb.novel.core.utils.ThreadLocalUtil;
|
||||||
import com.java2nb.novel.entity.Book;
|
import com.java2nb.novel.entity.Book;
|
||||||
import com.java2nb.novel.entity.BookContent;
|
import com.java2nb.novel.entity.BookContent;
|
||||||
import com.java2nb.novel.entity.BookIndex;
|
import com.java2nb.novel.entity.BookIndex;
|
||||||
@ -49,7 +49,7 @@ public class PageController{
|
|||||||
* */
|
* */
|
||||||
@RequestMapping(path = {"/", "/index", "/index.html"})
|
@RequestMapping(path = {"/", "/index", "/index.html"})
|
||||||
public String index() {
|
public String index() {
|
||||||
return TemplateUtil.getTemplateDir()+"index";
|
return ThreadLocalUtil.getTemplateDir()+"index";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -66,7 +66,7 @@ public class PageController{
|
|||||||
@RequestMapping("book/book_ranking.html")
|
@RequestMapping("book/book_ranking.html")
|
||||||
public String bookRank() {
|
public String bookRank() {
|
||||||
|
|
||||||
return TemplateUtil.getTemplateDir()+"book/book_ranking";
|
return ThreadLocalUtil.getTemplateDir()+"book/book_ranking";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -80,7 +80,7 @@ public class PageController{
|
|||||||
//查询首章目录ID
|
//查询首章目录ID
|
||||||
Long firstBookIndexId = bookService.queryFirstBookIndexId(bookId);
|
Long firstBookIndexId = bookService.queryFirstBookIndexId(bookId);
|
||||||
model.addAttribute("firstBookIndexId",firstBookIndexId);
|
model.addAttribute("firstBookIndexId",firstBookIndexId);
|
||||||
return TemplateUtil.getTemplateDir()+"book/book_detail";
|
return ThreadLocalUtil.getTemplateDir()+"book/book_detail";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -93,7 +93,7 @@ public class PageController{
|
|||||||
List<BookIndex> bookIndexList = bookService.queryIndexList(bookId,null,null);
|
List<BookIndex> bookIndexList = bookService.queryIndexList(bookId,null,null);
|
||||||
model.addAttribute("bookIndexList",bookIndexList);
|
model.addAttribute("bookIndexList",bookIndexList);
|
||||||
model.addAttribute("bookIndexCount",bookIndexList.size());
|
model.addAttribute("bookIndexCount",bookIndexList.size());
|
||||||
return TemplateUtil.getTemplateDir()+"book/book_index";
|
return ThreadLocalUtil.getTemplateDir()+"book/book_index";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -116,7 +116,7 @@ public class PageController{
|
|||||||
//查询内容
|
//查询内容
|
||||||
BookContent bookContent = bookService.queryBookContent(bookIndex.getId());
|
BookContent bookContent = bookService.queryBookContent(bookIndex.getId());
|
||||||
model.addAttribute("bookContent",bookContent);
|
model.addAttribute("bookContent",bookContent);
|
||||||
return TemplateUtil.getTemplateDir()+"book/book_content";
|
return ThreadLocalUtil.getTemplateDir()+"book/book_content";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2,13 +2,10 @@ package com.java2nb.novel.core.filter;
|
|||||||
|
|
||||||
import com.java2nb.novel.core.cache.CacheKey;
|
import com.java2nb.novel.core.cache.CacheKey;
|
||||||
import com.java2nb.novel.core.cache.CacheService;
|
import com.java2nb.novel.core.cache.CacheService;
|
||||||
import com.java2nb.novel.core.utils.BrowserUtil;
|
import com.java2nb.novel.core.utils.*;
|
||||||
import com.java2nb.novel.core.utils.Constants;
|
|
||||||
import com.java2nb.novel.core.utils.SpringUtil;
|
|
||||||
import com.java2nb.novel.core.utils.TemplateUtil;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
|
|
||||||
import javax.servlet.*;
|
import javax.servlet.*;
|
||||||
|
import javax.servlet.http.Cookie;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
@ -53,23 +50,29 @@ public class NovelFilter implements Filter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
String userMark = CookieUtil.getCookie(req,Constants.USER_CLIENT_MARK);
|
||||||
|
if(userMark == null){
|
||||||
|
userMark = UUIDUtil.getUUID32();
|
||||||
|
CookieUtil.setCookie(resp,Constants.USER_CLIENT_MARK,userMark);
|
||||||
|
}
|
||||||
|
ThreadLocalUtil.setCientId(userMark);
|
||||||
//根据浏览器类型选择前端模板
|
//根据浏览器类型选择前端模板
|
||||||
String to = req.getParameter("to");
|
String to = req.getParameter("to");
|
||||||
CacheService cacheService = SpringUtil.getBean(CacheService.class);
|
CacheService cacheService = SpringUtil.getBean(CacheService.class);
|
||||||
if("pc".equals(to)){
|
if("pc".equals(to)){
|
||||||
//直接进PC站
|
//直接进PC站
|
||||||
cacheService.set(CacheKey.TEMPLATE_DIR_KEY,"",60*60*24);
|
cacheService.set(CacheKey.TEMPLATE_DIR_KEY+userMark,"",60*60*24);
|
||||||
}else if("mobile".equals(to)){
|
}else if("mobile".equals(to)){
|
||||||
//直接进手机站
|
//直接进手机站
|
||||||
cacheService.set(CacheKey.TEMPLATE_DIR_KEY,"mobile/",60*60*24);
|
cacheService.set(CacheKey.TEMPLATE_DIR_KEY+userMark,"mobile/",60*60*24);
|
||||||
}else{
|
}else{
|
||||||
//自动识别是PC站还是手机站
|
//自动识别是PC站还是手机站
|
||||||
if(BrowserUtil.isMobile(req)){
|
if(BrowserUtil.isMobile(req)){
|
||||||
//手机端访问
|
//手机端访问
|
||||||
TemplateUtil.setTemplateDir("mobile/");
|
ThreadLocalUtil.setTemplateDir("mobile/");
|
||||||
}else{
|
}else{
|
||||||
//PC端访问
|
//PC端访问
|
||||||
TemplateUtil.setTemplateDir("");
|
ThreadLocalUtil.setTemplateDir("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,4 +15,9 @@ public class Constants {
|
|||||||
* 本地图片保存前缀
|
* 本地图片保存前缀
|
||||||
* */
|
* */
|
||||||
public static final String LOCAL_PIC_PREFIX = "/localPic/";
|
public static final String LOCAL_PIC_PREFIX = "/localPic/";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户客户端标识
|
||||||
|
* */
|
||||||
|
public static final String USER_CLIENT_MARK = "userClientMark";
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,29 @@
|
|||||||
|
package com.java2nb.novel.core.utils;
|
||||||
|
|
||||||
|
import javax.servlet.http.Cookie;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Administrator
|
||||||
|
*/
|
||||||
|
public class CookieUtil {
|
||||||
|
|
||||||
|
public static String getCookie(HttpServletRequest request,String key){
|
||||||
|
Cookie[] cookies = request.getCookies();
|
||||||
|
if(cookies != null) {
|
||||||
|
for (Cookie cookie : cookies) {
|
||||||
|
if (cookie.getName().equals(key)) {
|
||||||
|
return cookie.getValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public static void setCookie(HttpServletResponse response,String key,String value){
|
||||||
|
Cookie cookie = new Cookie(key, value);
|
||||||
|
cookie.setPath("/");
|
||||||
|
response.addCookie(cookie);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -7,13 +7,18 @@ import com.java2nb.novel.core.cache.CacheService;
|
|||||||
* 模板操作工具类
|
* 模板操作工具类
|
||||||
* @author Administrator
|
* @author Administrator
|
||||||
*/
|
*/
|
||||||
public class TemplateUtil {
|
public class ThreadLocalUtil {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 存储当前线程访问的模板目录
|
* 存储当前线程访问的模板目录
|
||||||
* */
|
* */
|
||||||
private static ThreadLocal<String> templateDir = new ThreadLocal<>();
|
private static ThreadLocal<String> templateDir = new ThreadLocal<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 存储当前会话的sessionID
|
||||||
|
* */
|
||||||
|
private static ThreadLocal<String> clientId = new ThreadLocal<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置当前应该访问的模板目录
|
* 设置当前应该访问的模板目录
|
||||||
* */
|
* */
|
||||||
@ -26,12 +31,20 @@ public class TemplateUtil {
|
|||||||
* */
|
* */
|
||||||
public static String getTemplateDir(){
|
public static String getTemplateDir(){
|
||||||
CacheService cacheService = SpringUtil.getBean(CacheService.class);
|
CacheService cacheService = SpringUtil.getBean(CacheService.class);
|
||||||
String prefix = cacheService.get(CacheKey.TEMPLATE_DIR_KEY);
|
String prefix = cacheService.get(CacheKey.TEMPLATE_DIR_KEY+clientId.get());
|
||||||
if(prefix != null){
|
if(prefix != null){
|
||||||
return prefix;
|
return prefix;
|
||||||
}
|
}
|
||||||
return templateDir.get();
|
return templateDir.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置当前访问线程的客户端ID
|
||||||
|
* */
|
||||||
|
public static void setCientId(String id){
|
||||||
|
clientId.set(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -179,6 +179,11 @@
|
|||||||
for (var i = 0; i < bookList.length; i++) {
|
for (var i = 0; i < bookList.length; i++) {
|
||||||
var book = bookList[i];
|
var book = bookList[i];
|
||||||
|
|
||||||
|
var end = book.bookDesc.indexOf("<");
|
||||||
|
if(end != -1) {
|
||||||
|
book.bookDesc = book.bookDesc.substring(0,end);
|
||||||
|
}
|
||||||
|
|
||||||
bookListHtml += ("<div class=\"layui-row\" style=\"margin-bottom:10px;padding:10px;background: #f2f2f2\">\n" +
|
bookListHtml += ("<div class=\"layui-row\" style=\"margin-bottom:10px;padding:10px;background: #f2f2f2\">\n" +
|
||||||
" <a href=\"/book/"+book.id+".html\">\n" +
|
" <a href=\"/book/"+book.id+".html\">\n" +
|
||||||
" <div class=\"layui-col-xs6 layui-col-sm3 layui-col-md2 layui-col-lg2\" style=\"text-align: center\">\n" +
|
" <div class=\"layui-col-xs6 layui-col-sm3 layui-col-md2 layui-col-lg2\" style=\"text-align: center\">\n" +
|
||||||
@ -199,7 +204,7 @@
|
|||||||
" <div style=\"margin-top: 5px;color: #4c6978;\">状态:"+(book.bookStatus==0?'连载':'完结')+"</div>\n" +
|
" <div style=\"margin-top: 5px;color: #4c6978;\">状态:"+(book.bookStatus==0?'连载':'完结')+"</div>\n" +
|
||||||
" <div style=\"margin-top: 5px;color: #4c6978;\">更新:<i>"+book.lastIndexUpdateTime+"</i>\n" +
|
" <div style=\"margin-top: 5px;color: #4c6978;\">更新:<i>"+book.lastIndexUpdateTime+"</i>\n" +
|
||||||
" </div>\n" +
|
" </div>\n" +
|
||||||
" <div style=\"margin-top: 5px;color: #4c6978;\">简介:"+(book.bookDesc?(book.bookDesc.length>20?(book.bookDesc.substr(0,20)+"..."):bookDesc.length):book.bookDesc)+"</div>\n" +
|
" <div style=\"margin-top: 5px;color: #4c6978;\">简介:"+(book.bookDesc?(book.bookDesc.length>20?(book.bookDesc.substr(0,20)+"..."):book.bookDesc):book.bookDesc)+"</div>\n" +
|
||||||
"\n" +
|
"\n" +
|
||||||
"\n" +
|
"\n" +
|
||||||
" </div>\n" +
|
" </div>\n" +
|
||||||
|
@ -323,6 +323,10 @@
|
|||||||
for (var i = 0; i < 10; i++) {
|
for (var i = 0; i < 10; i++) {
|
||||||
|
|
||||||
var updateRankBook = updateRankBooks[i];
|
var updateRankBook = updateRankBooks[i];
|
||||||
|
var end = updateRankBook.bookDesc.indexOf("<");
|
||||||
|
if(end != -1) {
|
||||||
|
updateRankBook.bookDesc = updateRankBook.bookDesc.substring(0,end);
|
||||||
|
}
|
||||||
|
|
||||||
updateRankBookHtml += ("<div style=\"padding-bottom: 30px\"\n" +
|
updateRankBookHtml += ("<div style=\"padding-bottom: 30px\"\n" +
|
||||||
" class=\"layui-col-xs12 layui-col-sm6 layui-col-md6 layui-col-lg6\">\n" +
|
" class=\"layui-col-xs12 layui-col-sm6 layui-col-md6 layui-col-lg6\">\n" +
|
||||||
|
Loading…
x
Reference in New Issue
Block a user