如果我想在rails中获得Office's
展示页面,我只需使用网址.../offices/:id
我有一个Spring应用程序,我正试图让同样的事情发生。我不确定如何编写href来转到office's
showOffice
页面。我有一个控制器方法:
@RequestMapping(value = "/showOffice", method=RequestMethod.GET)
public ModelAndView showOfficePage(Long officeId) {
Office office = officeServiceImpl.find(officeId);
ModelAndView result = new ModelAndView("showOffice", "command", office);
return result;
}
我唯一能想到的是<a href="${pageContext.request.contextPath}/showOffice(${10})" class="btn btn-primary btn-lg" role="button">
有人能指出我正确的方向吗?感谢。
答案 0 :(得分:2)
是。对于这种情况,Spring 3.0及更高版本支持@PathVariable注释。有关详细信息,请参阅docs。
@RequestMapping(value = "/offices/{officeId}", method=RequestMethod.GET)
public ModelAndView showOfficePage(@PathVariable("officeId") Long officeId) {
Office office = officeServiceImpl.find(officeId);
ModelAndView result = new ModelAndView("showOffice", "command", office);
return result;
}
普通旧连接可用于在视图中构建这些URL:
<a href="/offices/<%= offices.id %>" >Link</a>