Spring @ModelAttribute-绑定属性,用括号括起来,而不是用点分隔
@ModelAttribute可以将Spring @ModelAttribute-绑定属性,用括号括起来,而不是用点分隔,spring,spring-mvc,Spring,Spring Mvc,@ModelAttribute可以将myObj.myProp绑定到以下类而不会出现问题: public class MyObj { private String myProp; // plus a default constructor and setter / getter for myProp } 但如果参数作为myObj[myProp]传递,则绑定失败。弹簧可以绑定括号中指定的属性吗 不,spring被设计为使用解释属性,因此它将作为myObj.myProp工作。我使用的U
myObj.myProp
绑定到以下类而不会出现问题:
public class MyObj {
private String myProp;
// plus a default constructor and setter / getter for myProp
}
但如果参数作为
myObj[myProp]
传递,则绑定失败。弹簧可以绑定括号中指定的属性吗 不,spring被设计为使用
解释属性,因此它将作为myObj.myProp
工作。我使用的UI库使用括号表示法传递HTTP参数。不幸的是,我不能改为使用点符号。由于Spring在org.springframework.beans.InvalidPropertyException
中出错,我必须通过HttpServletRequest
对象获取参数。我确实发现了这一点,但不确定他们是如何让弹簧绑定与支架一起工作的。