spring boot开发REST接口
Posted Code Job
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了spring boot开发REST接口相关的知识,希望对你有一定的参考价值。
1.配置pom.xml文件的<parent>和<depencencies>,指定spring boot web依赖
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.4.1.RELEASE</version> <relativePath /> <!-- lookup parent from repository --> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </dependency> <dependency> <groupId>com.wangxiaobao</groupId> <artifactId>wxb-common</artifactId> <version>1.0-SNAPSHOT</version> </dependency> </dependencies>
2.AppMain(可以随意起名)类
@SpringBootApplication public class AppMain { public static void main(String[] args) { SpringApplication.run(AppMain.class, args); } }
3.RestController 实现简单的字符串倒序逻辑。
@RestController public class TestService { @PostMapping(value = "/test") public String test(String input) { return new StringBuffer(input).reverse().toString(); } }
4.启动AppMain,Run as Java Application.测试成功(使用post-man):
以上是关于spring boot开发REST接口的主要内容,如果未能解决你的问题,请参考以下文章
spring boot:使接口返回统一的RESTful格式数据(spring boot 2.3.1)