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 ...
随机推荐
- CM5.15安装kafka
cm主节点执行: [root@dip001 kafka]#ll KAFKA-.jar KAFKA---el7.parcel KAFKA---el7.parcel.sha1 manifest.json ...
- 大数据python词频统计之hdfs分发-cacheArchive
-cacheArchive也是从hdfs上进分发,但是分发文件是一个压缩包,压缩包内可能会包含多层目录多个文件 1.The_Man_of_Property.txt文件如下(将其上传至hdfs上) ha ...
- better-scroll项目中遇到的问题
1.在项目中发现个问题,用better-scroll实现的轮播图和页面滚动条俩个效果一起出现的时候,当鼠标或手指放在轮播图位置的时候,上下滚动的时候,页面滚动条不动 发现最新的版本就会出这个问题,就是 ...
- 手机端上点击input框软键盘出现时把input框不被覆盖,显示在屏幕中间(转)
转载地址:https://www.cnblogs.com/xzzzys/p/7526761.html 1 用定位为题来解决var oHeight = $(document).height(); // ...
- Maven设置本地仓库路径
在maven文件下的settings.xml中添加<localRepository>F:\cppdy\repo</localRepository>(本地仓库路径)
- MySQL5.7.20安装过程报错CMake Error at cmake/boost.cmake:81 (MESSAGE):
MySQL在5.7版本及以后,都需要boots 库,所以需要先安装boots 步骤: 1.在/usr/local下创建 名为boots的目录 mkdir -p /usr/local/boots 2.进 ...
- maven依赖查找方法
http://mvnrepository.com 1. 搜索依赖库 2. 选择合适版本 3. 复制配置 点击合适的版本进入,负责maven配置: <dependency> ...
- js里添加的标签
js里添加的标签.网页加载此标签绑定的js函数时,由于没有标签,故无法执行函数. 例如: js中添加了一个button: html1 += "<td><button typ ...
- 如何获取jar包的在执行机上面的路径
背景: 最近在项目中遇到一个小问题, 几行代码就能解决了 String path = this.getClass().getProtectionDomain().getCodeSource().get ...
- IDEA新建模块