创建SpringBoot项目
此处起名字比较随意,但写项目时不可随意命名,最好做到望文生义
等待依赖下载完成,完成后,目录结构是这样的:
:
在java目录下创建类
FirstSpringApplication类
package com.tx.sboot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication //启动类的注解
public class FirstSpringApplication {
public static void main (String[] args) {
SpringApplication.run(FirstSpringApplication.class,args);
}
}
TestController类
package com.tx.sboot;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class TestController {
@RequestMapping("hello")//接口,可以通过浏览器访问
public String hello(){
return "hello springboot";//浏览器中看到的内容
}
}
浏览器地址栏输入:http://localhost:8080/hello
可看到返回值:hello springboot
注意:配置全局JDK,指定Maven路径