(1)编写一个实体类Demo
package me.shijunjie.entity; public class Demo {
private long id; private String name; public long getId() {
return id;
} public void setId(long id) {
this.id = id;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} }
(2)编写Controller
package me.shijunjie.controller; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import me.shijunjie.entity.Demo; @RestController
@RequestMapping("/demo")
public class DemoController { @RequestMapping("/testDemo")
public Demo getDemo(){ Demo demo = new Demo(); demo.setId(1); demo.setName("Shijunjie"); return demo; }
}
(3)运行并测试