@Slf4j -- lombok.extern.slf4j.Slf4j;


@Log4j:注解在類上;為類提供一個 屬性名為log 的 log4j 日志對像

package com.atguigu.springcloud.controller;

import com.atguigu.springcloud.entities.CommonResult;
import com.atguigu.springcloud.entities.Payment;
import com.atguigu.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@Slf4j
public class PaymentController {

    @Resource
    private PaymentService paymentService;

    @PostMapping(value = "/payment/create")
    public CommonResult create(Payment payment){
        int result = paymentService.create(payment);
        log.info("*****插入結果:"+result);       //這里就是使用了Log這個對象
        if (result>0){  //成功
            return new CommonResult(200,"插入數據庫成功",result);
        }else {
            return new CommonResult(444,"插入數據庫失敗",null);
        }
    }
    @GetMapping(value = "/payment/get/{id}")
    public CommonResult getPaymentById(@PathVariable("id") Long id){
        Payment payment = paymentService.getPaymentById(id);
        log.info("*****查詢結果:"+payment);
        if (payment!=null){  //說明有數據,能查詢成功
            return new CommonResult(200,"查詢成功",payment);
        }else {
            return new CommonResult(444,"沒有對應記錄,查詢ID:"+id,null);
        }
    }
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM