【发布时间】:2021-12-02 00:23:18
【问题描述】:
我有一个实体投资列表显示,其中包含来自数据库的五行,状态最初设置为待处理。我想要做的是在每个结果行中添加一个激活功能按钮(React),这样当在一行上单击激活按钮时,它将获取投资 ID 并执行激活功能并将状态更改为 "Active" 。我正在发送 POST 请求,但在获取行 ID 时遇到问题。我可能做错了什么?
这是投资实体
public class Investment
{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
//@Column(nullable = true)
@ManyToOne(targetEntity = com.bethsaida.org.models.Customer.class,
cascade = CascadeType.ALL, fetch = FetchType.LAZY )
@JoinColumn(name="customer_id")
private Customer customer ;
@Column(name = "AccountNumber", updatable = false, nullable = false)
private int accountNumber;
private String category;
private BigDecimal principal;
//private BigDecimal netInvestmentAmount;
private BigDecimal currentInterest;
private BigDecimal maturityInterest;
private String tenure;
private String marketer;
private String investmentPackage;
@DateTimeFormat(pattern = "yyyy-MM-dd")
private LocalDate startDate;
@DateTimeFormat(pattern = "yyyy-MM-dd")
private LocalDate maturityDate;
private int rate;
这是实现激活逻辑的服务类
public void activateInvestment(Investment investment, Long id)
{
if(!(investment.getRate() <= 0))
investment.setStatus(InvestmentStatus.Active);
else {
System.out.println("Investment Rate Can't be Null");
}
}
这是 Controller 类
@PostMapping(value="/activateInvestment/{id}")
public void activateInvestment(@RequestBody Investment investment, @PathVariable Long id)
{
investmentService.activateInvestment(investment, id);
}
【问题讨论】:
标签: java mysql reactjs spring-boot spring-data-jpa