1

我在项目 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>
4

1 回答 1

1

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

@JsonDeserialize(using = LocalDateDeserializer.class)
@JsonFormat(pattern="dd/MM/yyyy hh:mm")
private LocalDateTime dateCreation = ...
于 2017-01-27T17:48:29.173 回答