我正在使用 Spring Data JPA,我有一个如下表:
public class Apk {
@Temporal(TemporalType.TIMESTAMP)
@Column
private java.util.Date creationTime;
}
我的 DBMS 是 MySQL5.x,上面的列是在其中定义的 datetime 类型。我只是在存储库类中调用 findAl() 方法扩展 PaginAndSortingRepository。
public interface ApksRepository extends PaginAndSortingRepository<Apk, Long>{
}
public class ApksServiceImpl implements ApksService {
public PagingRes<Apk> findAll(PageInfo pageInfo){
PaginRes<Apk> result = new PagingRes<Apk>();
Page page = apksRepos.findAll(pageInfo.toPageRequest());
result.fromPage(page);
return result;
}
}
public class PageInfo {
private int page;
private int rp;
private String sortname;
private String sortorder;
private String query;
private String qtype;
//getters and setters
public PageRequest toPageRequest() {
Sort.Direction direction = Sort.Direction.ASC;
if (sortorder!=null && "DESC".equals(sortorder))
direction = Sort.Direction.DESC;
return new PageRequest(page-1, rp, direction, sortname);
}
}
public class PagingRes<T> {
private long total;
private int page;
private int rowPerPage;
private List<T> rows;
//getters and setters
public PagingRes<T> fromPage(Page page) {
this.page = page.getNumber();
this.rowPerPage = page.getSize();
this.total = page.getTotalElements();
this.rows = page.getCotent();
return this;
}
}
我试图在表中显示数据,包括列,但是当我这样做时,列显示为长类型。我想以格式“dd-MM-yyyy hh:mm:ss”显示列。我怎样才能做到这一点?
提前致谢。