From 32ec34633cd87f2a1dbe8d6432e81eacc084cb37 Mon Sep 17 00:00:00 2001 From: Zhang Liguo <482370576@qq.com> Date: Sat, 23 Dec 2023 00:26:08 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=B3=A8=E5=86=8C=E8=AE=A1=E6=97=B6?= =?UTF-8?q?=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lovenav/controller/UserController.java | 19 +++++++++++++++++++ src/main/java/com/lovenav/dao/UserDao.java | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/lovenav/controller/UserController.java b/src/main/java/com/lovenav/controller/UserController.java index 0b2e13e..4c42103 100644 --- a/src/main/java/com/lovenav/controller/UserController.java +++ b/src/main/java/com/lovenav/controller/UserController.java @@ -10,6 +10,7 @@ import com.lovenav.utils.TokenUtils; import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.web.ServerProperties; +import org.springframework.mail.javamail.JavaMailSenderImpl; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; @@ -23,6 +24,9 @@ import java.io.IOException; import java.io.PrintWriter; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; @RestController public class UserController { @@ -31,15 +35,30 @@ public class UserController { @Autowired TokenUtils tokenUtils; //发送邮箱验证码 + ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(5); + //这个是我用户Service实现类可以自行替换 + + //这个是邮件类,必须要导入哦 + @GetMapping("/sendActiveCode") public String sendActiveCode(HttpSession session, User user){ String activecode=userService.sendEmailActivecode(user); session.setAttribute(user.getUserEmail(),activecode); + scheduledExecutorService.schedule(new Runnable() { + @Override + public void run() { + session.removeAttribute(user.getUserEmail()); + System.out.println(session.getAttribute(user.getUserEmail())); + } + },60, TimeUnit.SECONDS); return "发送验证码成功!"; } @RequestMapping("/register") public String userRegister(HttpSession session,User user){ + if (session.getAttribute(user.getUserEmail())==null){ + return "验证码过期"; + } // 比较验证码 if (!user.getActiveCode().equals((String) session.getAttribute(user.getUserEmail()))) { return "验证码不正确"; diff --git a/src/main/java/com/lovenav/dao/UserDao.java b/src/main/java/com/lovenav/dao/UserDao.java index ff38752..09e0bd6 100644 --- a/src/main/java/com/lovenav/dao/UserDao.java +++ b/src/main/java/com/lovenav/dao/UserDao.java @@ -5,8 +5,8 @@ import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Select; import org.springframework.stereotype.Repository; -@Repository @Mapper +@Repository public interface UserDao { int deleteByPrimaryKey(Integer id); From 1b4bf2837143385cdf9754cb3b2d7312424ddadf Mon Sep 17 00:00:00 2001 From: sjm <2431685932@qq.com> Date: Sat, 23 Dec 2023 15:34:05 +0800 Subject: [PATCH 2/2] =?UTF-8?q?update=E4=BA=86UrlCheck=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 19 ++++- .../lovenav/controller/BannersController.java | 1 - .../lovenav/controller/CommentController.java | 9 --- src/main/java/com/lovenav/dao/BannersDao.java | 2 +- src/main/java/com/lovenav/dao/CommentDao.java | 2 +- src/main/java/com/lovenav/entity/Banners.java | 3 - .../serviceImpl/BannersServiceImpl.java | 5 +- .../serviceImpl/CommentServiceImpl.java | 5 +- .../java/com/lovenav/utils/UrlCheckUtil.java | 74 +++++++++++++++++++ src/main/resources/mybatis/BannersDao.xml | 3 +- src/main/resources/mybatis/CommentDao.xml | 2 +- 11 files changed, 100 insertions(+), 25 deletions(-) create mode 100644 src/main/java/com/lovenav/utils/UrlCheckUtil.java 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