【发布时间】:2017-11-30 09:04:13
【问题描述】:
我有一个简单的注册。
这是我的jsp注册页面的一部分:
<form class="form-horizontal" method="post" action="RightsGroupRegister">
<div class="form-group">
<label for="Name of group" class="col-sm-2 control-label">Name of group:</label>
<div class="col-sm-10">
<input class="form-control" id="name" name="name" placeholder="Name of group">
</div>
</div>
<div class="form-group">
<label for="Rights" class="col-sm-2 control-label">Rights:</label>
<div class="col-sm-10">
<input class="form-control" id="rights" name="rights" placeholder="Rights">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button class="btn btn-default">Create</button>
</div>
</div>
</form>
这里还有一个控制器:
@Controller
public class RightsGroupController {
private static final Logger LOGGER = LoggerFactory.getLogger(RightsGroupController.class);
private final RightsGroupService rightsGroupService;
@Inject
public RightsGroupController(RightsGroupService rightsGroupService) {
this.rightsGroupService = rightsGroupService;
}
@RequestMapping(value = "RightsGroupRegister", method = RequestMethod.GET)
public ModelAndView getRightsGroupView() {
LOGGER.debug("Received request for addRight");
return new ModelAndView("RightsGroupRegister", "form", new RightsGroupForm());
}
@RequestMapping(value = "RightsGroupRegister", method = RequestMethod.POST)
public String createRightsGroup(@ModelAttribute("form") RightsGroupForm form ) {
LOGGER.debug("Received request to create {}, with result={}", form);
try {
rightsGroupService.save(new Rightsgroup(form.getName(),form.getRights()));
} catch (RightsGroupAlreadyExistsException e) {
LOGGER.debug("Tried to create rightsgroup with existing id", e);
return "right_create";
}
return "redirect:/";
}}
现在的问题,我真的不明白如何使用它。 如何从另一个对象获取此表单数据?例如权限列表(id,name)?
【问题讨论】:
-
什么意思?您想访问
RightsGroupForm中的字段吗?看起来你已经在这样做了。 -
我想用右对象的数据填充表格或组合框
-
你解决了吗?我的分析器有帮助吗?
标签: java spring jsp servlets javabeans