1首先要在pom.xml配置springboot的依赖

包括:

1 springboot

  Spring boot的项目必须要将parent设置为spring boot的parent,该parent包含了大量默认的配置,大大简化了我们的开发。,一般放在最顶层,

<parent>

      <groupId>org.springframework.boot</groupId>

      <artifactId>spring-boot-starter-parent</artifactId>

      <version>1.5.2.RELEASE</version>

   </parent>

2 web支持

<dependency>

        <groupId>org.springframework.boot</groupId>

        <artifactId>spring-boot-starter-web</artifactId>

      </dependency>

3 插件

<plugin>

           <groupId>org.springframework.boot</groupId>

           <artifactId>spring-boot-maven-plugin</artifactId>

        </plugin>

编写helloworld:

@Controller

@SpringBootApplication

@Configuration

public class HelloApplication {

   

    @RequestMapping("hello")

    @ResponseBody

    public String hello(){

        return "hello world";

    }

   

    public static void main(String[] args) {

        SpringApplication.run(HelloApplication.class, args);

    }

 

}

 

代码说明:

1、@SpringBootApplication:Spring Boot项目的核心注解,主要目的是开启自动配置。;

2、@Configuration:这是一个配置Spring的配置类;

3、@Controller:标明这是一个SpringMVC的Controller控制器;

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

5、@RequestMapping 是 Spring Web 应用程序中最常被用到的注解之一。这个注解会将 HTTP 请求映射到 MVC 和 REST 控制器的处理方法上,也就是url的后缀

6、@ResponseBody 表示该方法的返回结果直接写入 HTTP response body 中,一般在异步获取数据时使用【也就是AJAX】

可以直接启动,也可以使用配置的插件可以用于启动工程

springboot入门学习系列-4 springboot之helloworld

找到maven build 双击进入。

springboot入门学习系列-4 springboot之helloworld

 

 

相关文章: