Spring Boot学习——入门小程序

如何编写一个SpringBoot入门应用

主要步骤:
  • 在pom.xml中引入starts

  • 创建主程序

  • 在main方法上启动

具体代码
/**
 * @SpringBootApplication :来表示一个主应用的入口
 */
@SpringBootApplication
public class HelloWorldMianApplication {

    public static void main(String[] args) {
        SpringApplication.run(HelloWorldMianApplication.class,args);
    }
}
@Controller()
public class HelloWorldController {
    @ResponseBody
    @RequestMapping("/hello")
    public String helloworld(){
        return "HelloWorld";
    }
}
<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.1.RELEASE</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

运行效果:
在这里插入图片描述
1.@SpringBootApplication注解表明当前应用是一个SpringBoot应用的入口。
2.在main方法中SpringApplication.run(HelloWorldMianApplication.class,args);
run()表明启动应用。

发布了159 篇原创文章 · 获赞 86 · 访问量 7万+

猜你喜欢

转载自blog.csdn.net/qq_40301026/article/details/103093593