If it is to reflect the hierarchical sense of the project , When we use request When , It is generally used in the control layer , There is no need to request Also passed on to service use , So first of all, let's talk about controller Gets the absolute path of the current project
public Message<Object> uploadImgsFile(HttpServletRequest request) { //1 String
realPath =
request.getSession().getServletContext().getRealPath(File.separator);
System.out.println(realPath); //2 String realPath2 =
request.getServletContext().getRealPath(File.separator);
System.out.println(realPath2); return null; }
If you want to get the absolute path of the current project , And it's not here controller, At the same time, I don't want to pass it on request Parameters to service layer , You can do this
// code snippet // Now get the current path WebApplicationContext webApplicationContext =
ContextLoader.getCurrentWebApplicationContext(); ServletContext servletContext
= webApplicationContext.getServletContext(); String realPath =
servletContext.getRealPath(File.separator); System.out.println(realPath);
After the above operation, you can get the path of the project , In order to facilitate the needs of their own projects

Technology
©2020 ioDraw All rights reserved
Vue2.0+jsonserver+axios Simulate local request interface data Enterprises face SEM Bidding and SEO How to choose ? Or both ? Did you complain today ? Notes on core principles of reverse engineering ( One )——Hello World-1 Some views of a student on Hongmeng system Java Summary of basic learning (162)—— How to ensure thread safety ? Using function to realize the exchange of two numbers (C language )SK Hynix World Premiere DDR5 Memory : The frequency goes up 5600MHz, Capacity up to 256GBdjango Do not close CSRF middleware , Custom through CSRF Tested post request Zhejiang University data structure midterm examination questions