SpringMvc 中獲取項目根目錄的方法

自動注入servletContext對象
1.
@Autowired
private ServletContext servletContext;

獲取項目路徑

String webRootPath=servletContext.getRealPath("");

2種
String path = request.getServletContext().getRealPath("");

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章