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 <= #{startday} <!-- 前端Body参数 --!>
</if>
<if test="endday!=null and endday!=''">
and endday >= #{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时间转毫秒的更多相关文章
- Thymeleaf前后端传值 页面取值与js取值
参考: Thymeleaf前后端传值 页面取值与js取值 Thymeleaf 与 Javascript Thymeleaf教程 (十二) 标签内,js中使用表达式 目的: 后端通过Model传值到前端 ...
- ajax学习----json,前后端交互,ajax
json <script> var obj = {"name": "xiaopo","age": 18,"gender ...
- springmvc前后端传值
@pathvible 后端传值(rest风格) exp: @requestMapping("/view/{userId}") public String getiew(@Parth ...
- SSM框架用JSON进行前后端数据传输
一个根据用户id查找用户信息的简单功能,使用JSON进行数据的传输 前端代码 这里用bootstrap做简单的样式美化,中间留了个div用来异步的显示查询结果,ajax进行前端的数据传输(class内 ...
- SpringMVC踩坑3——前后端传值问题
在前端页面点击修改,同时把需要修改的ID传到后端,后端根据ID去修改具体数据 这是前端代码 <a href="${pageContext.request.contextPath}/bo ...
- springmvc前后端传值总结
1 前端向后端传参 1.1 普通方式传参 1.1.1 页面 参数需要解析成json对象:JSON.parse(JSON.stringify(query)) $.getJ ...
- JQuery ajax 前后端传值介绍
https://jingyan.baidu.com/album/ca41422f0bf08e1eae99ed04.html?picindex=5 现在我们话不多说,开始仔细讲解一下我们ajax内部传递 ...
- Ajax与json在前后端中的细节解惑
ajax请求JSON Thinkphp中对是否为Ajax的判断,在TP3.2开发手册中有这么一段:“需要注意的是,如果使用的是ThinkAjax或者自己写的Ajax类库的话,需要在表单里面添加一个隐藏 ...
- 前端传json数组 ,后端的接收
前端传输: var updateGoodsId=$(this).val();//get id var updateGoodsPrice=$("#IngoodsPrice"+upda ...
随机推荐
- vue 安装之路
vue 来源 1.安装node.js(http://www.runoob.com/nodejs/nodejs-install-setup.html) 2.基于node.js,利用淘宝npm镜像安装相关 ...
- Mysql8.0安装步骤
Mysql8.0安装步骤 2018年05月10日 14:39:05 93年的香槟 阅读数:19628 标签: mysql 更多 个人分类: 数据库 版权声明:本文为博主原创文章,未经博主允许不得转 ...
- Centos 7.3下 Linux For SQL Server安装及配置介绍
Centos 7.3下 Linux For SQL Server安装及配置介绍 高文龙关注13人评论2828人阅读2017-03-05 21:46:21 Centos 7.3下Linux For SQ ...
- spring springMvc spring-boot spring-cloud分别是什么
本文来源于:克己习礼成仁 的<spring springMvc spring-boot spring-cloud分别是什么> 什么是spring 关于spring的定义无论是从官方还是 ...
- Confluence 6 Oracle 连接问题解决
如果 Confluence 提示没有 class 文件,你可能将你的 JDBC 驱动放置到了错误的文件夹. 下面的页面包含了一些你在使用 Oracle 数据库连接的时候可能会遇到的常见问题,请参考: ...
- Confluence 6 链接到其他应用
应用链接(Application Links)有时候也被称为 "AppLinks" 是一系列测插件能够允许你在 Atlassian 的应用中互相链接.链接 2 个应用能够允许你在 ...
- CSS在线字体库,外部字体的引用方法@font-face
@font-face是CSS3中的一个模块,他主要是把自己定义的Web字体嵌入到你的网页中,随着@font-face模块的出现,我们在Web的开发中使用字体不怕只能使用Web安全字体,你们当中或许有许 ...
- vuecli3初尝试(转载)
https://segmentfault.com/a/1190000016423943 在vue-cli3中安装element-ui 其中两种方式自己选择 格式化代码 使用yarn lint命令自动格 ...
- jq插件模板
!(function($,window, document, undefined){ function Plugin(ele,options){ //默认参数设置 this.defaults={ pa ...
- string标准C++中的的用法总结(转)
转自:http://www.cnblogs.com/xFreedom/archive/2011/05/16/2048037.html 相信使用过MFC编程的朋友对CString这个类的印象应该非常深刻 ...