springboot入门程序

springboot

简介

优点 

入门程序

1、加入jar包

<!--设置spring boot的parent-->
<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.2.RELEASE</version>
</parent>
<!--  导入spring boot的web支持-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--添加Spring boot的插件,可不要-->
<plugin>
        <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-maven-plugin</artifactId>
</plugin>

2、编写第一个springboot程序

@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);
    }

}

3、代码说明

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

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

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

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

原文地址:https://www.cnblogs.com/durui/p/9323652.html