增加平均星数

This commit is contained in:
cyk
2023-07-07 10:11:10 +08:00
parent c4dd18b0c0
commit f22e270b22
2 changed files with 5 additions and 1 deletions

View File

@@ -12,6 +12,7 @@ import com.hellogithub.entity.commentEntity;
import com.hellogithub.entity.projectEntity;
import com.hellogithub.entity.supportEntity;
import java.math.BigDecimal;
import java.util.*;
@@ -158,7 +159,9 @@ public class projectService {
sum +=commentEntityList.get(i).getStar();
}
double average = sum/commentEntityList.size();
projectEntity.setAverage(average);
BigDecimal two = new BigDecimal(average);
double three = two.setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue();
projectEntity.setAverage(three);
}
else{
projectEntity.setAverage(0);

View File

@@ -43,6 +43,7 @@ public class selectProByIdServlet extends HttpServlet {
int num = projectService.addProjectLookcount(id);
PrintWriter writer = resp.getWriter();
String dataMap = projectService.retProjectLabel(id);
JSONObject jsonObject = JSON.parseObject(dataMap);
jsonObject.put("project",projectService.selectProById(id));
writer.println(JSONObject.toJSONString(jsonObject));