User
,其中有一个BigDecimal字段,它是私有的,我正试图通过getter访问它。但是当我尝试访问余额时出现NoSuchMethodError
@Service
public class PaymentProcessor {
@Autowired
UserDaoService userDao;
public void withdrawFunds(String payerId, double amount){
User payer = userDao.getByUserName(payerId);
if ( payer.getBalance().doubleValue() // I get Error here
< amount){
throw new RuntimeException("Insufficient Funds");
}
else {
payer.updateBalance(BigDecimal.valueOf(amount * (-1)));
userDao.saveUser(payer);
}
}
}
已添加编辑用户类别
@Entity
@Table(name = "users")
public class User {
@Id
private String username;
private String email;
private String name;
private String password;
private BigDecimal balance;
private String personalInfo;
private int rating;
@ManyToMany(cascade = {
CascadeType.PERSIST,
CascadeType.MERGE,
}, fetch = FetchType.EAGER)
@JoinTable(name = "user_role",
joinColumns = @JoinColumn(name = "username"),
inverseJoinColumns = @JoinColumn(name = "role_id")
)
private Set<UserRole> userRoles = new HashSet<>();
public User() {
userRoles.add(new UserRole("default"));
this.rating = 0;
this.balance = BigDecimal.valueOf(0);
}
public void updateBalance(BigDecimal balance) {
this.balance = this.balance.add(balance);
}
public BigDecimal getBalance() {
return balance;
}
我有一个类User,它的BigDecimal字段是私有的,我正在尝试通过getter访问它。但是,当我尝试访问余额时,出现NoSuchMethodError @Service公共类...
private BigDecimal balance = BigDecimal.ZERO;