update了UrlCheck工具类
This commit is contained in:
parent
32ec34633c
commit
1b4bf28371
19
pom.xml
19
pom.xml
@ -106,13 +106,30 @@
|
||||
<artifactId>javase</artifactId>
|
||||
<version>3.3.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.ws.commons.axiom</groupId>
|
||||
<artifactId>base64-utils</artifactId>
|
||||
<version>1.4.0</version>
|
||||
</dependency>
|
||||
|
||||
<!--检测URl依赖-->
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>4.5.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpcore</artifactId>
|
||||
<version>4.4.14</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<version>1.2</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- jackson 2.x 相关依赖 -->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
|
@ -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;
|
||||
|
@ -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")
|
||||
|
@ -21,5 +21,5 @@ public interface BannersDao {
|
||||
|
||||
int updateByPrimaryKey(Banners record);
|
||||
|
||||
List<Banners> selectByAllBanners();
|
||||
List<Banners> selectAllBanners();
|
||||
}
|
@ -22,7 +22,7 @@ public interface CommentDao {
|
||||
|
||||
int updateByPrimaryKey(Comment record);
|
||||
|
||||
List<Comment> selectByAllComment();
|
||||
List<Comment> selectAllComment();
|
||||
|
||||
List<Comment> selectByAllReply(int id);
|
||||
}
|
@ -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;
|
||||
|
||||
/**
|
||||
|
@ -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<Banners> list = bannersDao.selectByAllBanners();
|
||||
List<Banners> list = bannersDao.selectAllBanners();
|
||||
return JSON.toJSONString(list);
|
||||
}
|
||||
}
|
||||
|
@ -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<Comment> list = commentDao.selectByAllComment();
|
||||
List<Comment> list = commentDao.selectAllComment();
|
||||
return JSON.toJSONString(list);
|
||||
}
|
||||
|
||||
|
74
src/main/java/com/lovenav/utils/UrlCheckUtil.java
Normal file
74
src/main/java/com/lovenav/utils/UrlCheckUtil.java
Normal file
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -97,10 +97,11 @@
|
||||
</update>
|
||||
|
||||
|
||||
<select id="selectByAllBanners" parameterType="java.lang.Integer" resultMap="BaseResultMap">
|
||||
<select id="selectAllBanners" parameterType="java.lang.Integer" resultMap="BaseResultMap">
|
||||
select
|
||||
*
|
||||
from ln_banners
|
||||
where banner_status = 0;
|
||||
</select>
|
||||
|
||||
</mapper>
|
@ -146,7 +146,7 @@
|
||||
</update>
|
||||
|
||||
|
||||
<select id="selectByAllComment" parameterType="java.lang.Integer" resultMap="BaseResultMap">
|
||||
<select id="selectAllComment" parameterType="java.lang.Integer" resultMap="BaseResultMap">
|
||||
select
|
||||
*
|
||||
from ln_comment
|
||||
|
Loading…
Reference in New Issue
Block a user