SpringWebMVC - - Search Data with @ModelAtribute

0

Hello, I have the following method:

@RequestMapping(value = "/pesquisa", method = RequestMethod.POST)
public String pesquisa(@ModelAttribute("relSintetico") @Valid RelSintetico relSintetico, BindingResult bindingResult) {

    Timestamp dataInicial =  relSintetico.getDataInicial();

    Timestamp dataFinal = relSintetico.getDataFinal();

    System.out.println("Pesquisando");
    System.out.println(dataInicial);


    List<VE_RelResumoArrecadacao> relatorio = repositorioSintetico.findByDataOperacao(dataInicial, dataFinal);

    System.out.println("Pesquisado!");
    System.out.println(relatorio.size());


    return "sintetico.relatorios.tiles";
}

This method takes the relational modelAtribute from the page below:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>

Synthetic Report


                                                                                                                                                                                                                         

This is the class RelSynthetic Model:

package br.com.apasi.spring.dominios;

import java.io.Serializable; import java.sql.Timestamp;

import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Table;

@Entity @Table (name="RelSintetico", catalog="Pedagio", schema="dbo") public class RelSintetico implements Serializable {

/**
 * 
 */
private static final long serialVersionUID = 1L;

@Id
@Column(name = "IdRelSintetico")
private Integer idRelSintetico;

@Column(name = "DataInicial")
private Timestamp dataInicial;

@Column(name = "DataFinal")
private Timestamp dataFinal;

public Integer getIdRelSintetico() {
    return idRelSintetico;
}

public void setIdRelSintetico(Integer idRelSintetico) {
    this.idRelSintetico = idRelSintetico;
}

public Timestamp getDataInicial() {
    return dataInicial;
}

public Timestamp getDataFinal() {
    return dataFinal;
}

public void setDataInicial(Timestamp dataInicial) {
    this.dataInicial = dataInicial;
}

public void setDataFinal(Timestamp dataFinal) {
    this.dataFinal = dataFinal;
}

}

But the method returns null for getDataInitial and getDataFinal ... Is there anything to do with date conversion? or am I getting this Model data wrong?

    
asked by anonymous 31.08.2018 / 21:31

1 answer

1

Places the @org.springframework.format.annotation.DateTimeFormat annotation in the date attributes by reporting the format, adding javax.persistence.Temporal and changing the timestamp type to java.util.Date as in the example below:

@DateTimeFormat(pattern = "dd/MM/yyyy")
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "DataInicial")
private Date dataInicial;

@DateTimeFormat(pattern = "dd/MM/yyyy")
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "DataFinal")
private Date dataFinal;
    
31.08.2018 / 22:01