package com.sandu.common.util;
|
|
import com.sandu.common.domain.CommonPage;
|
import com.sandu.common.domain.ResponseVO;
|
import com.sandu.common.enums.ResponseStatusEnums;
|
import org.springframework.web.servlet.ModelAndView;
|
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* 接口返回工具类,支持ModelAndView、ResponseVO、PageResult
|
*
|
* @author chenjiantian
|
*/
|
public class ResponseUtil {
|
|
/**
|
* 返回 失败
|
*/
|
public static ResponseVO<Object> fail(String message) {
|
return new ResponseVO<>(ResponseStatusEnums.FAIL.getCode(), message, null);
|
}
|
|
/**
|
* 返回 成功
|
*/
|
public static ResponseVO<Object> success(Object data) {
|
return new ResponseVO<>(ResponseStatusEnums.SUCCESS.getCode(), ResponseStatusEnums.SUCCESS.getMessage(), data);
|
}
|
|
/**
|
* 返回 分页成功
|
*/
|
public static ResponseVO<Object> successPage(List<?> list) {
|
return success(CommonPage.restPage(list));
|
}
|
|
|
public static ModelAndView view(String view) {
|
return new ModelAndView(view);
|
}
|
|
public static ModelAndView view(String view, Map<String, Object> model) {
|
return new ModelAndView(view, model);
|
}
|
|
public static ModelAndView redirect(String view) {
|
return new ModelAndView("redirect:" + view);
|
}
|
|
public static ModelAndView forward(String view) {
|
return new ModelAndView("forward:" + view);
|
}
|
|
public static ResponseVO<Object> error(int code, String message) {
|
return new ResponseVO<>(code, message, null);
|
}
|
|
public static ResponseVO<Object> error(int code, String message, Object data) {
|
return new ResponseVO<>(code, message, data);
|
}
|
|
public static ResponseVO<Object> error(int code, String message, Object data, String exception) {
|
return new ResponseVO<>(code, message, data, exception);
|
}
|
|
|
}
|