refactor: 首页修改 (#1651)

* refactor:首页修改

* refactor: 首页修改

Co-authored-by: wangjiahao <1522128093@qq.com>
This commit is contained in:
fit2cloudrd
2022-01-18 12:38:33 +08:00
committed by GitHub
parent e4f44bd2d4
commit 5e32cd9dde
18 changed files with 344 additions and 68 deletions

View File

@@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
@Api(tags = "首页")
@@ -24,7 +25,7 @@ public class ReptileController {
@GetMapping("lastActive")
@ApiOperation("获取官方Blog最新动态")
public Map<String, String> lastActive() {
public List lastActive() {
return reptileService.lastActive();
}
}

View File

@@ -7,8 +7,7 @@ import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;
import java.util.*;
/**
* Author: wangjiahao
@@ -18,27 +17,33 @@ import java.util.Map;
@Service
public class ReptileService {
String blogUrl = "https://blog.fit2cloud.com/?cat=321";
//获取最新的前几条数据
private static int infoCount=1;
public Map<String, String> lastActive() {
Map<String, String> result = new HashMap();
public List lastActive() {
List result = new ArrayList();
try {
//爬取最新数据
Document doc = Jsoup.parse(HttpClientUtil.get(blogUrl, null));
Elements elementsContent = doc.getElementsByAttributeValue("rel", "bookmark");
Elements elementsTime = doc.getElementsByTag("time");
Element lastInfo = elementsContent.get(0);
result.put("title",lastInfo.attr("title"));
result.put("href",lastInfo.attr("href"));
result.put("time",elementsTime.get(0).childNode(0).outerHtml());
for(int i = 0;i<infoCount;i++){
Element info = elementsContent.get(i*3);
Map<String, String> infoMap = new HashMap();
infoMap.put("title",info.attr("title"));
infoMap.put("href",info.attr("href"));
infoMap.put("time",elementsTime.get(i).childNode(0).outerHtml());
result.add(infoMap);
}
} catch (Exception e) {
//ignore
result.put("title","支持移动端展示数据源新增对DB2的支持DataEase开源数据可视化分析平台v1.6.0发布");
result.put("href","https://blog.fit2cloud.com/?p=3200");
result.put("time","2022年1月10日");
Map<String, String> infoMap = new HashMap();
infoMap.put("title","支持移动端展示数据源新增对DB2的支持DataEase开源数据可视化分析平台v1.6.0发布");
infoMap.put("href","https://blog.fit2cloud.com/?p=3200");
infoMap.put("time","2022年1月10日");
result.add(infoMap);
}
return result;
}