Time format time to JSON is changed to normal string time 20170519

Source: Internet
Author: User


public class Jsondatevalueprocessor implements Jsonvalueprocessor {
Private String format = "YYYYMMDD";

Public Jsondatevalueprocessor () {
Super ();
}

Public jsondatevalueprocessor (String format) {
Super ();
This.format = format;
}

@Override
public Object Processarrayvalue (object Paramobject,
Jsonconfig paramjsonconfig) {
return process (Paramobject);
}

@Override
public Object Processobjectvalue (String paramstring, Object Paramobject,
Jsonconfig paramjsonconfig) {
return process (Paramobject);
}


Private object Process (object value) {
if (value instanceof Date) {
SimpleDateFormat SDF = new SimpleDateFormat (format, Locale.china);
return Sdf.format (value);
}
return value = = null? "": value.tostring ();
}
}

That's what the controller says.
list<t> list = Service.queryfromwtxs ();   Query to the Entity class table to display
Jsonconfig jsonconfig = new Jsonconfig ();
Jsonconfig.registerjsonvalueprocessor (Date.class, New Jsondatevalueprocessor ());
Jsonarray Jsonarray22=jsonarray.fromobject (list,jsonconfig); The Entity class table turns into JSON; time format in time-to-variable converters
sum = List.size ();
Mv.addobject ("list", jsonArray22); Use "List" in JSP

Time format time to JSON is changed to normal string time 20170519

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.