zoukankan      html  css  js  c++  java
  • json数组,前后端传值问题,与data时间转毫秒

    从json数组到ArrayList

    Gson gson = new Gson();
    Car cars = gson.fromJson(result,new TypeToken<ArrayList<Car>>() {}.getType());

    从实体类到JSON字符串

    Gson gson = new Gson();
    String jsonBDID = gson.toJson(bdPushID);

    如何让你传递出来的对象数据时间显示正确

    如果我们通过id来对数据库进行查询。那么你返回给前台的数据是有问题的。

    问题数据:

    这里显示的时间不对
    "cretime": "2018-07-04T12:47:55.000+0000",
    "updatetime": "2018-07-04T12:47:55.000+0000",

    转换方式1

    @ResponseBody
    @RequestMapping(value = "/spaceinfo", method = RequestMethod.POST)
    public Result getSpaceObjInfo(@RequestParam("spaceid") String spaceid)
    {
        YksptSpace space = yksptSpaceService.selectById(spaceid);
        // 稍微转换一下,已解决时间的问题
        String spacejson = JSON.toJSONString(space);
        JSONObject resultObj = JSON.parseObject(spacejson);
        return Result.ok().put("result", spacejson);
    }

    转换方式2,在你的bean里面给你的时间,加上一个json注解

    @JsonSerialize对javabean进行json格式化
    
    @JsonSerialize(using=JsonDateSerializer.class)
    public Date getModtime() {
        return modtime;
    }

    这时候返回的数据就会显示正确

     "cretime": 1530708475000,
     "updatetime": 1530708475000,

     dao.xml层次转换毫秒方法

    CONCAT(
    UNIX_TIMESTAMP(startday),
    '000'
    ) AS startday

    dao.xml层次sql语句做if判断

    <where>
    1 = 1
    <if test="classid !=null ">
    and CONCAT(p.classid) regexp #{classid} <!--多条件查询写法:调用StringUtils工具包正则转换classid = StringUtil.preRegStr(classid); !列如 前端传classid:1;2;3  --!>
    </if>
    <if test="status==4 or status==null or status==''">
    and p.status = 05
    </if>
    <if test="usertype =='jdleader.user' or usertype =='jdorg.user'">
    and r.creusertype = #{usertype}
    </if>
    <if test="pname!=null and pname!=''">
    and pname LIKE CONCAT('%',#{pname},'%') 
    </if>
    <if test="startday!=null and startday!=''">
    and startday &lt;= #{startday} <!-- 前端Body参数 --!>
    </if>
    <if test="endday!=null and endday!=''">
    and endday &gt;= #{endday}
    </if>
    </where>
    ORDER BY startday DESC<!-- where 判断之后做排序 --!>

    后台日期转换:

        @InitBinder
        public void initBinder(WebDataBinder binder, WebRequest request) {
            
            //转换日期
            DateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));// CustomDateEditor为自定义日期编辑器
        }

    修改日期返回前端为毫秒:

     String spacejson = JSON.toJSONString(page);
                 JSONObject resultObj = JSON.parseObject(spacejson);
    sql写法
    CONCAT(UNIX_TIMESTAMP(f.cretime),'000') AS cretime
  • 相关阅读:
    webserver项目的知识点
    Java处理List集合数据进行分页展示
    Java导出Excel文件,在Wps上可以打开但是Office上打不开的问题
    Java导出Excel内容有问题_关于 NPOI 导出的 Excel 出现“部分内容有问题” 的解决方法
    java使用postman导出execl文件名一直为response.xls问题
    windows如何把已安装的nodejs高版本降级为低版本
    px,em,rem的区别(补充vh和vw的)
    arr=[];与arr.length=0;的区别
    微信小程序引用 iconfont
    MySQL存储过程使用动态表名
  • 原文地址:https://www.cnblogs.com/yanchaohui/p/9950522.html
Copyright © 2011-2022 走看看