简体   繁体   English

为什么我在点击这个 api 时得到一个 null 值?

[英]Why am I getting a null value while hitting this api?

This is my controller:这是我的 controller:

@RestController
public class TransactionController {
    
    @Autowired
    TransactionService transactionService;
    
    @PostMapping("/add-transaction")
    public Transaction addTransaction(@RequestBody CustomerTransactions customerTransactions) {
        System.out.println("Check in controller");
        System.out.println(customerTransactions);
        return transactionService.addTransaction(customerTransactions);
    }

}

But the customerTransactions is null. I am sending the JSON request in Postman in the following way:但是 customerTransactions 是 null。我通过以下方式在 Postman 中发送 JSON 请求:


{
    "Customer":{
        "custName": "Bikash Bhattarai",
        "email": "bksbhattarai@gmail.com",
        "phone": 9818122018
    },
    "Transaction":{
        "custId": "446bdfd3-3d09-43e7-83df-1883f967d296",
        "transdate": "03-04-2023",
        "transamount": 2000
    }
}

This is the console output:这是控制台 output:

Check in controller
CustomerTransactions [customer=null, transaction=null]
here we go
CustomerTransactions [customer=null, transaction=null]
null
2023-01-01T20:07:08.514+05:45 ERROR 14976 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: java.lang.NullPointerException: Cannot invoke "com.rewardsystem.AugustStore.entities.Customer.getCustId()" because "customer" is null] with root cause

Looks like getter and setter methods are not available in CustomerTransactions , Customer and Transaction classes.看起来 getter 和 setter 方法在CustomerTransactionsCustomerTransaction类中不可用。 Please add getter/setter methods and try again.请添加 getter/setter 方法并重试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM