从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

json数组,前后端传值问题,与data时间转毫秒的更多相关文章

  1. Thymeleaf前后端传值 页面取值与js取值

    参考: Thymeleaf前后端传值 页面取值与js取值 Thymeleaf 与 Javascript Thymeleaf教程 (十二) 标签内,js中使用表达式 目的: 后端通过Model传值到前端 ...

  2. ajax学习----json,前后端交互,ajax

    json <script> var obj = {"name": "xiaopo","age": 18,"gender ...

  3. springmvc前后端传值

    @pathvible 后端传值(rest风格) exp: @requestMapping("/view/{userId}") public String getiew(@Parth ...

  4. SSM框架用JSON进行前后端数据传输

    一个根据用户id查找用户信息的简单功能,使用JSON进行数据的传输 前端代码 这里用bootstrap做简单的样式美化,中间留了个div用来异步的显示查询结果,ajax进行前端的数据传输(class内 ...

  5. SpringMVC踩坑3——前后端传值问题

    在前端页面点击修改,同时把需要修改的ID传到后端,后端根据ID去修改具体数据 这是前端代码 <a href="${pageContext.request.contextPath}/bo ...

  6. springmvc前后端传值总结

    1      前端向后端传参 1.1    普通方式传参 1.1.1         页面 参数需要解析成json对象:JSON.parse(JSON.stringify(query)) $.getJ ...

  7. JQuery ajax 前后端传值介绍

    https://jingyan.baidu.com/album/ca41422f0bf08e1eae99ed04.html?picindex=5 现在我们话不多说,开始仔细讲解一下我们ajax内部传递 ...

  8. Ajax与json在前后端中的细节解惑

    ajax请求JSON Thinkphp中对是否为Ajax的判断,在TP3.2开发手册中有这么一段:“需要注意的是,如果使用的是ThinkAjax或者自己写的Ajax类库的话,需要在表单里面添加一个隐藏 ...

  9. 前端传json数组 ,后端的接收

    前端传输: var updateGoodsId=$(this).val();//get id var updateGoodsPrice=$("#IngoodsPrice"+upda ...

随机推荐

  1. ES的Query、Filter、Metric、Bucketing使用详解

    由于笔者在实际项目仅仅将ES用作索引数据库,并没有深入研究过ES的搜索功能.而且鉴于笔者的搜索引擎知识有限,本文将仅仅介绍ES简单(非全文)的查询API. 笔者原本打算在本文中介绍聚合API的内容,但 ...

  2. css中input框不可点击+首行缩进

    Css 1)text-indent::首行缩进 2)disabled="true"设置input框不可以点击 3)Css:xx!important:声明提前优先级最高..!impo ...

  3. Confluence 6 尝试从 XML 备份中恢复时解决错误

    错误可能是因为数据库突然不可访问而产生.也有可能是你备份文件有问题,你需要找到你 XML 备份文件中违反数据库规定的记录修改这个记录后再创建一个新的 XML 备份: 在实例开始恢复的时候,请按照下面的 ...

  4. Confluence 6 链接到其他应用

    应用链接(Application Links)有时候也被称为 "AppLinks" 是一系列测插件能够允许你在 Atlassian  的应用中互相链接.链接 2 个应用能够允许你在 ...

  5. js数组的实例方法sort() 排序方法的运用,不再只是.sort()

    1, sort() 不传回调函数的话,默认按照字母顺序(字符编码)的顺序进行排序. 2, sort() 通过传回调函数来控制从小到大的排序还是从大到小的排序: var arr = [1,23,5,6, ...

  6. 【CSS】Bootstrap中select2+popover冲突

    网上搜索得到: It changes the position because the position is based on the popover's dimansions and select ...

  7. SSM框架整合篇

    目录 SSM整合 框架搭建步骤 SSM整合 Author:SimpleWu github(已上传SSMrest风格简单增删该查实例):https://gitlab.com/450255266/code ...

  8. STL的注意事项

    template是一个泛化的:使用template时开始仅仅是声明,具体的例如:k<int> a;叫做实例化显式实例化:类似k<int>a:明确指出哪种类型:隐式实例化:类似k ...

  9. 直径上的乱搞 bzoj1999求树直径上的结点+单调队列,bzoj1912负权树求直径+求直径边

    直径上的乱搞一般要求出这条直径上的点集或者边集 bzoj1999:对直径上的点集进行操作 /* 给出一颗树,在树的直径上截取长度不超过s的路径 定义点u到s的距离为u到s的最短路径长度 定义s的偏心距 ...

  10. 用HBuilderX 打包 vue 项目 为 App 的步骤

    首先打包你的 vue 项目 生成 dist 文件夹,教程请移步  https://www.cnblogs.com/taohuaya/p/10256670.html 看完上面的教程,请确保 你是 将: ...