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

封装data和size

上级 f9f70a80
......@@ -19,7 +19,6 @@ public class CommonResult<T> {
* 数据封装
*/
private T data;
private int size;
protected CommonResult() {
}
......@@ -30,12 +29,6 @@ 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;
}
/**
* 成功返回结果
......@@ -56,9 +49,6 @@ 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);
}
/**
* 失败返回结果
......@@ -153,11 +143,4 @@ public class CommonResult<T> {
this.data = data;
}
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
}
......@@ -15,7 +15,6 @@ import java.util.List;
* @Author wlj
*/
@RestController
@CrossOrigin(origins = "*")
public class CollectionListController {
@Autowired
CollectionListService collectionListService;
......
......@@ -13,7 +13,6 @@ import org.springframework.web.bind.annotation.*;
*/
@RestController
@CrossOrigin(origins = "*")
public class MajorController {
@Autowired
MajorService majorService;
......
......@@ -14,7 +14,6 @@ import org.springframework.web.bind.annotation.*;
* @Author wlj
*/
@RestController
@CrossOrigin(origins = "*")
public class MyInfoController {
@Autowired
PostService postService;
......
......@@ -22,7 +22,6 @@ import java.util.Map;
* @date 2022/4/28 20:43
*/
@RestController
@CrossOrigin(origins = "*")
public class PostController {
@Autowired
PostService postService;
......
......@@ -4,6 +4,7 @@ import com.nav.common.api.CommonResult;
import com.nav.dao.CommentDao;
import com.nav.dao.PostDao;
import com.nav.pojo.Comment;
import com.nav.utils.PackageUtils;
import com.nav.vo.result.LifePostResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -51,7 +52,8 @@ public class PostServiceImpl implements PostService{
@Override
public CommonResult getCommentByPostId(long id) {
List<Comment> commentList=commentDao.selectCommentByPostId(id);
return CommonResult.success(commentList,commentList.size(),"请求成功");
PackageUtils<List<Comment>> packageUtils=new PackageUtils<List<Comment>>(commentList.size(),commentList);
return CommonResult.success(packageUtils,"请求成功");
}
@Override
......
package com.nav.utils;
/**
* 类说明
* 封装data和size
* @author zyx
* @date 2022/5/1 10:42
*/
public class PackageUtils<T> {
private int size;
private T data;
public PackageUtils(int size, T data) {
this.size=size;
this.data = data;
}
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册