课程: Java for All Platforms: Desktop, Web, and Mobile Development
今天就学习课程吧!
今天就开通帐号,24,700 门业界名师课程任您挑!
Building APIs - Java教程
课程: Java for All Platforms: Desktop, Web, and Mobile Development
Building APIs
- [Instructor] Now, we're going to build a simple API using the Spring Framework. The first thing that we need to do is call out this class as a REST controller, which will enable us to be able to hit endpoints and return data from the server. Under the @SpringBootApplication annotation, type @RestController, then we're going to create a method that will return a value, and this is the great thing about Spring. We can create an API with just a few lines of code. The first thing we needed to define in the API is the endpoint. So we're going to go to the root of the server, slash, something. So to define our endpoint, we use this annotation called GetMapping. So type @GetMapping and then in parentheses, the endpoint name, which will be /hello in this case. Just like that, and then we define a public method that returns some kind of data. So public, String, hello and in the parenthesis, what we're going to do is take a value…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。