diff --git a/pom.xml b/pom.xml index 7010b1e..2f72140 100644 --- a/pom.xml +++ b/pom.xml @@ -106,13 +106,30 @@ javase 3.3.0 - org.apache.ws.commons.axiom base64-utils 1.4.0 + + + org.apache.httpcomponents + httpclient + 4.5.5 + + + org.apache.httpcomponents + httpcore + 4.4.14 + + + commons-logging + commons-logging + 1.2 + + + com.fasterxml.jackson.core diff --git a/src/main/java/com/lovenav/controller/BannersController.java b/src/main/java/com/lovenav/controller/BannersController.java index 2d6b1f8..5c61041 100644 --- a/src/main/java/com/lovenav/controller/BannersController.java +++ b/src/main/java/com/lovenav/controller/BannersController.java @@ -1,6 +1,5 @@ package com.lovenav.controller; -import com.fasterxml.jackson.annotation.JsonFormat; import com.lovenav.entity.Banners; import com.lovenav.service.BannersService; import org.springframework.beans.factory.annotation.Autowired; diff --git a/src/main/java/com/lovenav/controller/CommentController.java b/src/main/java/com/lovenav/controller/CommentController.java index 5675743..d3dd6c7 100644 --- a/src/main/java/com/lovenav/controller/CommentController.java +++ b/src/main/java/com/lovenav/controller/CommentController.java @@ -1,19 +1,10 @@ package com.lovenav.controller; -import com.alibaba.fastjson2.JSONObject; import com.lovenav.entity.Comment; import com.lovenav.service.CommentService; -import com.lovenav.service.serviceImpl.CommentServiceImpl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; -import java.io.IOException; -import java.io.PrintWriter; -import java.io.Writer; -import java.util.HashMap; @RestController @RequestMapping("/comment") diff --git a/src/main/java/com/lovenav/dao/BannersDao.java b/src/main/java/com/lovenav/dao/BannersDao.java index a3af52b..6689a45 100644 --- a/src/main/java/com/lovenav/dao/BannersDao.java +++ b/src/main/java/com/lovenav/dao/BannersDao.java @@ -21,5 +21,5 @@ public interface BannersDao { int updateByPrimaryKey(Banners record); - List selectByAllBanners(); + List selectAllBanners(); } \ No newline at end of file diff --git a/src/main/java/com/lovenav/dao/CommentDao.java b/src/main/java/com/lovenav/dao/CommentDao.java index 0c3cfe6..3bc1f61 100644 --- a/src/main/java/com/lovenav/dao/CommentDao.java +++ b/src/main/java/com/lovenav/dao/CommentDao.java @@ -22,7 +22,7 @@ public interface CommentDao { int updateByPrimaryKey(Comment record); - List selectByAllComment(); + List selectAllComment(); List selectByAllReply(int id); } \ No newline at end of file diff --git a/src/main/java/com/lovenav/entity/Banners.java b/src/main/java/com/lovenav/entity/Banners.java index 145d01d..1a93850 100644 --- a/src/main/java/com/lovenav/entity/Banners.java +++ b/src/main/java/com/lovenav/entity/Banners.java @@ -2,9 +2,6 @@ package com.lovenav.entity; import java.io.Serializable; import java.util.Date; - -import com.alibaba.fastjson2.annotation.JSONField; -import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; /** diff --git a/src/main/java/com/lovenav/service/serviceImpl/BannersServiceImpl.java b/src/main/java/com/lovenav/service/serviceImpl/BannersServiceImpl.java index a79bc4e..fda9a46 100644 --- a/src/main/java/com/lovenav/service/serviceImpl/BannersServiceImpl.java +++ b/src/main/java/com/lovenav/service/serviceImpl/BannersServiceImpl.java @@ -1,6 +1,6 @@ package com.lovenav.service.serviceImpl; -import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson2.JSON; import com.lovenav.dao.BannersDao; import com.lovenav.entity.Banners; import com.lovenav.service.BannersService; @@ -59,9 +59,8 @@ public class BannersServiceImpl implements BannersService { } // 展示banner - @Override public String View_banner(){ - List list = bannersDao.selectByAllBanners(); + List list = bannersDao.selectAllBanners(); return JSON.toJSONString(list); } } diff --git a/src/main/java/com/lovenav/service/serviceImpl/CommentServiceImpl.java b/src/main/java/com/lovenav/service/serviceImpl/CommentServiceImpl.java index 9b07f99..d82491b 100644 --- a/src/main/java/com/lovenav/service/serviceImpl/CommentServiceImpl.java +++ b/src/main/java/com/lovenav/service/serviceImpl/CommentServiceImpl.java @@ -6,11 +6,8 @@ import com.lovenav.dao.CommentDao; import com.lovenav.dao.UserDao; import com.lovenav.entity.Comment; import com.lovenav.service.CommentService; -import org.apache.ibatis.jdbc.Null; -import org.mybatis.spring.annotation.MapperScan; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; - import java.util.HashMap; import java.util.List; @@ -69,7 +66,7 @@ public class CommentServiceImpl implements CommentService { // 显示评论 public String View_comment(){ - List list = commentDao.selectByAllComment(); + List list = commentDao.selectAllComment(); return JSON.toJSONString(list); } diff --git a/src/main/java/com/lovenav/utils/UrlCheckUtil.java b/src/main/java/com/lovenav/utils/UrlCheckUtil.java new file mode 100644 index 0000000..1dcf885 --- /dev/null +++ b/src/main/java/com/lovenav/utils/UrlCheckUtil.java @@ -0,0 +1,74 @@ +package com.lovenav.utils; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import sun.net.www.protocol.http.HttpURLConnection; + +import java.io.IOException; +import java.net.*; +import javax.net.ssl.HttpsURLConnection; + +public class UrlCheckUtil { + + /** + * 判断链接是否有效 + * 输入链接 + * 返回true或者false + */ + public static boolean isUrlValid(String strLink) { + URL url; + try { + url = new URL(strLink); + HttpURLConnection connt = (HttpURLConnection)url.openConnection(); + connt.setRequestMethod("HEAD"); + String strMessage = connt.getResponseMessage(); + if (strMessage.compareTo("Not Found") == 0) { + return false; + } + connt.disconnect(); + } catch (Exception e) { + return false; + } + return true; + } + + public static String checkUrlConnection(String url) { + // 创建http POST请求 + HttpGet httpGet = new HttpGet(url); + httpGet.setHeader("Content-Type", "application/json"); + RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(600)// 设置连接主机服务超时时间 + .setConnectionRequestTimeout(1000)// 设置连接请求超时时间 + .setSocketTimeout(1000)// 设置读取数据连接超时时间 + .build(); + // 为httpPost实例设置配置 + httpGet.setConfig(requestConfig); + // 设置请求头 + CloseableHttpClient httpclient = null; + CloseableHttpResponse response = null; + int statusCode = 404; + try { + httpclient = HttpClients.createDefault();// 创建Httpclient对象 + response = httpclient.execute(httpGet);// 执行请求 + statusCode = response.getStatusLine().getStatusCode(); + }catch (SocketException e) { + return "404"; + } catch (IOException e) { + System.out.println("报错"); + return "404"; + } + return String.valueOf(statusCode); + } + + public static boolean CheckHttp(String address) throws URISyntaxException, MalformedURLException { + URL url = new URL(address); + URI uri = url.toURI(); + System.out.println(uri.getScheme()); + if(uri.getScheme().equals("https")){ + return true; + }else + return false; + } + +} \ No newline at end of file diff --git a/src/main/resources/mybatis/BannersDao.xml b/src/main/resources/mybatis/BannersDao.xml index a2b8727..4ad849a 100644 --- a/src/main/resources/mybatis/BannersDao.xml +++ b/src/main/resources/mybatis/BannersDao.xml @@ -97,10 +97,11 @@ - select * from ln_banners + where banner_status = 0; \ No newline at end of file diff --git a/src/main/resources/mybatis/CommentDao.xml b/src/main/resources/mybatis/CommentDao.xml index e1a4fbf..12f7f52 100644 --- a/src/main/resources/mybatis/CommentDao.xml +++ b/src/main/resources/mybatis/CommentDao.xml @@ -146,7 +146,7 @@ - select * from ln_comment