创建的两种方法:
1.可以从springboot官网创建下载,再在idea中打开
2.idea中集成了这个网站,注解使用idea创建一个springboot项目(一般用这种)
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <!--父项目--> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.6.3</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.kakafa</groupId> <artifactId>helloworld</artifactId> <version>0.0.1-SNAPSHOT</version> <name>helloworld</name> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> </properties> <dependencies> <!--web依赖:tomcat,dispatcherServlet,xml等--> <dependency> <groupId>org.springframework.boot</groupId> <!--所有的springBoot依赖名字都是以spring-boot-starter开头的--> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <!--打jar包插件--> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
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包试试看:
参考链接:https://www.cnblogs.com/banml/p/11767305.html