ResultVo<T>返回结果类

package com.yzx.operateplatform.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModelProperty;

/**
 * @author yuanshushu
 * @date 2018/8/29
 * @description 返回结果VO对象
 */
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ResultVO<T> {

    @ApiModelProperty("状态码 0失败 1成功 2未登录 3没有权限")
    private Integer code;

    @ApiModelProperty("返回信息")
    private String msg;

    @ApiModelProperty("返回数据")
    private T data;

    public ResultVO(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public ResultVO(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    /**
     * 请求成功  状态码 1
     *
     * @param msg 返回信息
     * @param <T> 类型
     * @return ResultVO
     */
    public static <T> ResultVO getSuccess(String msg) {
        return new ResultVO(1, msg);
    }

    /**
     * 请求成功  状态码 1
     *
     * @param msg  返回信息
     * @param data 返回对象
     * @param <T>  类型
     * @return ResultVO
     */
    public static <T> ResultVO getSuccess(String msg, T data) {
        return new ResultVO(1, msg, data);
    }

    /**
     * 请求失败   状态码 0
     *
     * @param msg 返回信息
     * @param <T> 类型
     * @return ResultVO
     */
    public static <T> ResultVO getFailed(String msg) {
        return new ResultVO(0, msg);
    }

    /**
     * 请求失败  状态 0
     *
     * @param msg  返回信息
     * @param data 返回数据
     * @param <T>  类型
     * @return ResultVO
     */
    public static <T> ResultVO getFailed(String msg, T data) {
        return new ResultVO(0, msg, data);
    }


    /**
     * 用户未登录
     *
     * @param <T> 类型
     * @return ResultVO
     */
    public static <T> ResultVO getNoLogin() {
        return new ResultVO(2, "用户未登录,请重新登录");
    }


    /**
     * 用户没有操作权限
     *
     * @param <T> 类型
     * @return ResultVO
     */
    public static <T> ResultVO getNoAuthorization() {
        return new ResultVO(3, "用户没有操作权限,请重新登录");
    }


    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}

使用

controller

@ApiOperation(value = "获取看房记录分页列表")
	@PostMapping("/page")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "currentPage", paramType = "query", dataType = "Long", value = "当前页码 必须", required = false),
			@ApiImplicitParam(name = "pageSize", paramType = "query", dataType = "Long", value = "分页大小 必须", required = false),
			@ApiImplicitParam(name = "renterId", paramType = "query", dataType = "String", value = "租客ID 必须 例:aaaaa0002", required = false) }) 
	public ResultVO<ReturnPaging> selectLookRoomPage(String lookRoomRecordVo) {  

		try {
			return this.lookRoomService.selectLookRoomPage(JSON.parseObject(lookRoomRecordVo, LookRoomRecordVo.class));
		} catch (Exception e) {  
			e.printStackTrace();   
			return ResultVO.getFailed("查询看房记录分页列表失败");   
		}
	}

 

 

 

service

/**
	 * 看房记录分页列表
	 * 
	 * @param lookRoomRecordVo
	 *            <p>
	 *            currentPage 当前页<br>
	 *            pageSize 分页大小<br>
	 *            renterId 租客ID<br>
	 *            landlordId 房东ID<br>
	 *            </p>
	 * @return ResultVO<ReturnPaging>
	 */
	ResultVO<ReturnPaging> selectLookRoomPage(LookRoomRecordVo lookRoomRecordVo);

serviceImpl

@Override
	public ResultVO<ReturnPaging> selectLookRoomPage(LookRoomRecordVo lookRoomRecordVo) {

		PageHelper.startPage(lookRoomRecordVo.getCurrentPage(), lookRoomRecordVo.getPageSize());
		List<LookRoomRecordVo> lookRoomRecordList = this.LookRoomRecordMapper.selectLookRoomPage(lookRoomRecordVo);

		PageInfo<LookRoomRecordVo> pageInfo = new PageInfo<>(lookRoomRecordList); 
		ReturnPaging returnPaging = new ReturnPaging(); 
		returnPaging.setRecordsTotal((int) pageInfo.getTotal());  
		returnPaging.setPageSize(lookRoomRecordVo.getPageSize()); 
		returnPaging.setData(lookRoomRecordList); 

		return ResultVO.getSuccess("查询看房记录分页列表成功", returnPaging);
	}

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值