我页面上显示的日期格式有问题

时间:2019-02-01 14:27:20

标签: java html spring-boot derby

当用户进行搜索时出现问题,该对象随附的日期不是像dd-mm-yyyy这样的通用格式,例如,日期显示为“ 1548820800000”而不是“ 30-01” -2019“

过去,当我使用MySql DB时,日期可以正常工作,但是现在我修改了后端以使用Derby嵌入式DB,我不得不将日期更改为Timestamp,以避免Java代码中的错误

实体:

    package ControlTransferencias.wDatos;




    import java.sql.Timestamp;

    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import lombok.AllArgsConstructor;
    import lombok.Data;
    import lombok.NoArgsConstructor;


    /**
     *
     * @author juan.finol
     */
    @Entity
    @Data
    @AllArgsConstructor
    @NoArgsConstructor
public class Transferencias {

@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id;
private Long referencia;
private String beneficiario;
private String banco;
private Timestamp fecha;
private String notaAdicional;
private String descripcion;
private Long monto;
private String tipo;

public String getTipo() {
    return tipo;
}
public void setTipo(String tipo) {
    this.tipo = tipo;
}
public Long getReferencia() {
    return referencia;
}
public void setReferencia(Long referencia) {
    this.referencia = referencia;
}
public String getBeneficiario() {
    return beneficiario;
}
public void setBeneficiario(String beneficiario) {
    this.beneficiario = beneficiario;
}
public String getBanco() {
    return banco;
}
public void setBanco(String banco) {
    this.banco = banco;
}
public Long getId() {
    return id;
}
public void setId(Long id) {
    this.id = id;
}
public String getDescripcion() {
    return descripcion;
}
public void setDescripcion(String descripcion) {
    this.descripcion = descripcion;
}
public Timestamp getFecha() {
    return fecha;
}
public void setFecha(Timestamp fecha) {
    this.fecha = fecha;
}
public Long getMonto() {
    return monto;
}
public void setMonto(Long monto) {
    this.monto = monto;
}
public String getNotaAdicional() {
    return notaAdicional;
}
public void setNotaAdicional(String notaAdicional) {
    this.notaAdicional = notaAdicional;
}

     }

用于搜索的实体:

    package ControlTransferencias.wDatos;

    import java.sql.Timestamp;

      /**
       *
       * @author juan.finol
       */
    public class Consulta {
private Timestamp fecha1;
private Timestamp fecha2;
private String banco;
private String beneficiario;
private String tipo;

public String getBanco() {
    return banco;
}
public void setBanco(String banco) {
    this.banco = banco;
}
public String getBeneficiario() {
    return beneficiario;
}
public void setBeneficiario(String beneficiario) {
    this.beneficiario = beneficiario;
}
public String getTipo() {
    return tipo;
}
public void setTipo(String tipo) {
    this.tipo = tipo;
}
public Timestamp getFecha1() {
    return fecha1;
}
public void setFecha1(Timestamp fecha1) {
    this.fecha1 = fecha1;
}
public Timestamp getFecha2() {
    return fecha2;
}
public void setFecha2(Timestamp fecha2) {
    this.fecha2 = fecha2;
}

}

查询:

    @SuppressWarnings("unchecked")
@RequestMapping(value = "/transferencias/consultatodos", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
@CrossOrigin
@RequestScope
Collection<Transferencias> transferenciasConsultastodos(@RequestBody Consulta conf) throws JsonProcessingException {
    List<Transferencias> transl = new ArrayList<>();
    log.info("/transferencias/consultar");
    String Query = "Select trans from Transferencias trans";
    if (conf.getFecha1() != null && conf.getFecha2() != null) {
        java.util.Date date1 = new java.util.Date();
        java.util.Date date2 = new java.util.Date();
        date1 = conf.getFecha1();
        date2 = conf.getFecha2();
        Query = Query + " WHERE trans.fecha >= '" + date1 + "' AND trans.fecha<= '"+date2+"'";
         if (conf.getBanco() != null) {
            Query = Query + " AND trans.banco = '" + conf.getBanco() +"'";
        }
         if (conf.getBeneficiario() != null) {
            Query = Query + " AND trans.beneficiario = '" + conf.getBeneficiario() +"'";
        }
         if (conf.getTipo() != null) {
            Query = Query + " AND trans.tipo = '" + conf.getTipo() +"'";
        }
    }
    else {
        if (conf.getBanco() != null) {
            Query = Query + " WHERE trans.banco = '" + conf.getBanco() +"'";
            if (conf.getBeneficiario() != null) {
                Query = Query + " AND trans.beneficiario = '" + conf.getBeneficiario() +"'";
            }
            if (conf.getTipo() != null) {
                Query = Query + " AND trans.tipo = '" + conf.getTipo() +"'";
            }
        }
        else {
            if (conf.getBeneficiario() != null) {
                Query = Query + " WHERE trans.beneficiario = '" + conf.getBeneficiario() +"'";
                if (conf.getTipo() != null) {
                    Query = Query + " AND trans.tipo = '" + conf.getTipo() +"'";
                }
            }
            else {
                if (conf.getTipo() != null) {
                    Query = Query + " WHERE trans.tipo = '" + conf.getTipo() +"'";
                }
            }
        }
    }
    log.info("fecha 1: "+conf.getFecha1()+" fecha 2: "+conf.getFecha2());
    transl = em.createQuery(Query).getResultList();
    return transl;
}

前端表:

    <table>
                              <tr>
                                <th class="thth">Numero de Referencia</th>
                                <th class="thth">Tipo</th>
                                <th class="thth">Banco</th>
                                <th class="thth">Beneficiario</th>
                                <th class="thth">Monto</th>
                                <th class="thth">Nota Adicional</th>
                                <th class="thth">Descripcion</th>
                                <th class="thth">Fecha</th>
                              </tr>
                              <tr ng-repeat="r in resp">
                                <td class="tdtd">{{r.referencia}}</td>
                                <td class="tdtd">{{r.tipo}}</td>
                                <td class="tdtd">{{r.banco}}</td>
                                <td class="tdtd">{{r.beneficiario}}</td>
                                <td class="tdtd" ng-init="resp.total.monto = resp.total.monto + r.monto">{{r.monto}}</td>
                                <td class="tdtd">{{r.notaAdicional}}</td>
                                <td class="tdtd">{{r.descripcion}}</td>
                                <td class="tdtd" type="date">{{r.fecha}}</td>
                              </tr>
                              <tr>
                                  <td class="tdtd">Total: {{resp.total.monto}}</td>
                              </tr>
                              </table>

当用户添加新数据或按日期范围进行搜索时,发送的日期格式正确,但我想时间戳会更改日期格式,并向我显示日期,例如1548820800000,所以我想了解显示搜索结果时将其更改为正确格式的方法。

0 个答案:

没有答案