提交 f9f70a80 编写于 作者: LKJKJOIUIU's avatar LKJKJOIUIU

添加data的size

上级 d6d84c26
......@@ -19,6 +19,7 @@ public class CommonResult<T> {
* 数据封装
*/
private T data;
private int size;
protected CommonResult() {
}
......@@ -29,6 +30,13 @@ public class CommonResult<T> {
this.data = data;
}
protected CommonResult(long code, String message, int size, T data) {
this.code = code;
this.message = message;
this.data = data;
this.size=size;
}
/**
* 成功返回结果
*
......@@ -48,6 +56,10 @@ public class CommonResult<T> {
return new CommonResult<T>(ResultCode.SUCCESS.getCode(), message, data);
}
public static <T> CommonResult<T> success(T data,int size, String message) {
return new CommonResult<T>(ResultCode.SUCCESS.getCode(), message,size,data);
}
/**
* 失败返回结果
* @param errorCode 错误码
......@@ -140,4 +152,12 @@ public class CommonResult<T> {
public void setData(T data) {
this.data = data;
}
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
}
......@@ -53,12 +53,8 @@ public class PostController {
}
@GetMapping("comment/{id}")
public Map<Integer,CommonResult> getCommentByPostId(@PathVariable long id) {
Map<Integer,CommonResult> map=new HashMap<>();
CommonResult commonResult=postService.getCommentByPostId(id);
List<CommentResult> commentResult = (List<CommentResult>) commonResult.getData();
map.put(commentResult.size(),commonResult);
return map;
public CommonResult getCommentByPostId(@PathVariable long id) {
return postService.getCommentByPostId(id);
}
@GetMapping("lifePost/tag/{tag}")
......
......@@ -50,7 +50,8 @@ public class PostServiceImpl implements PostService{
@Override
public CommonResult getCommentByPostId(long id) {
return CommonResult.success(commentDao.selectCommentByPostId(id),"请求成功");
List<Comment> commentList=commentDao.selectCommentByPostId(id);
return CommonResult.success(commentList,commentList.size(),"请求成功");
}
@Override
......
package com.nav;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class NavApplicationTests {
@Test
void contextLoads() {
}
}
//package com.nav;
//
//import org.junit.jupiter.api.Test;
//import org.springframework.boot.test.context.SpringBootTest;
//
//@SpringBootTest
//class NavApplicationTests {
//
// @Test
// void contextLoads() {
// }
//
//}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册