手抄报 安全手抄报 手抄报内容 手抄报图片 英语手抄报 清明节手抄报 节约用水手抄报

SpringBoot入门程序

时间:2024-11-18 11:50:11

1、创建一个Maven工程:

SpringBoot入门程序
SpringBoot入门程序

2、导入SpringBoot相关的依赖包:<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.0.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies>

SpringBoot入门程序

3、编写一个主程序,启动Spring Boot应用。package com.gwolf;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.ResponseBody;@SpringBootApplicationpublic class SpringHelloMainApplication { public static void main(String[] args) throws Exception { SpringApplication.run(SpringHelloMainApplication.class, args); }}

SpringBoot入门程序

4、编写相关的Controller、Service。package com.gwolf.controller;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.ResponseBody;@Controllerpublic class HelloController { @ResponseBody @RequestMapping("/hello") public String hello() { return "hello World!"; }}

SpringBoot入门程序

5、启动主程序的main方法启动应用。

SpringBoot入门程序

6、在浏览器中访问地址:http://localhost:8080/hello

SpringBoot入门程序

7、springboot打包部署也是相当简单,只需要导入一个插件。将这个应用打成一个jar包可以直接使用java -jar命令进行执行。<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>

SpringBoot入门程序
© 手抄报圈