增加用户查看点赞项目
This commit is contained in:
@@ -5,9 +5,12 @@ import com.hellogithub.entity.supportEntity;
|
||||
import com.hellogithub.utils.JdbcUtils;
|
||||
import org.apache.commons.dbutils.QueryRunner;
|
||||
import org.apache.commons.dbutils.handlers.BeanHandler;
|
||||
import org.apache.commons.dbutils.handlers.BeanListHandler;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class supportDao {
|
||||
public supportEntity selectSupport(int userId,int projectId)
|
||||
@@ -56,4 +59,20 @@ public class supportDao {
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
public List<supportEntity> selectProject(int userId)
|
||||
{
|
||||
List<supportEntity> supportEntityList =new ArrayList<>();
|
||||
try{
|
||||
Connection conn = JdbcUtils.getConnection();
|
||||
QueryRunner runner = new QueryRunner();
|
||||
String sql = "select * from support where isValid = 1 and userId = ?";
|
||||
supportEntityList = runner.query(conn, sql,new BeanListHandler<>(supportEntity.class) , userId);
|
||||
conn.close();
|
||||
}catch (SQLException e){
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return supportEntityList;
|
||||
}
|
||||
}
|
||||
|
@@ -5,8 +5,10 @@ import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.hellogithub.dao.categoryDao;
|
||||
import com.hellogithub.dao.projectDao;
|
||||
import com.hellogithub.dao.supportDao;
|
||||
import com.hellogithub.entity.categoryEntity;
|
||||
import com.hellogithub.entity.projectEntity;
|
||||
import com.hellogithub.entity.supportEntity;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -16,6 +18,8 @@ public class projectService {
|
||||
|
||||
private projectDao projectDao = new projectDao();
|
||||
private categoryDao categoryDao = new categoryDao();
|
||||
|
||||
private supportDao supportDao = new supportDao();
|
||||
/**
|
||||
* 按照期刊号查询
|
||||
*/
|
||||
@@ -186,5 +190,19 @@ public class projectService {
|
||||
}
|
||||
return JSONObject.toJSONString(projectEntityList);
|
||||
}
|
||||
public String retProBySupport(int userId)
|
||||
{
|
||||
List<supportEntity> supportEntityList = supportDao.selectProject(userId);
|
||||
List<projectEntity> projectEntityList = new ArrayList<>();
|
||||
for(int i=0;i<supportEntityList.size();i++)
|
||||
{
|
||||
supportEntity supportEntity =supportEntityList.get(i);
|
||||
projectEntity projectEntity = projectDao.selectProById(String.valueOf(supportEntity.getProjectId()));
|
||||
categoryEntity categoryEntity = categoryDao.retNum(projectEntity.getCategoryId());
|
||||
projectEntity.setCategoryName(categoryEntity.getCategoryName());
|
||||
projectEntityList.add(projectEntity);
|
||||
}
|
||||
return JSONObject.toJSONString(projectEntityList);
|
||||
}
|
||||
|
||||
}
|
@@ -58,6 +58,7 @@ public class userDetailServlet extends HttpServlet {
|
||||
int id = userService.selectIdByName(username);
|
||||
dataMap.put("comment",commentService.selectByUserId(id));
|
||||
dataMap.put("project",projectService.retProjectByUserId(id));
|
||||
dataMap.put("like",projectService.retProBySupport(id));
|
||||
jsonString = JSONObject.toJSONString(dataMap);
|
||||
writer.println(jsonString);
|
||||
writer.close();
|
||||
|
Reference in New Issue
Block a user