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 ...
随机推荐
- RedHat Linux关闭seLinux命令
Redhat使用了SELinux来增强安全,关闭的办法为: 1. 永久有效 修改 /etc/selinux/config 文件中的 SELINUX="" 为 disabled ,然 ...
- c# 图片插入Excel
引用COM:Microsoft Office 11.0 Object Library 引用类: using System; using System.Windows.Forms; u ...
- dict-test
#! -*- coding:utf-8 -*-"""键必须是唯一的,但值则不必len(dict) 计算字典元素个数,即键的总数str(dict) 输出字典,以可打印的字符 ...
- mysql5.7设置简单密码报错ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
注:本文来源于< mysql5.7设置简单密码报错ERROR 1819 (HY000): Your password does not satisfy the current policy r ...
- Confluence 6 数据库表-系统信息(System information)
这些表格有存储数据相关的状态和 Confluence 站点的相关配置信息. confversion 被用来在升级系统的时候确定那个数据库的版本应该使用,这个表格只对数据库升级有影响. pluginda ...
- vue.js 监听属性的学习/ 千米、米的转换 /时、分、秒 的转换
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- linux基础实操四
实操一: 1)为新加的硬盘分区,一个主分区大小为10剩余空间给扩展分区,在扩展分区上划分2个逻辑分别为5G 2)式化主分区为ext3系统 #mkfs.ext3 /dev/sdb1 3 将逻辑分区设置为 ...
- medir设置
setting中 MEDIA_URL="/media/"MEDIA_ROOT=os.path.join(BASE_DIR, "app01","medi ...
- 阿里云服务器配置SSL证书成功开启Https(记录趟过的各种坑)
环境: 阿里云云服务器 Windows Server 2008 标准版 SP2 中文版(趁1212优惠买的一年的水货配置) 阿里云购买的域名(已备案.已解析) 服务器:phpstudy:php5 ...
- 20165206第4次实验《Android程序设计》实验报告
20165206第4次实验<Android程序设计>实验报告 一.实验报告封面 课程:Java程序设计 班级:1652班 姓名:韩啸 学号:20165206 指导教师:娄嘉鹏 实验日期:2 ...