【发布时间】:2018-02-22 22:05:39
【问题描述】:
我遇到了我的模型属性在页面之间丢失值的情况。
我有两个控制器方法分别处理 GET 和 POST 请求。
GET方法
@RequestMapping(value = "/checkout/billing", method = RequestMethod.GET)
public String getBillingPage(Model model, final HttpServletRequest request) throws CMSItemNotFoundException {
// other code
checkoutForm.setCustomFieldsForm(customFieldsForm);
model.addAttribute("checkoutForm", checkoutForm);
// other code
}
POST 方法
@RequestMapping(value = "/checkout/billing", method = RequestMethod.POST)
public String submitPayment(
@Valid @ModelAttribute("checkoutForm") final CheckoutForm checkoutForm,
final BindingResult bindingResult,
Model model,
final HttpServletRequest request,
final HttpServletResponse response) throws CMSItemNotFoundException
{}
1234 来自用户在表单字段中输入该数据。其他值应该仍然存在并且不为空。
这里会发生什么?
【问题讨论】:
标签: java spring model-view-controller