@ModelAttribute
public void get(HttpServletRequest request, ModelMap model)
{
String href = request.getServletPath().replaceFirst(Global.getFrontPath(), "");
if (StringUtils.isNoneBlank(href))
{
Category category = this.categoryService.findByhref(href);
if (category != null)
{
Site site = this.siteService.get(category.getSite().getId());
model.addAttribute("site", site);
model.addAttribute("category", category);
}
}
}
在栏目中的时候,当跳转到一个栏目时,栏目category和站点site就已经通过addAttribute方法设置好了,可是当进入首页时,并没有对这两个变量进行设置
采用如上方法,使用地址获取栏目和站点信息即可