在第一篇(https://blog.csdn.net/codingToMaster/article/details/94354180)的基础上,编写实体类Student:
package com.huawei; public class Student { private int id; private String name; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } }
在HelloController中添加获取student的方法:
/** * springBoot默认使用的json解析框架是jackson * @return */ @RequestMapping("student") public Student getDemo() { Student student = new Student(); student.setId(1); student.setName("张三"); return student; }
运行: