SpringBoot学习(第一天)
1.创建maven项目
2.添加依赖
1 <parent> 2 <groupId>org.springframework.boot</groupId> 3 <artifactId>spring-boot-starter-parent</artifactId> 4 <version>2.0.3.RELEASE</version> 5 </parent> 6 7 <dependencies> 8 <dependency> 9 <groupId>org.springframework.boot</groupId> 10 <artifactId>spring-boot-starter-web</artifactId> 11 </dependency> 12 </dependencies>
3.编写主程序 run(); 传入的class必须是 @SpringBootApplication 标注的
1 import org.springframework.boot.SpringApplication; 2 import org.springframework.boot.autoconfigure.SpringBootApplication; 3 4 @SpringBootApplication 5 public class HellowordMainApplication { 6 public static void main(String[] args) { 7 SpringApplication.run(HellowordMainApplication.class); 8 } 9 }
4.编写Controller
1 import org.springframework.stereotype.Controller; 2 import org.springframework.web.bind.annotation.RequestMapping; 3 import org.springframework.web.bind.annotation.ResponseBody; 4 5 @Controller 6 public class HelloController { 7 @ResponseBody 8 @RequestMapping("/hello") 9 public String hello(){ 10 return "hello"; 11 } 12 }
5.简化部署
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>
6.将应用打成jar包 直接用 java -jar 运行