• 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
  • 相关阅读:
    理解css中min-width和max-width,width与它们之间的区别联系
    html实现时间轴_纯css实现响应式竖着/垂直时间抽布局效果
    web页面的重构和回流【转载】
    介绍web开发中实现会话跟踪的常用技术方法
    web标签语义化的理解_web语义化是什么意思
    从浏览器地址栏输入url到显示页面的步骤(以HTTP为例)
    H5调用手机的相机/摄像/录音等功能 _input:file的capture属性说明
    相邻元素之间的margin合并问题
    HTML连载33-背景定位
    Java连载22-for循环
  • 原文地址:https://www.cnblogs.com/yanchaohui/p/9950522.html
Copyright © 2020-2023  润新知