Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么当我从sql进入spring启动应用程序时,LocalDateTime变量会改变5个小时?_Sql_Spring Boot_Datetime_Jackson_Timezone - Fatal编程技术网

为什么当我从sql进入spring启动应用程序时,LocalDateTime变量会改变5个小时?

为什么当我从sql进入spring启动应用程序时,LocalDateTime变量会改变5个小时?,sql,spring-boot,datetime,jackson,timezone,Sql,Spring Boot,Datetime,Jackson,Timezone,我的LocalDateTime变量每次通过查询我的sql表得到它时都会更改5个小时。如果我的时间从上午9:30开始,那么它将返回到上午4:30作为时间。 每当我试图通过在repo中查询sql表来获取datetime类型字段时 @Query(value = "SELECT start FROM course_section WHERE crn = ?1", nativeQuery = true) LocalDateTime getStartTimeByCrn(i

我的LocalDateTime变量每次通过查询我的sql表得到它时都会更改5个小时。如果我的时间从上午9:30开始,那么它将返回到上午4:30作为时间。 每当我试图通过在repo中查询sql表来获取datetime类型字段时

    @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变量时,一行中的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;

这个bug似乎没有发生的逻辑原因…

取决于mysql数据库的托管位置。您是否可以检查mysql是否托管在云服务提供商所在的时区比您使用的DBMS产品提前4小时的地区?“SQL”只是所有关系数据库使用的查询语言,而不是特定数据库产品的名称,时间戳行为可以是特定于供应商的。请为您正在使用的数据库产品添加。数据库中的
start
end
列是什么数据类型?