JAVA8-Supplier函数

xiaoxiao2021-02-28  79

主要说明常用方法真实场景

主要说明

Supplier<T> 无参数,返回一个结果。可以用来把service或controller层结果统一包装返回

常用方法

T get();无参数执行函数逻辑返回结果

真实场景

public interface ResultWrapper { default <T extends Serializable> CallResult<T> wrapper(Supplier<T> supplier, String desc) { try { T model = supplier.get(); return new CallResult<>(model); } catch (PandaException pe) { return new CallResult<>(pe.getCode(), pe.getMessage()); } catch (Exception e) { return new CallResult<>(ErrorCodeEnum.SYSTEM_ERROR.getErrorCode(), e.getMessage()); } } } 说明:实现该接口,调用default方法可以对返回结果进行统一的包装和异常处理。
转载请注明原文地址: https://www.6miu.com/read-78125.html

最新回复(0)