@RequestMapping("/admin")
public String index(ModelMap modelMap,HttpServletRequest req){
String scheme = req.getScheme();
String serverName = req.getServerName();
int serverPort = req.getServerPort();
String path = req.getContextPath();
String basePath = scheme+"://"+serverName+":"+serverPort+path+"/";
modelMap.put("basePath",basePath);
modelMap.put("adminPath", basePath+"admin/");
modelMap.put("staticPath", basePath+"static/admin/common");
return "admin/index";
}
@RequestMapping("/admin/login")
public String login(ModelMap modelMap,HttpServletRequest req){
String scheme = req.getScheme();
String serverName = req.getServerName();
int serverPort = req.getServerPort();
String path = req.getContextPath();
String basePath = scheme+"://"+serverName+":"+serverPort+path+"/";
modelMap.put("basePath",basePath);
modelMap.put("adminPath", basePath+"admin/");
modelMap.put("staticPath", basePath+"static/admin/common");
return "admin/login";
}
取得路徑的程式碼寫了兩份 ,感覺好臃腫啊,怎麼讓只寫一份,然後給共用?
1.首先中間件概念你沒弄清楚,不能亂用
2.回到你的問題,就是一個方法抽取的場景,建議看一下>這本書
寫到filter當中,或用動態代理
程式碼隨便重構一下就好看多了