第一个SpringBoot程序
创建的两种方法:
- 1.可以从springboot官网创建下载,再在idea中打开
- 2.idea中集成了这个网站,注解使用idea创建一个springboot项目(一般用这种)
pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
4.0.0
org.springframework.boot
spring-boot-starter-parent
2.6.3
com.kakafa
helloworld
0.0.1-SNAPSHOT
helloworld
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
编写http接口
package com.kakafa.helloworld.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
//接口 http://localhost:8080/hello
@RequestMapping("/hello")
public String hello(){
return "helloworld!";
}
}
打包
运行测试后可用即可打包
打包成功,这个jar包就是一个接口程序(是一个可执行程序)
执行该jar包试试看:
jar包和war包的区别
参考链接: