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 ...
随机推荐
- Jquery分享插件
效果图如下: 代码如下: <!DOCTYPE HTML> <html style="padding-bottom: 54px;"> <head> ...
- 【MySql】Group By数据分组
GROUP BY 语句根据一个或多个列对结果集进行分组. 在分组的列上我们可以使用 COUNT, SUM, AVG,等函数. 因为聚合函数通过作用于一组数据而只返回一个单个值, 因此,在SELECT语 ...
- Confluence 6 数据导入和导出
Confluence 管理员和用户可以从各种方法向 Confluence 中导入数据.针对不同的导入方式,有关权限的要求也是不相同的.请参考页面 Import Content Into Conflu ...
- nodejs之crypto加密算法
示例 const crypto = require('crypto'); const hash = crypto.createHash('sha256'); hash.update('some dat ...
- java----AOP框架理解
面向切面编程: 通过动态代理+加配置文件 目的解耦 给主逻辑添加一些修饰功能,但是不在主逻辑代码中进行修改,有点类似python中的装饰器,调用方法还是是通过接口的那个类来调用: import jav ...
- AI-认证
AI-认证 做登录验证 #models.py class Users(models.Model): user=models.CharField(max_length=32) pwd=models.Ch ...
- HTML CSS JavaScript 工作笔记
1. onclick方法如何传递多个参数 "<a href='#' onclick=\"applied_status('" + ids + "', '&q ...
- python练习册0006
第 0006 题:你有一个目录,放了你一个月的日记,都是 txt,为了避免分词的问题,假设内容都是英文,请统计出你认为每篇日记最重要的词. import re import os def get_li ...
- WPF 对控件进行截图且不丢失范围(转载)
原文:Taking WPF “Screenshots” I was recently working on a Surface project at Microsoft (that will be s ...
- [转] 梦里Babel知多少(一)
平时开发中,经常需要用到ES6/ES7的语法.那么就需要用到Babel来对代码进行转码处理. 之前用Vue比较多,所以以Vue-cli作为参考来分析. 第一张图是几个月前的Vue-cli生成的 第二 ...