[Solved] insertSale attempted to return null from a method with a primitive return type (int).

1. Problems arising

I am executing the mytest program. Yes, I reported an error.

1. Dao layer interface

1     int insertSale(Sale sale);

2. Service layer

1     @Override
2     public void buy(Integer goodsId, Integer nums) {
3 
4         // Record sales information and add records to the sale table
5         ....
6         saleDao.insertSale(sale);
7      }

The above error will be reported after running the program

2. Error reason

The reason for this error is that the service layer buy() method does not return a value. And we defined the dao layer method is to return int, there will be the following prompt

3. Solution

This is a problem with the Dao layer. The Dao layer is modified as follows:

1     void insertSale(Sale sale);

Similar Posts: