1 启动类
@RestController
@SpringBootApplication
public class AppRun {
public static void main(String[] args){
SpringApplication.run(AppRun.class, args);
}
}
2 Model类
import java.util.Date;
public class StudentModel {
private Integer id;
private String name;
private Date birth;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Date getBirth() {
return birth;
}
public void setBirth(Date birth) {
this.birth = birth;
}
}
3 控制类
import java.util.Date;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/student")
public class StudentController {
@RequestMapping("/getStudent")
public StudentModel getStudent(){
StudentModel student = new StudentModel();
student.setId(1);
student.setName("Jason");
student.setBirth(new Date());
return student;
}
}
说明:Spring Boot也是引用了JSON解析包Jackson,那么自然我们就可以在Demo对象上使用Jackson提供的json属性的注解,对时间进行格式化,对一些字段进行忽略等等
4 访问
Paste_Image.png