How to disply timdstamp column with specific format in Spring Data JPA -
i using spring data jpa , have table below:
public class apk { @temporal(temporaltype.timestamp) @column private java.util.date creationtime; }
my dbms mysql5.x , above column defined datetime type in it. call findal() method in repository class extends 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 , 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 , 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; } }
and trying display data in table including column when did it, column shown long type. wan display column in fomat 'dd-mm-yyyy hh:mm:ss'. how can this?
thanks in advance.
i knew jackson mapper json response giving weird result. after searching, used jsonserializer fix below:
entity class @jsonserialize(using=audateserializer.class) private java.util.date eventtime; custom serializer public class audateserializerextends jsonserializer<date> { @override public void serialize(date value, jsongenerator gen, serializerprovider provider) throws ioexception, jsonprocessingexception { dateformat formatter = new simpledateformat("dd-mm-yyyy hh:mm:ss"); jgen.writestring(formatter.format(value)); } }
now works fine. thanks.
Comments
Post a Comment