Spring参数解析错误

时间:2024-11-15 11:39:12

报错信息

2021-03-31 09:54:22.383 [http-nio-8103-exec-11] WARN - Resolved [org.springframework.: : 2 errors
Field error in object ‘userParam’ on field ‘endTime’: rejected value [2021-03-30T16:00:00.000Z]; codes [,,,typeMismatch]; arguments [: codes [,endTime]; arguments []; default message [endTime]]; default message [Failed to convert property value of type ‘’ to required type ‘’ for property ‘endTime’; nested exception is : Failed to convert from type [] to type [@ ] for value ‘2021-03-30T16:00:00.000Z’; nested exception is ]
Field error in object ‘userParam’ on field ‘startTime’: rejected value [2021-03-29T16:00:00.000Z]; codes [,,,typeMismatch]; arguments [: codes [,startTime]; arguments []; default message [startTime]]; default message [Failed to convert property value of type ‘’ to required type ‘’ for property ‘startTime’; nested exception is : Failed to convert from type [] to type [@ ] for value ‘2021-03-29T16:00:00.000Z’; nested exception is ]]

接收参数的DTO

@Data
public class UserParam {
    @ApiModelProperty("手机号")
	private String mobile;
    @ApiModelProperty("开始时间")
	private Date startTime;
	@ApiModelProperty("结束时间")
	private Date endTime;
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

Controller


```java

```java

```java

```java
@RestController
@RequestMapping("/v1/client")
@Api(value = "C端用户管理", tags = "C端用户管理相关接口")
public class ClientController {
    @Autowired
	IClientService iClientService;
	@GetMapping("/clientQueryList")
	public PageResult clientQueryList(UserParam userParam,
									@ApiParam @RequestParam(value = "pageIndex",required = false,defaultValue = "1") Long pageIndex,
									@ApiParam  @RequestParam(value = "pageNum",required = false,defaultValue = "10") Long pageNum) {

		return iClientService.queryClientList(userParam, pageIndex, pageNum);



	}
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25

Swagger 请求参数格式

在这里插入图片描述

报错信息: 无法将对应的字符串解析成日期类型
解决方法: 参见链接