From 34ab3e98b46c9caa0b6018352a2a5975d71e0402 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BA=AF=E6=B4=81=E7=9A=84=E5=BE=AE=E7=AC=91?= Date: Tue, 22 May 2018 11:47:36 +0800 Subject: [PATCH] m --- .../com/favorites/cache/CacheService.java | 3 ++ .../com/favorites/comm/aop/LoggerAdvice.java | 2 +- .../java/com/favorites/domain/Collect.java | 2 +- .../java/com/favorites/domain/UrlLibrary.java | 4 +- .../service/impl/CollectServiceImpl.java | 3 ++ .../java/com/favorites/utils/HtmlUtil.java | 38 ++++++++++--------- app/src/main/resources/templates/tool.html | 16 +++++--- 7 files changed, 40 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/com/favorites/cache/CacheService.java b/app/src/main/java/com/favorites/cache/CacheService.java index 704d6ac8..2deafcc0 100644 --- a/app/src/main/java/com/favorites/cache/CacheService.java +++ b/app/src/main/java/com/favorites/cache/CacheService.java @@ -36,6 +36,9 @@ public String getMap(String key){ public void addMaps(String key){ + if(key.contains("?")){ + key=key.substring(0,key.indexOf("?")); + } String logoUrl = HtmlUtil.getImge(key); maps.put(key,logoUrl); UrlLibrary urlLibrary = new UrlLibrary(); diff --git a/app/src/main/java/com/favorites/comm/aop/LoggerAdvice.java b/app/src/main/java/com/favorites/comm/aop/LoggerAdvice.java index f63fb7b0..13928a94 100644 --- a/app/src/main/java/com/favorites/comm/aop/LoggerAdvice.java +++ b/app/src/main/java/com/favorites/comm/aop/LoggerAdvice.java @@ -41,7 +41,7 @@ public void addAfterThrowingLogger(JoinPoint joinPoint, LoggerManage loggerManag } private String parseParames(Object[] parames) { - if (null == parames || parames.length <= 0) { + if (null == parames || parames.length <= 0 || parames.length >10240) { return ""; } StringBuffer param = new StringBuffer("传入参数[{}] "); diff --git a/app/src/main/java/com/favorites/domain/Collect.java b/app/src/main/java/com/favorites/domain/Collect.java index 1609a024..49b03c32 100644 --- a/app/src/main/java/com/favorites/domain/Collect.java +++ b/app/src/main/java/com/favorites/domain/Collect.java @@ -18,7 +18,7 @@ public class Collect implements Serializable { private Long userId; @Column(nullable = false) private Long favoritesId; - @Column(nullable = false, columnDefinition = "varchar(500)") + @Column(nullable = false, columnDefinition = "varchar(600)") private String url; @Column(nullable = false) private String title; diff --git a/app/src/main/java/com/favorites/domain/UrlLibrary.java b/app/src/main/java/com/favorites/domain/UrlLibrary.java index 17e26eb0..abd7a03f 100644 --- a/app/src/main/java/com/favorites/domain/UrlLibrary.java +++ b/app/src/main/java/com/favorites/domain/UrlLibrary.java @@ -12,9 +12,9 @@ public class UrlLibrary extends Entitys implements Serializable{ @Id @GeneratedValue(strategy= GenerationType.IDENTITY) private Long id; - @Column(nullable = false) + @Column(nullable = false, columnDefinition = "varchar(600)") private String url; - @Column(nullable = true) + @Column(nullable = true,columnDefinition = "varchar(300)") private String logoUrl; @Column(columnDefinition="INT default 0") private int count; diff --git a/app/src/main/java/com/favorites/service/impl/CollectServiceImpl.java b/app/src/main/java/com/favorites/service/impl/CollectServiceImpl.java index be5dcc47..50b71089 100644 --- a/app/src/main/java/com/favorites/service/impl/CollectServiceImpl.java +++ b/app/src/main/java/com/favorites/service/impl/CollectServiceImpl.java @@ -168,6 +168,9 @@ public void saveCollect(Collect collect) { if(StringUtils.isBlank(collect.getDescription())){ collect.setDescription(collect.getTitle()); } + if(collect.getUrl().contains("?")){ + collect.setUrl(collect.getUrl().substring(0,collect.getUrl().indexOf("?"))); + } collect.setIsDelete(IsDelete.NO); collect.setCreateTime(DateUtils.getCurrentTime()); collect.setLastModifyTime(DateUtils.getCurrentTime()); diff --git a/app/src/main/java/com/favorites/utils/HtmlUtil.java b/app/src/main/java/com/favorites/utils/HtmlUtil.java index ada854c0..bd5cbbd6 100644 --- a/app/src/main/java/com/favorites/utils/HtmlUtil.java +++ b/app/src/main/java/com/favorites/utils/HtmlUtil.java @@ -31,7 +31,7 @@ public class HtmlUtil { public static String getImge(String url){ String logo=""; logo=getPageImg(url); - if(StringUtils.isBlank(logo)){ + if(StringUtils.isBlank(logo) || logo.length()>300){ logo=Const.BASE_PATH + Const.default_logo; } return logo; @@ -60,27 +60,29 @@ public static String getPageImg(String url){ } // 判断图片大小 String fileUrl = download(imgUrl); - File picture = new File(fileUrl); - FileInputStream in = new FileInputStream(picture); - BufferedImage sourceImg = ImageIO.read(in); - String weight = String.format("%.1f",picture.length()/1024.0); - int width = sourceImg.getWidth(); - int height = sourceImg.getHeight(); - // 删除临时文件 - if(picture.exists()){ - in.close(); - picture.delete(); - } - if(Double.parseDouble(weight) <= 0 || width <=0 || height <= 0){ - logger.info("当前图片大小为0,继续获取图片链接"); - imgUrl=""; - }else{ - break; + if(fileUrl!=null){ + File picture = new File(fileUrl); + FileInputStream in = new FileInputStream(picture); + BufferedImage sourceImg = ImageIO.read(in); + String weight = String.format("%.1f",picture.length()/1024.0); + int width = sourceImg.getWidth(); + int height = sourceImg.getHeight(); + // 删除临时文件 + if(picture.exists()){ + in.close(); + picture.delete(); + } + if(Double.parseDouble(weight) <= 0 || width <=0 || height <= 0){ + logger.info("当前图片大小为0,继续获取图片链接"); + imgUrl=""; + }else{ + break; + } } } } catch (Exception e) { // TODO: handle exception - logger.error("getPageImg失败,url:"+url,e); + logger.warn("getPageImg 失败,url:"+url,e.getMessage()); } return imgUrl; } diff --git a/app/src/main/resources/templates/tool.html b/app/src/main/resources/templates/tool.html index 03722387..3a56eede 100644 --- a/app/src/main/resources/templates/tool.html +++ b/app/src/main/resources/templates/tool.html @@ -4,12 +4,16 @@

网页收集工具

- - - - 网页收集小工具 - 云收藏 - (将该按钮拖动至浏览器书签栏,如下图) +
+
1、使用浏览器扩展收藏网页
+ 支持:Chrome/360极速/QQ/UC/百度浏览器 + 下载 +
+
+
2、网页收集小工具
+ 云收藏 + (将该按钮拖动至浏览器书签栏,如下图) +