zoukankan      html  css  js  c++  java
  • spring框架中list(JSONArray)的date类型转json类型的string 【BaseController中的定義函數】


    /**
    *
    * 下一是date和time转换json的spring代码工具
    *
    *
    **/

    public class JsonDateValueProcessor implements JsonValueProcessor {

    private String format ="yyyy-MM-dd";
    private String format1 ="HH:mm:ss";

    public Object processArrayValue(Object value, JsonConfig config) {
    return process(value);
    }

    public Object processObjectValue(String key, Object value, JsonConfig config) {
    return process(value);
    }

    private Object process(Object value){

    /* if(value instanceof Date){
    SimpleDateFormat sdf = new SimpleDateFormat(format,Locale.UK);
    return sdf.format(value);
    }*/
    //下面如果把Time换成Date,输出结果就不一样了。试下有惊喜哦
    if(value instanceof Time){
    SimpleDateFormat sdf = new SimpleDateFormat(format1,Locale.UK);

    return sdf.format(value);

    }
    return value == null ? "" : value.toString();
    }
    }
    ×××××××××××××××××××××××××××××××××××××××××××××××××


    public void writePagination(int total,List list,HttpServletResponse response) throws IOException{

    //初始化工具
    JsonConfig jsonConfig = new JsonConfig();
    jsonConfig.registerJsonValueProcessor(Date.class , new JsonDateValueProcessor());

    //使用date和time转换json的spring代码工具
    if(null!=list) jarray = JSONArray.fromObject(list,jsonConfig);


    }

  • 相关阅读:
    压缩与解压
    Ubuntu下搭建yocto
    Ubuntu 1804 进入紧急模式
    How To Configure NFS Client on CentOS 8 / RHEL 8
    Install and Configure NFS Server on RHEL 8 / CentOS 8
    结构体大小的计算
    SQL语句对数据库调优常用
    用SQL语句操作数据库高级
    windows命令行操作mysql
    创建方便的csv格式文件
  • 原文地址:https://www.cnblogs.com/OP-RONG/p/4193352.html
Copyright © 2011-2022 走看看