IntelliJ IDEA 2017版 SpringBoot的web项目补充

一、注解
       @SpringBootApplication:Spring Boot项目的核心注解,主要目的是开启自动配置。
       @Configuration:这是一个配置Spring的配置类
       @Controller:标明这是一个SpringMVC的Controller控制器
 注意:
   SpringBoot相当于内置一个tomcat虚拟机,可以自动将Springboot项目转化为jar文件直接运行,方便快捷,当然也可以放入Tomcat中使用。
二、Pom配置 
1 <parent>
2  <groupId>org.springframework.boot</groupId>
3 <artifactId>spring-boot-starter-parent</artifactId><version>1.5.2.RELEASE</version>
4 </parent>
View Code

注意:
   Spring boot的项目必须要将parent设置为spring boot的parent,该parent包含了大量默认的配置,大大简化了我们的开发。

1 <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin>
View Code

三、实战讲解:

 1 @Controller
 2 @SpringBootApplication
 3 @Configuration
 4 public class HelloApplication {
 5     
 6     @RequestMapping("hello")
 7     @ResponseBody
 8     public String hello(){
 9         return "hello world!";
10     }
11     
12     public static void main(String[] args) {
13         SpringApplication.run(HelloApplication.class, args);
14     }
15 }
View Code

注:
    @SpringBootApplication注解必须有,SpringApplication是启动springboot的一个应用程序,同时传入对象和参数

    main方法:在main方法中启动一个应用,即:这个应用的入口

原文地址:https://www.cnblogs.com/liuyangfirst/p/8684172.html