sql - 当我从我的 sql 到我的 spring-boot 应用程序时,为什么我的 LocalDateTime 变量改变了 5 小时?
问题描述
每次通过查询我的 sql 表得到它时,我的 LocalDateTime 变量都会更改 5 小时。如果我有一个从上午 9:30 开始的时间,那么它将返回上午 4:30 作为时间。 每当我尝试通过在我的 repo 中查询来从我的 sql 表中获取日期时间类型字段时
@Query(value = "SELECT start FROM course_section WHERE crn = ?1", nativeQuery = true)
LocalDateTime getStartTimeByCrn(int term);
@Query(value = "SELECT end FROM course_section WHERE crn = ?1", nativeQuery = true)
LocalDateTime getEndTimeByCrn(int term);
我将其发送给我的服务
//Method to get the Start time for Section class
public LocalDateTime getStartTimeByCrn(int term) {
LocalDateTime start = (LocalDateTime) repo.getStartTimeByCrn(term);
return start;
}
//Method to get the End time for the Section class
public LocalDateTime getEndTimeByCrn(int term) {
LocalDateTime end = (LocalDateTime) repo.getEndTimeByCrn(term);
return end;
我的控制器使用这些方法
@RequestMapping(value = "/accepted", method = RequestMethod.POST)
public String addSchedule(@ModelAttribute("schedule") Schedule schedule) throws JsonProcessingException {
int crn = schedule.getCrn();
Section sec = new Section();
//set all the attributes of Section object
sec.setStart(service.getStartTimeByCrn(crn));
sec.setEnd(service.getEndTimeByCrn(crn));
// String stringToJson = new JsonMapper().writeValueAsString(sec);
service.save(sec);
System.out.print( sec.getStart() + " is the subject!!!");
return "calendar";
}
当我从我的 sql 表中通过 crn 获取它时,我的 datetime 变量将连续更改五个小时。其他都没有改变,年、月、日、分或秒都没有改变。
我的 @Entity LocalDateTime 变量看起来像
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss")
private LocalDateTime start;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss")
private LocalDateTime end;
发生此错误似乎没有合乎逻辑的理由...
解决方案
推荐阅读
- mysql - 根据连接 4 个表更新一个表
- python - 如何编写一个在第一次回显后不断开连接的python回显服务器?
- elasticsearch - Elasticsearch - 按分数修剪结果的最佳方法?
- python - 列表的python交集,但没有相同的索引
- javascript - 是否有替换 JSON 值的流程/实践?具体来说,将 API URL 替换为 API 提供的值
- python - 无法连接到测试服务器。“ERR_CONNECTION_REFUSED”
- airflow - 为 MLEngine 气流算子提供参数
- spring-security - 在 Spring Weblux 中为给定路径禁用身份验证和 csrf?
- python - 将数据集分组为所选变量差异最小的两组
- xcode - 你怎么知道一个复选框被选中来执行一个功能