package com.dg.core.controller;
|
|
import com.dg.core.HttpStatus;
|
import com.dg.core.ResultData;
|
import com.dg.core.util.TableDataInfo;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
|
/**
|
* web层通用数据处理
|
*
|
* @author ruoyi
|
*/
|
public class BaseController
|
{
|
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
|
/**
|
* 响应请求分页数据
|
*/
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
protected TableDataInfo getDataTable(List<?> list)
|
{
|
TableDataInfo rspData = new TableDataInfo();
|
rspData.setResult(HttpStatus.SUCCESS);
|
rspData.setMsg("查询成功");
|
if(list!=null)
|
{
|
rspData.setRows(list);
|
// rspData.setTotal(new PageInfo(list).getTotal());
|
}
|
else
|
{
|
rspData.setRows(new ArrayList<>());
|
rspData.setTotal(0);
|
}
|
return rspData;
|
}
|
|
/**
|
* 响应请求分页数据
|
*/
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
protected TableDataInfo getDataTable(List<?> list,long num)
|
{
|
TableDataInfo rspData = new TableDataInfo();
|
rspData.setResult(HttpStatus.SUCCESS);
|
rspData.setMsg("查询成功");
|
rspData.setRows(list);
|
rspData.setTotal(num);
|
return rspData;
|
}
|
|
|
/**
|
* 响应请求分页数据 报错内容
|
*/
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
protected TableDataInfo getDataTable(String msg)
|
{
|
TableDataInfo rspData = new TableDataInfo();
|
rspData.setResult(HttpStatus.ERROR);
|
rspData.setMsg(msg);
|
rspData.setRows(new ArrayList<>());
|
rspData.setTotal(0);
|
return rspData;
|
}
|
|
/**
|
* 返回成功
|
* <T> ResultData<T> success(T data) {
|
*/
|
public ResultData success()
|
{
|
return ResultData.success();
|
}
|
|
|
/**
|
* 返回失败消息
|
*/
|
public ResultData error()
|
{
|
return ResultData.error();
|
}
|
|
/**
|
* 返回成功消息
|
*/
|
public ResultData success(String message)
|
{
|
return ResultData.success(message);
|
}
|
|
/**
|
* 返回失败消息
|
*/
|
public ResultData error(String message)
|
{
|
return ResultData.error(message);
|
}
|
|
/**
|
* 响应返回结果
|
*
|
* @param rows 影响行数
|
* @return 操作结果
|
*/
|
protected ResultData toAjax(int rows)
|
{
|
return rows > 0 ? ResultData.success() : ResultData.error();
|
}
|
|
/**
|
* 响应返回结果
|
*
|
* @param result 结果
|
* @return 操作结果
|
*/
|
protected ResultData toAjax(boolean result)
|
{
|
return result ? success() : error();
|
}
|
|
}
|