完善贡献值和搜索用户标签的“未登录”状态
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
package com.hellogithub.servlet;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.hellogithub.dao.UserDao;
|
||||
import com.hellogithub.entity.articleEntity;
|
||||
import com.hellogithub.entity.userEntity;
|
||||
import com.hellogithub.service.UserService;
|
||||
import com.hellogithub.service.articleService;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.annotation.WebServlet;
|
||||
import jakarta.servlet.http.HttpServlet;
|
||||
@@ -12,11 +15,14 @@ import jakarta.servlet.http.HttpSession;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
@WebServlet("/contributionValue")
|
||||
public class contributionValueSevlet extends HttpServlet {
|
||||
private UserService userService = new UserService();
|
||||
protected UserService userService = new UserService();
|
||||
@Override
|
||||
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
doPost(req, resp);
|
||||
}
|
||||
@@ -34,13 +40,27 @@ public class contributionValueSevlet extends HttpServlet {
|
||||
resp.setContentType("application/json;charset=UTF-8");
|
||||
|
||||
|
||||
|
||||
PrintWriter writer = resp.getWriter();
|
||||
HttpSession session = req.getSession();
|
||||
userEntity user = (userEntity)session.getAttribute("user");
|
||||
String userName = user.getUserName();
|
||||
int Value = userService.contributionValueReturn(userName);
|
||||
writer.println(Value);
|
||||
if(user == null){
|
||||
setResultError("用户暂未登录", writer);
|
||||
}else{
|
||||
String userName = user.getUserName();
|
||||
int Value = userService.contributionValueReturn(userName);
|
||||
writer.println(Value);
|
||||
}
|
||||
writer.close();
|
||||
}
|
||||
public void setResult(Integer code, String msg, PrintWriter writer) {
|
||||
HashMap<String, Object> 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);
|
||||
}
|
||||
}
|
||||
|
@@ -35,9 +35,13 @@ public class selectUserLabelServlet extends HttpServlet {
|
||||
PrintWriter writer = resp.getWriter();
|
||||
HttpSession session = req.getSession();
|
||||
userEntity userEntity=(userEntity)session.getAttribute("user");
|
||||
String name = userEntity.getUserName();
|
||||
String jsonString = JSONObject.toJSONString(userService.selectLabel(name));
|
||||
writer.println(jsonString);
|
||||
if(userEntity == null){
|
||||
setResultError("用户暂未登录", writer);
|
||||
}else{
|
||||
String name = userEntity.getUserName();
|
||||
String jsonString = JSONObject.toJSONString(userService.selectLabel(name));
|
||||
writer.println(jsonString);
|
||||
}
|
||||
// setResultOK("success",writer);
|
||||
writer.close();
|
||||
|
||||
|
Reference in New Issue
Block a user