我想插入一个简单的对象到数据库,但在我的控制器上,我无法发送LocalDate
参数。如何接收LocalDate作为参数
错误说malformed request syntax, invalid request message framing, or deceptive request routing
我很确定这个参数是LocalDate
造成的。
我控制器
@RequestMapping(value = "/finance",method = RequestMethod.POST)
public String postFinance(@ModelAttribute("finance")
Finance finance, Model model){
financeServices.targetActivate(finance);
model.addAttribute("targetSetStatus",true);
return "finance/finance";
}
金融实体
@Entity
public class Finance {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private LocalDate targetDate;
private Double targetAmount;
private LocalDate createdDate;
//getter setters //
}
编辑: - 我试图从形式插入,所以我的形式看起来像: -
<form class="form-horizontal" id="productForm"
th:action="@{/finance}" method="post">
<div class="form-group">
<div th:if="${targetSetStatus}">
<div class="alert alert-success">
<p>New Target Has Been Set</p>
</div>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3"
for="targetAmount">Target Amount:</label>
<div class="col-sm-9">
<input type="number" class="form-control"
placeholder="Targeted Amount"
name="targetAmount" id="targetAmount">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3"
for="targetDate">Target Date:</label>
<div class="col-sm-9">
<input type="date" class="form-control"
placeholder="Targeted Date"
name="targetDate" id="targetDate">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-9">
<button type="submit" class="btn btn-default">Set Target</button>
</div>
</div>
</form>
如果我用java.util.Date
代替LocalDate它可以工作,但我想使用LocalDate它提供的java 8 API。
基地支持在未来的未来,请参阅[拉入请求和分辨率(https://github.com/spring-projects/spring-boot/pull/9930)。与此同时,[看到这个问题](https://stackoverflow.com/questions/44924656/how-to-register-global-databinding-for-localdate-in-spring-mvc)。 –