标签:stat loader object tco nav load omr 文件路径 return
1.方法一
调试时只能获取eclipse 项目未编译前的路径 不太好用
/* private static Logger logger = Logger.getLogger(BookController.class); */ @RequestMapping("/index") public String bookHandle(HttpServletRequest servlet) { JSONObject json = JsonResourceUtils.getJsonObjFromResource ("static/json/book_nav.json",servlet.getServletContext().getRealPath("/")); return "book"; }
2.方法 二
获取项目运行时的真实类路径
/* private static Logger logger = Logger.getLogger(BookController.class); */ @RequestMapping("/index") public String bookHandle(HttpServletRequest servlet) { JSONObject json = JsonResourceUtils.getJsonObjFromResource
/* 这里直接获取到了文件路径 */ (BookController.class.getClassLoader().getResource("static/json/book_nav.json").getPath()); return "book"; }
标签:stat loader object tco nav load omr 文件路径 return
原文地址:https://www.cnblogs.com/jiangfeilong/p/11106129.html