新闻资讯
Could not write JSON: java.sql.Timestamp cannot be cast to java.lang.String;date传递前端变成时间戳问题的报错解决
List<Map<String, String>> smokeBriefList = smokeBriefService.findSmokeBriefDataByDate(startTime, endTime);
List<Map<String,String>> findSmokeBriefDataByDate(@Param(“startTime”) String startTime, @Param(“endTime”) String endTime);
// 正确写法
List<Map<String, Object>> smokeBriefList = smokeBriefService.findSmokeBriefDataByDate(startTime, endTime);
List<Map<String,Object>> findSmokeBriefDataByDate(@Param(“startTime”) String startTime, @Param(“endTime”) String endTime);
start_time字段数据库数据类型是java.sql.Data,返回Map接收查询结果,接收时使用了List<Map<String,String>>接收结果集;list集合转为json时,时间戳转为字符串会报错,需要将接受结果集改为List<Map<String,Object>>。
xml文件:
<select id="findSmokeBriefDataByDate" resultType="java.util.HashMap">
select
p.prj_name,b.build_name,e.start_time,e.end_time,
s.total_cases,s.total_time,s.fail_cases,s.skip_cases,s.pass_rate,s.downtime,s.flashtime
from
tb_project p inner join tb_build b
on p.id = b.prj_id
inner join tb_test_event e
on b.id = e.build_id
inner join tb_report_smoke_brief s
on e.id = s.test_event_id
where
e.testtype_id = 2 and start_time >= #{startTime} and end_time < #{endTime}
order by e.start_time
</select>
解决date传递前端变成时间戳问题
在application.properties文件中添加:
#spring.jackson.serialization.write-dates-as-timestamps=true
spring.jackson.time-zone=GMT+8
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
回复列表