返回List

时间:2018-06-04 23:47:39

标签: java mysql spring-boot spring-data-jpa

我有一个端点,可以保存用户的交易,以便我可以在月底计算用户的佣金。持久的交易工作正常,但是返回一个交易清单是行不通的。即使有数据,它总是返回一个空列表。我尝试了不同的解决方案但结果相同,我可能会遗漏什么。我正在使用mysql数据库来保存我的数据。这是我的代码:

实体:

@Entity
@Table(name = "commission", uniqueConstraints = {
            @UniqueConstraint(columnNames = "transactionsReference")
        }
)
public class commission implements Serializable{

    @Id @GeneratedValue(strategy=GenerationType.IDENTITY)
    private int transactionId;
    private String customerIdentification;
    private String transactionsReference;
    private double commission;
    private double transactionAmount;
    private String transactionType;
    private String commissionClass;
    private String commissionName;
    private String transactionDate;

    public commission() {
    }

    public commission(String customerID, String transactionsReference, double commission, double transactionAmount, String transactionType, String commissionClass, String commissionName, String transactionDate) {
        this.customerIdentification = customerID;
        this.transactionsReference = transactionsReference;
        this.commission = commission;
        this.transactionAmount = transactionAmount;
        this.transactionType = transactionType;
        this.commissionClass = commissionClass;
        this.commissionName = commissionName;
        this.transactionDate = transactionDate;
    }

  // Getters and setters omitted for brevity  

}

存储库:

public interface CommissionRepository extends CrudRepository<commission, Integer> {    

 public List<commission> findByCustomerIdentification(String customerId);
    public List<commission> findByCommissionClass(String comclass);
    public commission findByTransactionsReference(String ref); 

}

服务:

@Service
@Transactional
public class CommisionService {

    @Autowired
    private CommissionRepository commission_repository;

    public List<commission> getAllCommissions(String customerid) {
        List<commission> userCommissions = commission_repository.findByCustomerIdentification(customerid);
        if (userCommissions == null) {
            throw new ResourceNotFoundException("Empty", "Missing Data Exception");
        }
        return userCommissions;
    }

}

控制器类:

@RestController
@Api(value = "TransactionsAPI", produces = MediaType.APPLICATION_JSON_VALUE)
public class CommissionsController {

    @Autowired
    private CommisionService transactionsService;

    @RequestMapping(method = RequestMethod.POST, value = "/myendpoint/endpoint/getAll/customer/commissions/byCustomerID")
    @ApiOperation("Get all customer commissions")
    @ApiResponses(value = {
    @ApiResponse(code = 200, message = "OK", response = TransactionResponse.class)})
    public List<commission> getAllCollectionPoints(@Valid @RequestBody String cusid) {
        return transactionsService.getAllCommissions(cusid);
    }
}

实体:

@Entity
@Table(name = "commission", uniqueConstraints = {
            @UniqueConstraint(columnNames = "transactionsReference")
        }
)
public class commission implements Serializable{

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int transactionId;
    private String customerId;
    private String transactionsReference;
    private String commissionClass;

    public commission() {
    }

    public commission(String customerId, String transactionsReference, String commissionClass) {
        this.customerId = customerId;
        this.transactionsReference = transactionsReference;
        this.commissionClass = commissionClass;
    }

    public int getTransactionId() {
        return transactionId;
    }

    public void setTransactionId(int transactionId) {
        this.transactionId = transactionId;
    }

    public String getCustomerId() {
        return customerId;
    }

    public void setCustomerId(String customerId) {
        this.customerId = customerId;
    }

    public String getTransactionsReference() {
        return transactionsReference;
    }

    public void setTransactionsReference(String transactionsReference) {
        this.transactionsReference = transactionsReference;
    }

    public String getCommissionClass() {
        return commissionClass;
    }

    public void setCommissionClass(String commissionClass) {
        this.commissionClass = commissionClass;
    }


}

0 个答案:

没有答案