DTO可以有实例格式数据方法吗?

时间:2012-11-02 13:07:52

标签: java methods format instance dto

我的问题是:DTO可以使用实例格式数据方法吗?

例如:

public class CosasDTO{

  String cosa_nombre;
  String cosa_apellido;
  String cosa_fecha;


   ///-------------------------Constructor

    public CosasDTO(CosaExtrema cExtrema) {

        cosa_nombre = cExtrema.getName();
        cosa_apellido = cExtrema.getApellido();
        cosa_fecha = formatDate(cExtrema.getDate());
    }

    private String formatDate(Timestamp fechaHora) {

    String horaFechaFormateadas = new SimpleDateFormat("yyyyMMddhhmmss").format(fechaHora);

        return horaFechaFormateadas;
    }
}

在DTO中实例化格式化方法是否正确?

1 个答案:

答案 0 :(得分:2)

格式化/本地化是表示(端点)层的责任,因此通常没有。在持久性的同时,您可以使用UTC保存日期/时间,并根据用户的偏好在表示层中对其进行格式化。