Java rest url中查询参数的日期时间格式
我使用joda DateTime作为参数 在SpringREST中为请求查询参数使用自定义日期时间格式 我尝试过@DateTimeFormat注释 我试过使用自定义转换器Java rest url中查询参数的日期时间格式,java,spring,rest,spring-mvc,postman,Java,Spring,Rest,Spring Mvc,Postman,我使用joda DateTime作为参数 在SpringREST中为请求查询参数使用自定义日期时间格式 我尝试过@DateTimeFormat注释 我试过使用自定义转换器 @GetMapping("/users/time") public ResponseEntity<User> findByTimeRange(final DateTime from, final DateTime to) { } @GetMapping(“/users/time”) 公共响应fi
@GetMapping("/users/time")
public ResponseEntity<User> findByTimeRange(final DateTime from, final DateTime to) {
}
@GetMapping(“/users/time”)
公共响应findByTimeRange(最终日期时间从,最终日期时间到){
}
Spring REST仅支持
“2019-09-01T7:32:56.235-05:30”
,但我想使用“2019-09-01T7:32:56”
基本上,您需要一个自定义格式设置程序,将参数作为字符串传递并用它解析它们。以下是使用Joda Time并使用您的输入进行测试的工作代码:
private static final DateTimeFormatter FORMATTER =
DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss");
@GetMapping("/users/time")
public ResponseEntity<User> findByTimeRange(@RequestParam("from") String fromParam,
@RequestParam("to") String toParam) {
DateTime from = FORMATTER.parseDateTime(fromParam);
DateTime to = FORMATTER.parseDateTime(toParam);
// Do your search part...
}
private static final DateTimeFormatter格式化程序=
模式的日期时间格式(“yyyy-MM-dd'HH:MM:ss”);
@GetMapping(“/users/time”)
公共响应findByTimeRange(@RequestParam(“from”)字符串fromParam,
@RequestParam(“to”)字符串(toParam){
DateTime from=FORMATTER.parseDateTime(fromParam);
DateTime to=FORMATTER.parseDateTime(toParam);
//做你的搜索部分。。。
}
那是哪种DateTime
类型?乔达时间的那个?是的,是乔达时间