我的控制器是:
@PostMapping("/car/{id}/book", consumes =
[MediaType.APPLICATION_FORM_URLENCODED_VALUE])
fun orderProcess(model: Model,
@PathVariable id: Int,
@Valid customerBindingModel: CustomerBindingModel,
bindingResult: BindingResult,
request: HttpServletRequest,
@RequestBody multiParams: MultiValueMap<String, String>) : String {
println(multiParams)
val params = multiParams.toSingleValueMap()
println(params)
val startDateString = params["datetime_pick"]!!
val endDateString = params["datetime_off"]!!
...
}
我的观点是:
<form th:action="@{/car/{id}/book(id=${car.id})}" id="confirmForm" method="POST">
<div class="formrow">
<input type="hidden" id="startDate" name="startDate" th:value="${param.datetime_pick[0]}" />
<input type="hidden" id="endDate" name="endDate" th:value="${param.datetime_off[0]}" />
<label for="email">Email</label>
<input type="email" id="email" name="email" th:value="${customer.email}" />
<label for="phoneNumber">ТелеÑон</label>
<input type="tel" id="phoneNumber" name="phoneNumber" th:value="${customer.phoneNumber}" />
<script th:src="@{/intl-tel-input-12.1.0/build/js/intlTelInput.js}"></script>
<!-- Bootstrap -->
<br/>
<label class="check-container">Сега Ñе плаÑÑ Ð´ÐµÐ¿Ð¾Ð·Ð¸Ñ:
<input type="checkbox" name="payDepositNow" th:checked="${payDepositNow}">
<span class="checkmark"></span>
</label>
<script>
$("#phoneNumber").intlTelInput({
nationalMode: false,
preferredCountries: ['bg'],
});
</script>
</div>
问题是我得到了一个NPE(空指针),我尝试了各种方法来正常获取函数体。我的意思是我可以通过拆分一个URL编码的字符串来获得它,但我有点想把它作为一个映射来获得。
我也可以做一个函数来转换
@RequestBody params: String
我自己去画一张地图,但一定有更好的方法把身体画成一张地图。NPE必须在断言的周围。(
!!
)
如果我试图获得数据
@RequestParam param: String
我显然不能,因为数据在身体里。