SpringBoot官方文档
3.创建一个MainApplication.class文件4.0.0 org.atgg boot-01-helloworld 1.0-SNAPSHOT org.springframework.boot spring-boot-starter-parent 2.3.4.RELEASE org.springframework.boot spring-boot-starter-web
package com.atgg.boot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class MainApplication {
public static void main(String[] args) {
SpringApplication.run(MainApplication.class,args);
}
}
4.创建一个控制器controller,处理响应请求
HelloController.class
package com.atgg.boot.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
//请求映射,当发出/hello的请求时,回复一个字符串:Hello, Spring Boot 2!
@RequestMapping("/hello")
public String handle01(){
return "Hello, Spring Boot 2!";
}
}
4.点击MainApplication.class的main函数的run开始运行程序:
在浏览器输入本地请求:
http://localhost:8080/hello
页面会显示字符串:Hello, Spring Boot 2!
server.port=8888相应的,请求页面为8888时才会显示对应的字符串: 6.打包成可执行文件(.jar) 在pom.xml中添加以下字段:
点击Maven,将其打成jar包 进入target文件夹就可以找到.jar包了,进入cmdorg.springframework.boot spring-boot-maven-plugin2.3.4.RELEASE
输入命令执行:
照样可以执行响应请求java -jar boot-01-helloworld-1.0-SNAPSHOT.jar(jar包名)
注意点:
取消掉cmd的快速编辑模式



