我有一个日期为util.Date的域类。当我运行jpa方法时,从db中查找行。它返回long而不是实际日期。有人可以帮忙吗?
编辑:
域:
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import org.hibernate.annotations.Formula;
@Entity
public class Expense {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
int intTranId;
BigDecimal fltAmt;
Date dtDate;
....
/setter getter methods
存储库:
import java.util.Date;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import com.ext.domain.Expense;
@Repository
public interface ExpenseRepository extends CrudRepository<Expense, Integer>{
@Query("SELECT min(dtDate) as dtDate ,Max(dtDate) as dtDate FROM Expense")
Iterable<Date> getAvlRptDates();
@Query("SELECT monthYear FROM Expense group by Year(dtDate),Month(dtDate) order by Year(dtDate),Month(dtDate)")
Iterable<String> getAvlRptRecords();
Iterable<Expense> findAll();
}
findAll将值返回为
[{"intTranId":1064,"fltAmt":2.00,"dtDate":1454481056294,"monthYear":"2016-1","category":{"intCatId":5,"strCatName":"Grocery"}}]
答案 0 :(得分:1)
@Column(name = "DatabaseColumnName")
@DateTimeFormat(pattern = "YYYY-MM-DD")
@Temporal(TemporalType.DATE)
private Date dtDate;
请使用DateTimeFormat将您的日期DB映射到您的费用类实体