数据绑定不使用弹簧taglib [英] Data binding without using spring taglib
问题描述
我的html是在不使用spring taglib的情况下构建的,现在我想将表单的参数绑定到控制器中的对象。
My html is built without using the spring taglib and now I'd like to bind the parameters of the form to a object in my controller.
目前我的表单看起来像这样
Currently my form looks like this
<form>
<input type="text" name="frAccUserMgmt.userName"/>
<input type="password" name="frAccUserMgmt.userPwd"/>
</form>
我的对象的相关部分是
Class FrAccUserMgmt {
private String userName;
private Strint userPwd;
// getter and setter
}
我的控制器是
@RequestMapping("login")
Public ModelAndView doLogin(FrAccUserMgmt frAccUserMgmt) {
//code
}
我如何去绑定它呢?目前绑定不会发生。我只是在我的代码中找到一个空的对象。
How do I go about binding it. Currently the binding doesn't happen. I just get an empty object in my code.
推荐答案
你可以尝试包括 BindingResult
类中的方法签名,然后查看是否有任何绑定错误:
You could try including the BindingResult
class in the method signature and then see if there are any binding errors:
@RequestMapping("login")
Public ModelAndView doLogin(FrAccUserMgmt frAccUserMgmt, BindingResult result) {
if (result.hasErrors()) {
logger.warn("BindingResult errors: " + result.toString());
}
//code
}
删除 frAccUserMgmt
表单域名中的部分。 Spring将根据命令对象中定义的getter和setter自动找到命令对象来绑定请求参数。
Remove the frAccUserMgmt
part from the form field names. Spring will automatically find the command object to bind the request parameters based on the getters and setters defined in the command object.
这篇关于数据绑定不使用弹簧taglib的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!