使用Spring REST(primeng)在Angular 2中显示LocalDateTime

时间:2017-01-26 12:03:01

标签: spring rest angular java-8 localdate

我在项目Spring中使用Java 8日期时间, 但是当我显示那个日期时,我有:[object Object]

服务器:

class Person {
   LocalDateTime dateCreation;
   ...
}

@RestController
public class PersonController {
    @RequestMapping(value ="/getPerson", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public List<A> getPerson() {
        return personRepository.findAll();
    }
    ....

客户:

ngOnInit() {
        this.PersonService.getPersons().subscribe(persons => this.persons = persons);
    }

export class Person {
    ....
    dateCreation:Date;
}

和person.html:

<p-dataTable [value]="persons" ...>
  <p-column field="dateCreation" header="DateCreation" [sortable]="true">
        <template let-col let-person="rowData" pTemplate="body">
              {{person.dateCreation|date}}
        </template>
  </p-column>

1 个答案:

答案 0 :(得分:1)

感谢pdem,这个链接解决了我的问题 我正在使用:

@JsonDeserialize(using = LocalDateDeserializer.class)
@JsonFormat(pattern="dd/MM/yyyy hh:mm")
private LocalDateTime dateCreation = ...