之前访问需要加项目路径和请求
通过controller重新映射下
具体的实现代码
跳转的controller,在此controller中请求index,则跳转到主页
@Controller
@RequestMapping(value = "${frontPath}")
public class QtLoginController extends BaseController {
/**
* 首页
*/
@RequestMapping(value = "index")
public ModelAndView index(HttpServletRequest request, Model model){
GkzyUser gkzyUser = (GkzyUser) request.getSession().getAttribute("gkUser");
ModelAndView mv = new ModelAndView();
if (gkzyUser != null) {
model.addAttribute("phone",gkzyUser.getLoginName());
}
mv.setViewName(pageDir + "index_school");
// mv.setViewName(pageDir + "index");
List<Category> categoryList = new ArrayList<Category>();
if(!LocalCache.isExist("categoryList")){
try {
categoryList = categoryService.findListForArticleList();
for (int i=0;i<categoryList.size();i++){
if ("高考头条".equals(categoryList.get(i).getName())){
for (int j = 0;j<categoryList.get(i).getChildList().size();j++){
Article article = new Article();
article.setCategory(categoryList.get(i).getChildList().get(j));
categoryList.get(i).getChildList().get(j).setArticleList(this.articleService.findList(article));
}
}
}
LocalCache.putValue("categoryList",categoryList, 3600);
}catch (Exception e){
e.printStackTrace();
}
}else {
categoryList = (List<Category>)LocalCache.getValue("categoryList");
}
mv.addObject("categoryList",categoryList);
return mv;
}
}
controller跳controller的方法
@Controller
public class IndexController extends BaseController {
@Autowired
QtLoginController qtLoginController;
/**
* 首页
*/
@RequestMapping(value = {"/",""})
public ModelAndView index(HttpServletRequest request, Model model){
return qtLoginController.index(request ,model);
}
}
等价于这种请求转发
@RequestMapping(value = {"/",""})
public void index(HttpServletRequest request, Model model, HttpServletResponse response) {
try {
request.getRequestDispatcher("/gkzytb/index").forward(request,response);
} catch (ServletException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}