springboot输出helloworld
打开IDEA,新建项目
选择Spring Initializr–>Next
(项目信息设置可以默认,也可以Next)
选择Web–>SpringWeb --> Next
Project Name自定义 --> Finish
目录如下
(主要文件一致即可,存在其他不一致不影响)
DemoApplication是启动类,在和启动类同一个包下新建JAVA类——hello类
代码如下:
//DemoApplication类
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
//hello类
package com.example.demo;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class hello {
@RequestMapping("/hello")
public String print(){
return "hello,SpringBoot";
}
}
回到启动类DemoApplication 运行,打开浏览器 输入localhost:8080/hello