如何优雅的处理API接口的返回数据-----附源码( 二 )

> testList(){ ResponseDTO> result = ResponseDTO.success(); try { //业务代码 List data = studyService.testList(); result.setData(data); } catch (Exception e) { log.error("处理异常", e); result.setResult(false); result.setCode("500"); result.setMsg("异常"); } return result; }}service层源码:
package com.study.service;import java.util.List;import org.springframework.stereotype.Service;@Servicepublic class StudyService { public void testVoid(){ } public String testString(){ return null; } public List<String> testList(){ return null; }}



推荐阅读