fastjson strong turn as a time stamp solutions datatime

When the output fastjson json object will automatically convert the format of time stamp, available online ideas

1. rewriting json implementation class
2. In the entity class field corresponding to annotate @JSONField (format = "yyyy-MM -dd HH: mm: ss") // FastJson package using annotations
3.JSON.toJSONStringWithDateFormat (data, " yyyy-mM-dd HH: mm : ss ")

When the map by my side so there is no entity class, said it may be a third way to solve the problem, but the string does not meet the third way json output, then add a layer of conversion, to solve the problem

@RequestMapping("activityListApi.htm")
    @ResponseBody
    public JSONObject activityListApi() {
        JSONObject jsonObject = new JSONObject();
        HashMap<String, String> map = new HashMap<>();
        List<Map> list = miniProgramActivityService.getMiniProgramActivityList(map);
        jsonObject.put("code", 1);
        jsonObject.put("data", JSON.parse(JSONObject.toJSONStringWithDateFormat(list,"yyyy-MM-dd HH:mm:ss.SSS")));
        jsonObject.put("message", "活动列表请求成功!");
        return jsonObject;
    }

The above results were as follows

{
    "code": 1,
    "data": [
        {
            "start_time": "2019-06-01 00:00:00.000",
            "icon_img": "http://thirdwx.qlogo.cn/mmopen/vi_32/DYAIOgq83eoQYiaktFqPGp1IChYYQzWONZODQ2s3AKu6vDJ1gyPcT6m2StZOylpOBPQDdrx2LbxSAoibmvWnTgeQ/132",
            "create_time": "2019-06-04 03:46:53.000",
            "name": "优惠券活动",
            "end_time": "2019-06-30 00:00:00.000",
            "bg_img": "http://thirdwx.qlogo.cn/mmopen/vi_32/DYAIOgq83eoQYiaktFqPGp1IChYYQzWONZODQ2s3AKu6vDJ1gyPcT6m2StZOylpOBPQDdrx2LbxSAoibmvWnTgeQ/132",
            "id": 1,
            "sort": 1,
            "desc": "优惠券活动,没人限领两张",
            "status": 1
        }
    ],
    "message": "活动列表请求成功!"
}

Reproduced in: https: //www.jianshu.com/p/3990d5d283c4

Guess you like

Origin blog.csdn.net/weixin_33777877/article/details/91215934