Springboot如何配置虚拟目录呢?
下文笔者讲述springboot中添加虚拟目录的方法分享,如下所示
实现思路:
在application.properties中设置属性
server.servlet.context-path
即可为SpringBoot虚拟目录
server.servlet.context-path配置功能简介
server.servlet.context-path=
应用的上下文路径,可称为项目路径,是url地址的一部分
注意事项:
server.servlet.context-path不配置时,默认为/
如:localhost:8080/xxxxxx
当server.servlet.context-path配置时
如:/demo
此时的访问方式为localhost:8080/demo/xxxxxx
springboot 2.0 虚拟目录配置的方法
springboot 2.0之前 配置为server.context-path springboot 2.0之后 配置为server.servlet.context-path例:
//前端页面
<form th:action="@{/user/userLogin}" method="post" id="userLogin"></form>
//action
@Controller
@RequestMapping("/user")
public class LoginController {
@PostMapping("/userLogin")
public String userLogin(HttpServletRequest request, Model model) {
//application.properties文件
server:
port: 8080
servlet:
context-path: /demo
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。


