安装lombok插件:
pom.xml加入依赖:
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
<version>1.16.18</version>
</dependency>
使用@Slf4j注解
使用log对象的info()方法
@RestController
@Slf4j
public class PaymentController {
@Autowired
private PaymentService paymentService;
@GetMapping(value = "/payment/get/{id}")
public CommonResult getById(@PathVariable("id") long id){
Payment result = paymentService.getPaymentById(id);
log.info("查询结果:"+result);
if(result!=null){
return new CommonResult(200,"查询成功",result);
} else {
return new CommonResult(444,"没有查到,ID:"+id,null);
}
}
}