我跟随一个关于小帐户应用程序的课程,我开始得到与构造函数相关的错误,而构造函数已经创建了。我先复制下面的一个错误& &;然后介绍一些与错误相关的类。我很感激你的帮助
错误:
java: no suitable constructor found for PrimaryTransaction(java.util.Date,java.lang.String,
java.lang.String,java.lang.String,double,java.math.BigDecimal)
constructor com.front.domain.PrimaryTransaction.PrimaryTransaction() is not applicable
(actual and formal argument lists differ in length)
PrimaryTransaction.java
public class PrimaryTransaction {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private Date date;
private String description;
private String type;
private String status;
private double amount;
private BigDecimal availableBalance;
@ManyToOne
@JoinColumn(name = "primary_account_id")
private PrimaryAccount primaryAccount;
public PrimaryTransaction() {
}
public PrimaryTransaction(Date date, String description, String type, String status, double
amount, BigDecimal availableBalance, PrimaryAccount primaryAccount) {
this.date = date;
this.description = description;
this.type = type;
this.status = status;
this.amount = amount;
this.availableBalance = availableBalance;
this.primaryAccount = primaryAccount;
}
PrimaryAccountDAO.java
public interface PrimaryAccountDao extends CrudRepository<PrimaryAccount, Long> {
PrimaryAccount findByAccountNumber (int accountNumber);
}
AccountServiceImpl
@Service
public class AccountServiceImpl implements AccountService {
@Autowired
private PrimaryAccountDao primaryAccountDao;
@Autowired
private UserService userService;
public void deposit(String accountType, double amount, Principal principal) {
User user = userService.findByUsername(principal.getName());
if (accountType.equalsIgnoreCase("Primary")) {
PrimaryAccount primaryAccount = user.getPrimaryAccount();
primaryAccount.setAccountBalance(primaryAccount.getAccountBalance().add(new
BigDecimal(amount)));
primaryAccountDao.save(primaryAccount);
Date date = new Date();
//////线后,出现错误/////////////////////
PrimaryTransaction primaryTransaction = new PrimaryTransaction(date, "Deposit to
Primary Account", "Account", "Finished", amount, primaryAccount.getAccountBalance());
}
}
构造函数期望primaryAccount
对象作为最终参数,所以尝试如下,
PrimaryTransaction primaryTransaction = new PrimaryTransaction(date, "Deposit to Primary Account", "Account", "Finished", amount, primaryAccount);