springboot的特点:
- 创建独立的Spring应用程序
- 嵌入的Tomcat,无需部署WAR文件
- 简化Maven配置
- 自动配置Spring
- 提供生产就绪型功能,如指标,健康检查和外部配置
创建idea第一个springboot
配置maven
创建RunApp.java
package cn.tedu.cotroller;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Controller;
@SpringBootApplication
@Controller
public class RunApp {
public static void main(String[] args) {
SpringApplication.run(RunApp.class, args);
}
}
创建HelloController.java
package cn.tedu.cotroller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController//接受浏览器的请求 并返回json数据
public class HelloController {
// @RequestMapping("hi")//只匹配一个路径
@RequestMapping({"hi","hello/hi"})//匹配两种路径/hi或者/hello/hi
public String hi() {
return "hi springboot!";
}
}
测试
解决端口冲突的问题:
application.properties文件中 编写 server.port=8081