Good morning everyone! I'm trying to return a formatted date, it's in the database as date, but for return it could be a msm string. Some friends have indicated two modes, creating a new method for formatting or using java 1.8's LocalDate.
The problem is that since I'm a beginner and I get lost in some things, I do not know how to do it to return getFormatado ... I'm going through the code that I think will explain better ... I'm having a return with Hibernate ... .package model;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import org.hibernate.annotations.ForeignKey;
@Entity
@Table(name ="fornecedor")
public class Fornecedor extends Pessoa{
@Column
private Integer codigo;
@Column
private String pessoaContato;
@Column
private String cnpj;
@Column
private Date inicioAtividades;
// ********* Omiti os Get and Setters desnecessários pra pergunta :)
public Date getInicioAtividades() {
return inicioAtividades;
}
public void setInicioAtividades(Date inicioAtividades) {
this.inicioAtividades = inicioAtividades;
}
// ********** Pediram pra eu acrescentar este método aqui, abaixo
public String getInicioFormatado() throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
String data = sdf.format(inicioAtividades);
return data;
}
The problem is, how do I call this kra, since in hibernate it looks like this:
public List<Fornecedor> listarFornecedores() {
session = HibernateUtil.getSessionFactory().openSession();
List<Fornecedor> listaFornecedores = new ArrayList<Fornecedor>();
query = session.createQuery("FROM Fornecedor");
listaFornecedores = query.list();
session.close();
return listaFornecedores;
Can anyone give me this light there? Thank you guys!!!