WIN10+IDEA2021+Maven3.6.3+JDK1.8
选择Spring和Java版本
添加依赖
package com.example.demo.controller;import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
@RequestMapping("/war3")
public class HeroController {@RequestMapping("/heroes")public String getHeroes() {System.out.println("Jaina Proudmoore\nArthas Menethil");return "Jaina Proudmoore\nArthas Menethil";}
}
value
指定请求URL;method
指定请求方式,默认GET@RequestMapping(value="/a",method=RequestMethod.GET)
可简写为@RequestMapping("/a")
/war3/heroes
点击绿色三角进行测试
浏览器访问
http://localhost:8080/war3/heroes
打包
在WIN10或CentOS7上的运行命令都如下
java -jar demo2-0.0.1-SNAPSHOT.jar
新建工程后,pom.xml
内容如下
4.0.0 org.springframework.boot spring-boot-starter-parent 2.7.6 com.example demo2 0.0.1-SNAPSHOT demo2 Demo project for Spring Boot 1.8 org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-test test org.springframework.boot spring-boot-maven-plugin
starter
parent
英 | 🔉 | 中 |
---|---|---|
starter | /ˈstɑːrtər/ | n. adj. (机器或引擎的)启动装置;发车信号;起步时使用的 |
artifact | /ˈɑːrtɪfækt/ | n. 历史文物;非自然存在物体;遗物 |
新建工程后,会自动创建@SpringBootApplication
,可以启动SpringBoot程序
package com.example.demo;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication
public class Demo2Application {public static void main(String[] args) {SpringApplication.run(Demo2Application.class, args);}
}
org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-tomcat
org.springframework.boot spring-boot-starter-jetty
上一篇:LLVM浅析