Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -201,26 +201,20 @@ public class UserDao {
|
||||
Connection conn = null;
|
||||
PreparedStatement preparedStatement = null;
|
||||
ResultSet rs = null;
|
||||
String sql = "SELECT * FROM `user` t1,article t2 WHERE t1.userId = t2.userId AND t1.userId = ? and isValid = 1";
|
||||
String sql = "SELECT * FROM `user` WHERE userName = ? AND isValid = 1;";
|
||||
int Value = 0;
|
||||
try{
|
||||
conn = JdbcUtils.getConnection();
|
||||
preparedStatement = conn.prepareStatement(sql);
|
||||
preparedStatement.setString(1, name);
|
||||
rs = preparedStatement.executeQuery();
|
||||
if(rs.next()){
|
||||
while(rs.next()){
|
||||
int projectNum = rs.getInt(6);
|
||||
Value = Value+projectNum;
|
||||
Value++;
|
||||
}
|
||||
return Value;
|
||||
}else{
|
||||
return 0;
|
||||
}
|
||||
|
||||
while(rs.next()){
|
||||
Value = rs.getInt(8);
|
||||
}return Value;
|
||||
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
return 0;
|
||||
}finally {
|
||||
try{
|
||||
conn.close();
|
||||
@@ -229,7 +223,7 @@ public class UserDao {
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}return Value;
|
||||
}
|
||||
|
||||
public int addLabel(String username,String str){
|
||||
@@ -283,4 +277,5 @@ public class UserDao {
|
||||
|
||||
return label;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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