package org.hx.springboot_gson_demo14;import java.util.Date;publicclassUser{private String username;private Date birthday;public String getUsername(){return username;}publicvoidsetUsername(String username){this.username = username;}public Date getBirthday(){return birthday;}publicvoidsetBirthday(Date birthday){this.birthday = birthday;}}
新建UserController控制类
package org.hx.springboot_gson_demo14;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.RestController;import java.util.Date;@RestControllerpublicclassUserController{@GetMapping("/user")public User getUser(){
User user =newUser();
user.setUsername("hx");
user.setBirthday(newDate());return user;}}
创建User类package org.hx.springboot_gson_demo14;import java.util.Date;public class User { private String username; private Date birthday; public String getUsername() { return username; } public void setUsername(String userna