Spring Cloud 2.2 创建Controller
1.开发环境:
1. JDK 1.8
2. IntelliJ IDEA
2.开发步骤:
1. 在2.1代码基础上新建 MyController.java
@RestController
public class MyController {
@GetMapping("/hello")
@ResponseBody
public String hello() {
return "Hello World";
}
@RequestMapping(value = "/person/{personId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public Person findPerson(@PathVariable("personId") Integer personId) {
Person p = new Person();
p.setId(personId);
p.setName("Crazyit");
p.setAge(30);
return p;
}
}
2. 启动 MyApplication.java
3-1.验证 /hello
3-2.验证 /person/{personId}
3.源码:
项目源码路径:02/env-test
Spring Cloud 全部源码 百度云:https://pan.baidu.com/s/1pTQC-MXDAoHqv0BU79uyaw