创建SpringBoot项目,启动后,默认的访问路径即主机IP+默认端口号8080:http://localhost:8080/

此时,我们就可以访问Controller层的接口了,如:http://localhost:8080/hello
package com.springboot.test;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class SpringBootTest {
@RequestMapping("/hello")
public String helloSpringBoot() {
return "Hello SpringBoot Project.";
}
}

当然,我们可以通过配置来更改默认端口和项目访问路径:
修改端口号
使用properties文件方式:
<

本文介绍了如何在SpringBoot项目中更改默认访问端口和设置自定义访问路径。通过修改application.properties或application.yml文件,分别展示了properties和yml格式的配置方法。
订阅专栏 解锁全文
6万+

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



