package com.demo.wjj.controller; import com.demo.wjj.po.Demo; import com.demo.wjj.service.DemoService; import com.demo.wjj.utils.ApiResult; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; /** * demo * @author wangqing * @date 2018.11.07 */ @RestController @RequestMapping("/demo") public class DemoController { private final Logger LOG = LoggerFactory.getLogger(getClass()); @Autowired private DemoService demoService; @GetMapping("/get/{id}") public ApiResult getDemo(@PathVariable String id) { LOG.info("调用获取demo接口, id:{}", id); try { final Demo demo = demoService.get(Integer.parseInt(id)); ApiResult apiResult = ApiResult.createSuccess(demo); LOG.info("调用获取demo接口end, apiResult:{}", apiResult); return apiResult; } catch (Exception e) { LOG.error("调用获取demo接口异常", e); ApiResult apiResult = ApiResult.createFailure(); LOG.info("调用获取demo接口end, apiResult:{}", apiResult); return apiResult; } } }