欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

springboot实现配置本地访问端口及路径

程序员文章站 2022-06-16 10:34:27
目录springboot配置本地访问端口及路径1.在application.properties中配置2.在控制层配置springboot启动端口+访问路径springboot配置本地访问端口及路径简...

springboot配置本地访问端口及路径

简单地来说,访问端口及路径加上参数就是我们常说的接口,下面是配置详情

1.在application.properties中配置

#访问路径 你自定义的
server.servlet.context-path=/test
#访问端口 你自定义的
server.port=9002

2.在控制层配置

@restcontroller
@requestmapping("/user")
public class usercontroller {
    @requestmapping("/save")
    string save(@requestparam string name) {
        return "name:"+name;
    }
}

然后启动服务

访问 http://localhost:9002/test/user/save?name=123

ok了。

简单,是吧?

springboot启动端口+访问路径

只需要在配置文件中添加访问端口和访问路径就ok,一般添加在配置文件开头

server.port=9090
server.context-path=/springboot //2.0之前
server.servlet.context-path=/springboot //2.0之后

现在只能用http://127.0.0.1:9090/springboot才能访问到项目

以上为个人经验,希望能给大家一个参考,也希望大家多多支持。