Spring mvc 3 一般Controller架构问题
抱歉新手问题, 场景很简单,我进入Jsp页面,可以填写Driver信息, 我有驱动程序对象的设置方法
@RequestMapping(method = RequestMethod.GET)
public ModelAndView setUpForm(){
ModelAndView modelAndView = new ModelAndView("/driverForm");
Driver = myService.getDriver();
modelAndView.addObject("driver",driver);
return modelAndView;
}
和更新方法来获取驱动程序更新的数据
@RequestMapping(params = "update", method = RequestMethod.POST)
public String update(Driver driver, BindingResult result, SessionStatus status) {
myService.saveDriver(driver);
return "driversList";
}
然后我向 jsp 层“提供”所需的驱动程序信息,例如驱动程序名称:
<form:input path="name" size="20" maxlength="50" />
我的问题是如何填充不同的模型属性并连接驱动程序这些属性的信息 例如: 将各种许可证类型显示为复选框,供用户选择(自行车、公共汽车、出租车等),并将它们在我的控制器中映射到驱动程序对象上的单个属性, 从此字段编辑现有驱动程序时还要映射选择 什么是正确的控制器架构?
Sorry for the newbie question,
The scenario is simple, I go Jsp page where one can fill Driver information,
I have setup method for the driver object
@RequestMapping(method = RequestMethod.GET)
public ModelAndView setUpForm(){
ModelAndView modelAndView = new ModelAndView("/driverForm");
Driver = myService.getDriver();
modelAndView.addObject("driver",driver);
return modelAndView;
}
And update method to get the driver updated data
@RequestMapping(params = "update", method = RequestMethod.POST)
public String update(Driver driver, BindingResult result, SessionStatus status) {
myService.saveDriver(driver);
return "driversList";
}
Then I am "feeding" the jsp layer with the desired driver information, for example driver name:
<form:input path="name" size="20" maxlength="50" />
My question is how to populate different model attributes and connect the driver information to these attribute
For example:
Display various license types as checkboxes for the user to select from (bike,bus,cab, etc) and map them in my controller to a single attribute on the driver object,
Also map the selection when editing existing driver from this field
What is the correct controller architecture?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的控制器中,将一个集合添加到包含您想要提供的所有选项的模型中,然后使用 from:radioButtons 标记来呈现它,这样代码将如下所示:
在 JSP 中,您将执行类似这样的操作
您可以找到更多有关单选按钮标签的信息:
In your controller add a collection to the model containing all the options you want to offer and then use the from:radioButtons tag to render it so the code would look like this :
In the JSP you would then do something like this
You can find more information on the radio buttons tag here : http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/view.html#view-jsp-formtaglib-radiobuttonstag