更改用户主页查询逻辑
This commit is contained in:
59
src/com/hellogithub/dao/supportDao.java
Normal file
59
src/com/hellogithub/dao/supportDao.java
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
package com.hellogithub.dao;
|
||||||
|
|
||||||
|
import com.hellogithub.entity.projectEntity;
|
||||||
|
import com.hellogithub.entity.supportEntity;
|
||||||
|
import com.hellogithub.utils.JdbcUtils;
|
||||||
|
import org.apache.commons.dbutils.QueryRunner;
|
||||||
|
import org.apache.commons.dbutils.handlers.BeanHandler;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
public class supportDao {
|
||||||
|
public supportEntity selectSupport(int userId,int projectId)
|
||||||
|
{
|
||||||
|
int num;
|
||||||
|
supportEntity supportEntity =null;
|
||||||
|
try{
|
||||||
|
Connection conn = JdbcUtils.getConnection();
|
||||||
|
QueryRunner runner = new QueryRunner();
|
||||||
|
String sql = "select * from support where isValid = 1 and userId = ? and projectId = ?";
|
||||||
|
supportEntity = runner.query(conn, sql,new BeanHandler<>(supportEntity.class) , userId,projectId);
|
||||||
|
conn.close();
|
||||||
|
}catch (SQLException e){
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return supportEntity;
|
||||||
|
}
|
||||||
|
public int insertSupport(int userId,int projectId)
|
||||||
|
{
|
||||||
|
int num;
|
||||||
|
try{
|
||||||
|
Connection conn = JdbcUtils.getConnection();
|
||||||
|
QueryRunner runner = new QueryRunner();
|
||||||
|
String sql = "insert into support (userId,projectId,isValid) VALUES (?,?,1) ";
|
||||||
|
num = runner.update(conn, sql, userId,projectId);
|
||||||
|
conn.close();
|
||||||
|
}catch (SQLException e){
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return num;
|
||||||
|
}
|
||||||
|
public int deleteSupport(int userId,int projectId)
|
||||||
|
{
|
||||||
|
int num;
|
||||||
|
try{
|
||||||
|
Connection conn = JdbcUtils.getConnection();
|
||||||
|
QueryRunner runner = new QueryRunner();
|
||||||
|
String sql = "delete from support where isValid = 1 and userId = ? and projectId =?";
|
||||||
|
num = runner.update(conn, sql , userId,projectId);
|
||||||
|
conn.close();
|
||||||
|
}catch (SQLException e){
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return num;
|
||||||
|
}
|
||||||
|
}
|
41
src/com/hellogithub/entity/supportEntity.java
Normal file
41
src/com/hellogithub/entity/supportEntity.java
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
package com.hellogithub.entity;
|
||||||
|
|
||||||
|
public class supportEntity {
|
||||||
|
int userId;
|
||||||
|
int projectId;
|
||||||
|
int isValid;
|
||||||
|
|
||||||
|
int id;
|
||||||
|
|
||||||
|
public int getUserId() {
|
||||||
|
return userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserId(int userId) {
|
||||||
|
this.userId = userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getProjectId() {
|
||||||
|
return projectId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProjectId(int projectId) {
|
||||||
|
this.projectId = projectId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getIsValid() {
|
||||||
|
return isValid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsValid(int isValid) {
|
||||||
|
this.isValid = isValid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
}
|
49
src/com/hellogithub/service/supprotService.java
Normal file
49
src/com/hellogithub/service/supprotService.java
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
package com.hellogithub.service;
|
||||||
|
|
||||||
|
import com.hellogithub.dao.supportDao;
|
||||||
|
import com.hellogithub.entity.supportEntity;
|
||||||
|
|
||||||
|
public class supprotService {
|
||||||
|
private supportDao supportDao = new supportDao();
|
||||||
|
|
||||||
|
public int retNum(int userId,int projectId){
|
||||||
|
int num ;
|
||||||
|
supportEntity supportEntity = supportDao.selectSupport(userId,projectId);
|
||||||
|
if(supportEntity == null)
|
||||||
|
{
|
||||||
|
num =0;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
num = 1;
|
||||||
|
}
|
||||||
|
return num ;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String insertSupport(int userId , int projectId)
|
||||||
|
{
|
||||||
|
String tip;
|
||||||
|
int num = supportDao.insertSupport(userId,projectId);
|
||||||
|
if(num == 1)
|
||||||
|
{
|
||||||
|
tip="点赞成功";
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
tip="点赞失败";
|
||||||
|
}
|
||||||
|
return tip;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String deleteSupport(int userId , int projectId)
|
||||||
|
{
|
||||||
|
String tip;
|
||||||
|
int num = supportDao.deleteSupport(userId,projectId);
|
||||||
|
if(num == 1)
|
||||||
|
{
|
||||||
|
tip="删除成功";
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
tip="删除失败";
|
||||||
|
}
|
||||||
|
return tip;
|
||||||
|
}
|
||||||
|
}
|
@@ -47,20 +47,21 @@ public class userDetailServlet 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();
|
String jsonString="";
|
||||||
userEntity userEntity=(userEntity)session.getAttribute("user");
|
String username = req.getParameter("username");
|
||||||
if(userEntity == null){
|
jsonString = JSONObject.toJSONString(userService.selectUserByName(username));
|
||||||
setResultError("用户暂未登录", writer);
|
if(jsonString.equals(""))
|
||||||
|
{
|
||||||
|
setResultError("查询失败",writer);
|
||||||
}else{
|
}else{
|
||||||
String name = userEntity.getUserName();
|
|
||||||
Map<String,String> dataMap= new HashMap<>();
|
Map<String,String> dataMap= new HashMap<>();
|
||||||
int id = userService.selectIdByName(name);
|
int id = userService.selectIdByName(username);
|
||||||
dataMap.put("comment",commentService.selectByUserId(id));
|
dataMap.put("comment",commentService.selectByUserId(id));
|
||||||
dataMap.put("project",projectService.retProjectByUserId(id));
|
dataMap.put("project",projectService.retProjectByUserId(id));
|
||||||
String jsonString = JSONObject.toJSONString(dataMap);
|
jsonString = JSONObject.toJSONString(dataMap);
|
||||||
writer.println(jsonString);
|
writer.println(jsonString);
|
||||||
|
setResultOK("查询失败",writer);
|
||||||
}
|
}
|
||||||
writer.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setResult(Integer code, String msg, PrintWriter writer) {
|
public void setResult(Integer code, String msg, PrintWriter writer) {
|
||||||
|
Reference in New Issue
Block a user