diff --git a/src/com/hellogithub/servlet/githubinfo/ret_Github_infoServlet.java b/src/com/hellogithub/servlet/githubinfo/ret_Github_infoServlet.java index 01a333d..768873c 100644 --- a/src/com/hellogithub/servlet/githubinfo/ret_Github_infoServlet.java +++ b/src/com/hellogithub/servlet/githubinfo/ret_Github_infoServlet.java @@ -35,7 +35,28 @@ public class ret_Github_infoServlet extends HttpServlet { PrintWriter writer = resp.getWriter(); String projectid = req.getParameter("projectId"); - writer.println(githubservice.ret_Github_info(Integer.parseInt(projectid))); + String json = githubservice.ret_Github_info(Integer.parseInt(projectid)); + if(json == null){ + setResultError("该信息未收录", writer); + }else{ + writer.println(json); + } writer.close(); } + public void setResult(Integer code, String msg, PrintWriter writer) { + HashMap result = new HashMap<>(); + result.put("code", code); + result.put("msg", msg); + String jsonString = JSONObject.toJSONString(result); + writer.println(jsonString); + writer.close(); + } + + public void setResultError(String msg, PrintWriter writer) { + setResult(500, msg, writer); + } + + public void setResultOK(String msg, PrintWriter writer) { + setResult(200, msg, writer); + } }