1. 创建一个springboot工程
可以参考springboot入门程序
2. 创建一个实体类
@Data //想相当于@Setter、@Getter和@ToString替代了setter、getter、toString方法 @AllArgsConstructor//全参数构造方法 @NoArgsConstructor//无参构造方法 public class User { private Integer id; private String name; private Date birth; }
3. 创建controller类
@RestController //相当于@Controller和@ResponseBody两个注解 public class UserController { @RequestMapping(value = "/getUser",method = RequestMethod.GET) public User getUser(){ return new User(1,"jxy",new Date()); } }
4. 实体类中注解的相关依赖
<dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.6</version> </dependency>
容易出现404路径错误,注意路径书写