修改评论

This commit is contained in:
cyk
2023-07-05 13:40:30 +08:00
parent 0814b4ad94
commit 223f979a0f
2 changed files with 19 additions and 2 deletions

View File

@@ -85,4 +85,14 @@ public class commentEntity {
public void setLikeNum(int likeCount) { public void setLikeNum(int likeCount) {
this.likeNum = likeCount; this.likeNum = likeCount;
} }
String username;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
} }

View File

@@ -6,6 +6,7 @@ import com.hellogithub.dao.UserDao;
import com.hellogithub.dao.commentDao; import com.hellogithub.dao.commentDao;
import com.hellogithub.entity.commentEntity; import com.hellogithub.entity.commentEntity;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -55,7 +56,7 @@ public class commentService {
public String selectByTrait(String id,String trait) public String selectByTrait(String id,String trait)
{ {
List<commentEntity> commentEntityList = commentDao.selectByTrait(id,trait); List<commentEntity> commentEntityList=new ArrayList<>();
if(trait.equals("last")) if(trait.equals("last"))
{ {
commentEntityList = commentDao.selectByTrait(id,"creatTime"); commentEntityList = commentDao.selectByTrait(id,"creatTime");
@@ -64,7 +65,13 @@ public class commentService {
{ {
commentEntityList = commentDao.selectByTrait(id,"likeNum"); commentEntityList = commentDao.selectByTrait(id,"likeNum");
} }
for(int i=0;i<commentEntityList.size();i++)
{
commentEntity commentEntity = commentEntityList.get(i);
int userid = commentEntity.getUserId();
String username = userDao.selectNameById(userid);
commentEntity.setUsername(username);
}
return JSONObject.toJSONString(commentEntityList); return JSONObject.toJSONString(commentEntityList);
} }
public String addLikeNum(int commentId){ public String addLikeNum(int commentId){