个人主页显示发布文章
This commit is contained in:
@@ -171,4 +171,39 @@ public class articleDao {
|
|||||||
}
|
}
|
||||||
return bool;
|
return bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<articleEntity> SelectByUserid(int userId){
|
||||||
|
Connection conn = null;
|
||||||
|
PreparedStatement preparedStatement = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
String sql = "SELECT * FROM `article` where userId = ? AND isValid = 1;";
|
||||||
|
ArrayList<com.hellogithub.entity.articleEntity> articleEntities = new ArrayList<articleEntity>();
|
||||||
|
try {
|
||||||
|
conn = JdbcUtils.getConnection();
|
||||||
|
preparedStatement = conn.prepareStatement(sql);
|
||||||
|
preparedStatement.setInt(1, userId);
|
||||||
|
rs = preparedStatement.executeQuery();
|
||||||
|
while (rs.next()) {
|
||||||
|
int articleid = rs.getInt(1);
|
||||||
|
int userid = rs.getInt(2);
|
||||||
|
String articlecontent = rs.getString(3);
|
||||||
|
String datetime = rs.getString(4);
|
||||||
|
int isvalid = rs.getInt(5);
|
||||||
|
int readcount = rs.getInt(6);
|
||||||
|
String articleTitle = rs.getString(7);
|
||||||
|
String articleIco = rs.getString(8);
|
||||||
|
articleEntity entity = new articleEntity(articleid, userid, articlecontent, datetime, isvalid, readcount,articleTitle,articleIco);
|
||||||
|
articleEntities.add(entity);
|
||||||
|
}
|
||||||
|
return articleEntities;
|
||||||
|
}catch(Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}finally{
|
||||||
|
try{
|
||||||
|
JdbcUtils.closeConnection(rs,preparedStatement, conn);
|
||||||
|
}catch(Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}return articleEntities;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -39,36 +39,6 @@ public class articleService {
|
|||||||
return JSONObject.toJSONString(dataMap1);
|
return JSONObject.toJSONString(dataMap1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String ArticleSortBylast(int userid){
|
|
||||||
List<articleEntity> articleEntityList =articleDao.ArticleSortBylast();
|
|
||||||
List<articleEntity> articleEntityList1=new ArrayList<>();
|
|
||||||
Map<String,Object> dataMap;
|
|
||||||
Map<String,Map<String,Object>> dataMap1 = new HashMap<>();
|
|
||||||
for(int i=0;i<articleEntityList.size();i++)
|
|
||||||
{
|
|
||||||
dataMap = new HashMap<>();
|
|
||||||
articleEntity articleEntity = articleEntityList.get(i);
|
|
||||||
int id = articleEntity.getUserId();
|
|
||||||
int a = 0;
|
|
||||||
if(id == userid){
|
|
||||||
String username = userDao.selectNameById(id);
|
|
||||||
dataMap.put("ArticleContent",articleEntity.getArticleContent());
|
|
||||||
dataMap.put("ArticleId",articleEntity.getArticleId());
|
|
||||||
dataMap.put("ArticleTitle",articleEntity.getArticleTitle());
|
|
||||||
dataMap.put("IsValid",articleEntity.getIsValid());
|
|
||||||
dataMap.put("ReadCount",articleEntity.getReadCount());
|
|
||||||
dataMap.put("username",username);
|
|
||||||
dataMap.put("publishtime",articleEntity.getPublishTime());
|
|
||||||
dataMap.put("articleico",articleEntity.getArticleIco());
|
|
||||||
dataMap1.put(a+"", dataMap);
|
|
||||||
articleEntityList1.add(articleEntity);
|
|
||||||
a++;
|
|
||||||
}else{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return JSONObject.toJSONString(dataMap1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String ArticleSortByhot(){
|
public String ArticleSortByhot(){
|
||||||
|
|
||||||
@@ -117,4 +87,28 @@ public class articleService {
|
|||||||
return bool;
|
return bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String SelectByUserid(int userId){
|
||||||
|
List<articleEntity> articleEntityList =articleDao.SelectByUserid(userId);
|
||||||
|
List<articleEntity> articleEntityList1=new ArrayList<>();
|
||||||
|
Map<String,Object> dataMap;
|
||||||
|
Map<String,Map<String,Object>> dataMap1 = new HashMap<>();
|
||||||
|
for(int i=0;i<articleEntityList.size();i++)
|
||||||
|
{
|
||||||
|
dataMap = new HashMap<>();
|
||||||
|
articleEntity articleEntity = articleEntityList.get(i);
|
||||||
|
int id = articleEntity.getUserId();
|
||||||
|
String username = userDao.selectNameById(id);
|
||||||
|
dataMap.put("ArticleContent",articleEntity.getArticleContent());
|
||||||
|
dataMap.put("ArticleId",articleEntity.getArticleId());
|
||||||
|
dataMap.put("ArticleTitle",articleEntity.getArticleTitle());
|
||||||
|
dataMap.put("IsValid",articleEntity.getIsValid());
|
||||||
|
dataMap.put("ReadCount",articleEntity.getReadCount());
|
||||||
|
dataMap.put("username",username);
|
||||||
|
dataMap.put("publishtime",articleEntity.getPublishTime());
|
||||||
|
dataMap.put("articleico",articleEntity.getArticleIco());
|
||||||
|
dataMap1.put(i+"", dataMap);
|
||||||
|
articleEntityList1.add(articleEntity);
|
||||||
|
}return JSONObject.toJSONString(dataMap1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -62,7 +62,7 @@ public class userDetailServlet extends HttpServlet {
|
|||||||
dataMap.put("comment",commentService.selectByUserId(id));
|
dataMap.put("comment",commentService.selectByUserId(id));
|
||||||
dataMap.put("project",projectService.retProjectByUserId(id));
|
dataMap.put("project",projectService.retProjectByUserId(id));
|
||||||
dataMap.put("like",projectService.retProBySupport(id));
|
dataMap.put("like",projectService.retProBySupport(id));
|
||||||
dataMap.put("article",articleService.ArticleSortBylast(id));
|
dataMap.put("article",articleService.SelectByUserid(id));
|
||||||
jsonString = JSONObject.toJSONString(dataMap);
|
jsonString = JSONObject.toJSONString(dataMap);
|
||||||
writer.println(jsonString);
|
writer.println(jsonString);
|
||||||
writer.close();
|
writer.close();
|
||||||
|
|||||||
Reference in New Issue
Block a user