SpringBoot 基础
SpringBoot 基础
1.0 第一个springboot程序
package com.javalearn;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@RequestMapping("/hello")
public String hello(){
System.out.println("hello");
return "hello world";
}
}
@RestController
标识这是一个请求处理类
@RequestMapping("/hello")
为路由函数添加路由
我们创建SpringBoot项目时,都会附加启动类,如果我们采用maven项目手动添加springboot依赖就需要自己
去写启动类了,启动类如下:
package com.javalearn;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SpringWebApplication {
public static void main(String[] args) {
SpringApplication.run(SpringWebApplication.class, args);
}
}
1.1 更改启动端口
通过更改resources目录下的application.properties
在其中修改server.port来更改启动端口,默认端口是8080
如果我们想要更改到8000
server.port=8000

浙公网安备 33010602011771号