Java angular5中的日期格式错误
在后端使用spring boot时,我有一个称为干预的实体:Java angular5中的日期格式错误,java,spring,spring-boot,angular5,Java,Spring,Spring Boot,Angular5,在后端使用spring boot时,我有一个称为干预的实体: import com.fasterxml.jackson.annotation.JsonBackReference; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import org.springframework.format.annotation.DateTimeFormat; import java
import com.fasterxml.jackson.annotation.JsonBackReference;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
@Entity
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Intervention implements Serializable {
@Id @GeneratedValue
private Long Id;
private String objet;
@DateTimeFormat(pattern = "dd/MM/yyyy")
private Date date;
@Column(columnDefinition="BOOLEAN DEFAULT false")
private boolean valid;
@ManyToOne
@JoinColumn(name = "Id_AppUser")
@JsonBackReference(value="appuser-intervention")
private AppUser appUser;
@ManyToOne
@JoinColumn(name ="Id_AppDevlopper")
@JsonBackReference(value="appuser-intervention-devlopper")
private AppUser app ;
}
我在前端使用angular5,当我想保存一个新的干预时,一切都很好,这是在phpmyadmin中保存日期的方式:
2018-06-22 13:10:2
当我尝试在angular5进行干预时,日期如下所示:
1529669422000
这是spring中的控制器:
干预.组件.ts
.component.html
我不明白为什么它看起来像这样,知道吗?要显示dd-mm-yyyy您需要使用
{{c.date | date : 'dd-MM-yyyy'}}
试试{c.date | date}}另外,在许多语言中,date是一个关键字/保留字,我会避免使用date作为变量名(类似objectDate或createdDate的东西也可以),我想这是因为Spring使用Jackson Marshaller来编组/解编JSON。默认情况下,Jackson Marshaller会以毫秒的形式发送日期谢谢你们两位的宝贵意见,现在显示的是2018年6月22日,我可以将其更改为2018年6月22日吗?{{c.date}date:'dd-MM-yyyy'}
getClientsIntervention(page:number , size:number , idClient:number){
if(this.authService.getToken()==null) {
this.authService.loadToken();
}
return this.http.get(this.host+
"/clientsintervention?size="+size+"&page="+page+"&id="+idClient,{headers:new HttpHeaders({'Authorization':this.authService.getToken()})});
}
interventionsclients(){
this.intervService.getClientsIntervention(this.page,this.size,this.id)
.subscribe((data:any)=>{
this.pageIntervention = data;
},err=>{
console.log('there is an error lady ! ');
})
}
<table class="table table-striped">
<thead>
<tr>
<th>Numéro</th>
<th>objet</th>
<th>date</th>
<th>Etat</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let c of pageIntervention?.content">
<td>{{c.id}}</td>
<td>{{c.objet}}</td>
<td>{{c.date}}</td> //The problem of showing date format is here !!
<td>
<button type="button" class="btn btn-warning" [hidden]="c.valid" >Non valide</button>
<button type="button" class="btn btn-primary" [hidden]="!c.valid" (click)="getDevlopperInformation(c.id)">Valide</button>
</td>
</tr>
</tbody>
</table>
saveIntervention(){
this.date = new Date();
this.intervSevice.saveInterv( this.sujet, this.date , this.selectedTypeId , this.selectedProjectId , this.idClient)
.subscribe((data:any)=> {
swal("operation réussi !", "Great ! !", "success");
this.router.navigate([ '../list' ], { relativeTo: this.activatedRoute });
},err=>{
console.log('this is error');
})
{{c.date | date : 'dd-MM-yyyy'}}