我正在尝试将Spring Data JPA 1.8与Java 8 Date/Time API JSR-310一起使用.
一切似乎都有效,直到我试图让所有车辆在两个LocalDateTimes之间.返回的实体数量似乎只与它应该的数量松散相关.
@Repository
public interface VehicleRepository extends JpaRepository<Vehicle, Long> {
List<Vehicle> findByDateTimeBetween(LocalDateTime begin, LocalDateTime end);
}
Run Code Online (Sandbox Code Playgroud)
@Entity
@Table(name = "VEHICLE")
public class Vehicle implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "IDX", nullable = false, unique = true)
@GeneratedValue(strategy = GenerationType.AUTO)
private long vehicleId;
@Column(name = "DATE_TIME", nullable = false)
private LocalDateTime dateTime = LocalDateTime.now();
// Getters and Setters
}
Run Code Online (Sandbox Code Playgroud)
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.8.0.RELEASE</version>
</dependency> …Run Code Online (Sandbox Code Playgroud) 我想配置jackson为以以下格式输出任何日期/时间值:
spring.jackson.date-format=yyyy-MM-dd'T'HH:mm:ss
我正在获取许多数据库行,并将它们作为json地图返回。
@RestController
public class MyService {
@GetMapping
public List<Map<String, Object>> get(Param params) {
return jdbcTemplate.queryForList(sql, params);
}
}
Run Code Online (Sandbox Code Playgroud)
问题:数据库和jvm的默认时区为Europe/Berlin,因此为UTC + 2。因此,杰克逊会先自动将接收java.sql.Timestamp到的所有数据库转换为UTC(减去2小时),然后通过json输出它们。
在mysql数据库本身中,它是一种datetime类型。
但是我只想让杰克逊按原样输出时间戳,而无需事先转换!是否可以跳过时区校正?
我只想忽略时区而不进行交谈。剪下来