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):
如果,您认为阅读这篇博客让您有些收获,不妨点击一下右下角的【推荐】。
如果,您希望更容易地发现我的新博客,不妨点击一下左下角的【关注我】。
如果,您对我的博客所讲述的内容有兴趣,请继续关注我的后续博客,我是【Arli】。
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。