添加web功能
在pom文件添加依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
建包必须在同级目录下新建
web测试
浏览器访问:http://localhost:8080/hello/hello
@Controller
@RequestMapping("/hello")
public class MyController {
@GetMapping("/hello") /* 和 RequestMapping("/hello")一样*/
@ResponseBody /*使方法返回得字符串为 页面内容*/
public String gethello(){
return "欢迎来到德莱联盟!";
}
}
通过配置文件修改端口号(微服务)
在application.properties文件
添加:server.port=8888
yaml文件
server:
port: 8081 修改端口号
spring:
profiles:
active: text 使用哪个代码块得配置
--- 分割线 分割不同
server:
port: 8082
spring:
profiles: dev 设置代码块别名
---
server:
port: 8083
spring:
profiles: text