Function的使用场景如下所示:
public class ApiInvoke<R> { private Logger logger = LoggerFactory.getLogger(getClass()); public <T> Map invoke(Map map, Class<T> tClass, Function<T, R> function) { return invokeWithoutException(map, tClass, function); } private <T> Map invokeWithoutException(Map map, Class<T> tClass, Function<T, R> function) { // map转化为vo T t = null; if (tClass != null) { t = JSON.toJavaObject((JSON) JSONObject.toJSON(map), tClass); } R result = function.apply(t); // 调用结果转化为map Map resultMap = JSON.parseObject(JSON.toJSONString(result, SerializerFeature.WRITE_MAP_NULL_FEATURES), Map.class); return resultMap; } }
可以记录接口调用日志,转化一些信息。
标签:Function,Map,场景,map,function,JSON,使用,tClass From: https://www.cnblogs.com/jelly12345/p/17333537.html