在Controller层自动装配ServletContext。
@Autowired
ServletContext context;
然后即可在Controller层的方法里获取项目的根路径。
String path = context.getRealPath("/");
本文介绍如何在Controller层通过@Autowired注解自动装配ServletContext,并演示了如何利用它来获取项目的根路径。
在Controller层自动装配ServletContext。
@Autowired
ServletContext context;
然后即可在Controller层的方法里获取项目的根路径。
String path = context.getRealPath("/");

被折叠的 条评论
为什么被折叠?