Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -201,26 +201,20 @@ public class UserDao {
|
|||||||
Connection conn = null;
|
Connection conn = null;
|
||||||
PreparedStatement preparedStatement = null;
|
PreparedStatement preparedStatement = null;
|
||||||
ResultSet rs = 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;
|
int Value = 0;
|
||||||
try{
|
try{
|
||||||
conn = JdbcUtils.getConnection();
|
conn = JdbcUtils.getConnection();
|
||||||
preparedStatement = conn.prepareStatement(sql);
|
preparedStatement = conn.prepareStatement(sql);
|
||||||
preparedStatement.setString(1, name);
|
preparedStatement.setString(1, name);
|
||||||
rs = preparedStatement.executeQuery();
|
rs = preparedStatement.executeQuery();
|
||||||
if(rs.next()){
|
|
||||||
while(rs.next()){
|
while(rs.next()){
|
||||||
int projectNum = rs.getInt(6);
|
Value = rs.getInt(8);
|
||||||
Value = Value+projectNum;
|
}return Value;
|
||||||
Value++;
|
|
||||||
}
|
|
||||||
return Value;
|
|
||||||
}else{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return 0;
|
|
||||||
}finally {
|
}finally {
|
||||||
try{
|
try{
|
||||||
conn.close();
|
conn.close();
|
||||||
@@ -229,7 +223,7 @@ public class UserDao {
|
|||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}return Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int addLabel(String username,String str){
|
public int addLabel(String username,String str){
|
||||||
@@ -283,4 +277,5 @@ public class UserDao {
|
|||||||
|
|
||||||
return label;
|
return label;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,8 +1,11 @@
|
|||||||
package com.hellogithub.servlet;
|
package com.hellogithub.servlet;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.hellogithub.dao.UserDao;
|
||||||
|
import com.hellogithub.entity.articleEntity;
|
||||||
import com.hellogithub.entity.userEntity;
|
import com.hellogithub.entity.userEntity;
|
||||||
import com.hellogithub.service.UserService;
|
import com.hellogithub.service.UserService;
|
||||||
|
import com.hellogithub.service.articleService;
|
||||||
import jakarta.servlet.ServletException;
|
import jakarta.servlet.ServletException;
|
||||||
import jakarta.servlet.annotation.WebServlet;
|
import jakarta.servlet.annotation.WebServlet;
|
||||||
import jakarta.servlet.http.HttpServlet;
|
import jakarta.servlet.http.HttpServlet;
|
||||||
@@ -12,11 +15,14 @@ import jakarta.servlet.http.HttpSession;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@WebServlet("/contributionValue")
|
@WebServlet("/contributionValue")
|
||||||
public class contributionValueSevlet extends HttpServlet {
|
public class contributionValueSevlet extends HttpServlet {
|
||||||
private UserService userService = new UserService();
|
protected UserService userService = new UserService();
|
||||||
@Override
|
@Override
|
||||||
|
|
||||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||||
doPost(req, resp);
|
doPost(req, resp);
|
||||||
}
|
}
|
||||||
@@ -34,13 +40,27 @@ public class contributionValueSevlet extends HttpServlet {
|
|||||||
resp.setContentType("application/json;charset=UTF-8");
|
resp.setContentType("application/json;charset=UTF-8");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PrintWriter writer = resp.getWriter();
|
PrintWriter writer = resp.getWriter();
|
||||||
HttpSession session = req.getSession();
|
HttpSession session = req.getSession();
|
||||||
userEntity user = (userEntity)session.getAttribute("user");
|
userEntity user = (userEntity)session.getAttribute("user");
|
||||||
String userName = user.getUserName();
|
if(user == null){
|
||||||
int Value = userService.contributionValueReturn(userName);
|
setResultError("用户暂未登录", writer);
|
||||||
writer.println(Value);
|
}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();
|
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();
|
PrintWriter writer = resp.getWriter();
|
||||||
HttpSession session = req.getSession();
|
HttpSession session = req.getSession();
|
||||||
userEntity userEntity=(userEntity)session.getAttribute("user");
|
userEntity userEntity=(userEntity)session.getAttribute("user");
|
||||||
String name = userEntity.getUserName();
|
if(userEntity == null){
|
||||||
String jsonString = JSONObject.toJSONString(userService.selectLabel(name));
|
setResultError("用户暂未登录", writer);
|
||||||
writer.println(jsonString);
|
}else{
|
||||||
|
String name = userEntity.getUserName();
|
||||||
|
String jsonString = JSONObject.toJSONString(userService.selectLabel(name));
|
||||||
|
writer.println(jsonString);
|
||||||
|
}
|
||||||
// setResultOK("success",writer);
|
// setResultOK("success",writer);
|
||||||
writer.close();
|
writer.close();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user