SpringBoot编写一个简单的Rest服务

@RestController
public class HelloController implements HelloService {
    @Override
    public String hello(@RequestParam("name") String name) {
        return "Hello " + name;
    }
}

接口代码:

@RequestMapping("/test")
public interface HelloService {
    @RequestMapping(value = "/hello1", method = RequestMethod.GET)
    String hello(@RequestParam("name") String name);
}

代码很简单,通过springMVC注解在接口HelloService上声明Rest服务,HelloController被@RestController注解声明为一个Rest服务。

启动spring boot 就可通过浏览器访问http://localhost:8080/test/hello1?name=test得到返回Hello test。

猜你喜欢

转载自blog.csdn.net/ruoxiyun/article/details/86551942