Spring:以编程方式绑定请求中的对象

Mat*_*lla 6 java spring spring-mvc

有没有办法以编程方式将表单数据绑定到知道类类型的对象?我以为会有类似的东西

T instance = something.pleaseDoSomeMagicBind(class, request)
Run Code Online (Sandbox Code Playgroud)

某处或类似的地方,但到目前为止我没有运气.

谢谢

Mat*_*lla 9

感谢Sotirios(你拯救了我的理智)的暗示,我已经能够实现我一直在寻找的东西,如果有其他人感兴趣,我将离开这里

final WebDataBinder binder = new WebDataBinder(BeanUtils.instantiate(clazz));
ServletRequestParameterPropertyValues values = new ServletRequestParameterPropertyValues(request);
binder.bind(values);
final BindingResult result = binder.getBindingResult();
Run Code Online (Sandbox Code Playgroud)