fix: 空值异常

This commit is contained in:
禾几海
2020-08-15 16:00:05 +08:00
parent 6b77655c16
commit 40e1f4d6ab
2 changed files with 14 additions and 10 deletions

View File

@@ -12,11 +12,11 @@ import cn.celess.blog.service.PartnerSiteService;
import cn.celess.blog.util.HttpUtil; import cn.celess.blog.util.HttpUtil;
import cn.celess.blog.util.RedisUtil; import cn.celess.blog.util.RedisUtil;
import cn.celess.blog.util.RegexUtil; import cn.celess.blog.util.RegexUtil;
import com.alibaba.druid.util.StringUtils;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage; import org.springframework.mail.SimpleMailMessage;

View File

@@ -10,6 +10,7 @@ import cn.celess.blog.service.WebUpdateInfoService;
import cn.celess.blog.util.DateFormatUtil; import cn.celess.blog.util.DateFormatUtil;
import cn.celess.blog.util.HttpUtil; import cn.celess.blog.util.HttpUtil;
import cn.celess.blog.util.ModalTrans; import cn.celess.blog.util.ModalTrans;
import com.alibaba.druid.util.StringUtils;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
@@ -88,15 +89,18 @@ public class WebUpdateInfoServiceImpl implements WebUpdateInfoService {
map.put("lastUpdateInfo", webUpdateInfoMapper.getLastestOne().getUpdateInfo()); map.put("lastUpdateInfo", webUpdateInfoMapper.getLastestOne().getUpdateInfo());
try { try {
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
JsonNode root = mapper.readTree(HttpUtil.get("https://api.github.com/repos/xiaohai2271/blog-frontEnd/commits?page=1&per_page=1")); String respStr = HttpUtil.get("https://api.github.com/repos/xiaohai2271/blog-frontEnd/commits?page=1&per_page=1");
Iterator<JsonNode> elements = root.elements(); if (!StringUtils.isEmpty(respStr)) {
JsonNode next = elements.next(); JsonNode root = mapper.readTree(respStr);
JsonNode commit = next.get("commit"); Iterator<JsonNode> elements = root.elements();
map.put("lastCommit", commit.get("message")); JsonNode next = elements.next();
map.put("committerAuthor", commit.get("committer").get("name")); JsonNode commit = next.get("commit");
Instant parse = Instant.parse(commit.get("committer").get("date").asText()); map.put("lastCommit", commit.get("message"));
map.put("committerDate", DateFormatUtil.get(Date.from(parse))); map.put("committerAuthor", commit.get("committer").get("name"));
map.put("commitUrl", "https://github.com/xiaohai2271/blog-frontEnd/tree/" + next.get("sha").asText()); Instant parse = Instant.parse(commit.get("committer").get("date").asText());
map.put("committerDate", DateFormatUtil.get(Date.from(parse)));
map.put("commitUrl", "https://github.com/xiaohai2271/blog-frontEnd/tree/" + next.get("sha").asText());
}
} catch (IOException e) { } catch (IOException e) {
log.info("网络请求失败{}", e.getMessage()); log.info("网络请求失败{}", e.getMessage());
} }