我正在使用Spring Boot和Spring Data Rest构建RESTful API。我想以json响应格式作为时间戳记。目前,我的答复是:
{ "firstName": "An", "lastName": "Nguyen", "createdDate": "2016-04-17T03:25:44.000+0000" }
我希望它是:
{ "firstName": "An", "lastName": "Nguyen", "createdDate": "1469346389" }
我怎样才能做到这一点?需要重新配置什么?
我的模特:
@Entity @Table(name = "users") public class User extends AbstractEntityimplements UserDetails { @Column(name = "first_name", length = 50) private String firstName; @Column(name = "last_name", length = 50) private String lastName; @Column(name = "created_date") private Date createdDate = new Date(); ..... }
我的资料库:
@Transactional @RestResource(path = "users") public interface UserRepository extends PagingAndSortingRepository, JpaSpecificationExecutor { User findByUsername(@NotNull String username); }
谢谢你的帮助。
希望此注释可以为您提供帮助:
@JsonFormat(shape = JsonFormat.Shape.NUMBER)