<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.9.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies>
/** * @SpringBootApplication 標註主程序:說明此類是 SpringBoot 應用 */ @SpringBootApplication public class HelloWorldMainApplication { public static void main(String[] args) { //springboot 應用啓動 SpringApplication.run(HelloWorldMainApplication.class, args); } }
@Controller public class HelloController { @ResponseBody @RequestMapping("/hello") public String hello(){ return "Hello World"; } }
http://localhost:8080/helloweb
頁面響應:Hello Worldspring
pom 文件添加以下內容springboot
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>
在 IDEA 右側邊欄,maven --> lifecycle--運行 package 命令進行打包,而後啓動打包後的 jar 文件,訪問 http://localhost:8080/hello 便可;app