还是关于r2dbc的问题,传参类型为对象时候,总是报null错误

问题遇到的现象和发生背景

环境:r2dbc + postgresql,idea,springdoc;
需求:按state + type两个参数查询数据,这两个参数如果为空,则查询条件中不加这个参数

1、 先写的代码如下:

Service:
 public Flux<SysEntity> getSysByType( String state, String type)
    {
        return this.sysRepo.getSysByType(state,type);
    }

    @Query("select c.* from sys c where (case when :state='' or :state is null then c.state else :state end)" +
            " = c.state and (case when :type='' or :type is null then c.type else :type end) =c.type ")
    public Flux<SysTaskEntity> getSysByType(@Param(value = "state")String state,@Param(value = "type")String type);

执行时候报错

org.springframework.dao.InvalidDataAccessApiUsageException: No parameter specified for [state] in query [select c.* from sys c where (case when :type='' or :type is null then c.type else :type end) =c.type and (case when :state='' or :state is null then c.state else :state end) = c.state]
    at org.springframework.r2dbc.core.DefaultDatabaseClient$DefaultGenericExecuteSpec.retrieveParameters(DefaultDatabaseClient.java:394) ~[spring-r2dbc-5.3.12.jar:5.3.12]
    Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:

就是说后面那个参数的值识别不出来。然后到处找代码和资料,无意中改成了这个:

Service:
 public Flux<SysEntity> getSysByType(final String state,final String type)
    {
        return this.sysRepo.getSysByType(state,type);
    }

参数前面加了个 final,居然执行成功了,哪位知道什么原因?

2、然后,我想学习一下传个对象参数进来,代码如下:

问题相关代码,请勿粘贴截图

SysRepo:

@Query("select c from sys c where c.state = :#{#sysQueryParam.state} and  c.type = :#{#sysQueryParam.type" )
    public Flux<SysEntity> searchSys(@Param(value = "sysQueryParam") SysQueryParam sysQueryParam);

SYSService:
    public Flux<SysEntity> searchSys(SysQueryParam sysQueryParam)
    {
        return this.sysRepo.searchSys(sysQueryParam);
    }

SysController@PostMapping("q")
    public Flux<SysEntity> searchSys(@RequestBody @Valid sysQueryParam sysQueryParam)
    {
        return sysService.searchSys(sysQueryParam);
    }

参数对象 SysQueryParam@Data
public class SysQueryParam
{
    private String state;
    private String type;
}

执行swagger时候报错如下:

2022-03-16 15:06:31.644 DEBUG 38508 --- [ctor-http-nio-2] o.s.w.s.adapter.HttpWebHandlerAdapter    : [b0e16e46-6, L:/0:0:0:0:0:0:0:1:8700 - R:/0:0:0:0:0:0:0:1:3042] HTTP POST "/sys/sys/q"
2022-03-16 15:06:31.657 DEBUG 38508 --- [ctor-http-nio-2] s.w.r.r.m.a.RequestMappingHandlerMapping : [b0e16e46-6, L:/0:0:0:0:0:0:0:1:8700 - R:/0:0:0:0:0:0:0:1:3042] Mapped to com.jundax.fluxwk.sys.controller.SysController#searchSys(QueryParam)
2022-03-16 15:06:31.669 DEBUG 38508 --- [ctor-http-nio-2] .r.m.a.RequestBodyMethodArgumentResolver : [b0e16e46-6, L:/0:0:0:0:0:0:0:1:8700 - R:/0:0:0:0:0:0:0:1:3042] Content-Type:application/json
2022-03-16 15:06:31.678 DEBUG 38508 --- [ctor-http-nio-2] .r.m.a.RequestBodyMethodArgumentResolver : [b0e16e46-6, L:/0:0:0:0:0:0:0:1:8700 - R:/0:0:0:0:0:0:0:1:3042] 0..1 [com.jundax.fluxwk.sys.model.QueryParam]
2022-03-16 15:06:31.687 DEBUG 38508 --- [ctor-http-nio-2] reactor.netty.channel.FluxReceive        : [b0e16e46-6, L:/0:0:0:0:0:0:0:1:8700 - R:/0:0:0:0:0:0:0:1:3042] FluxReceive{pending=0, cancelled=false, inboundDone=false, inboundError=null}: subscribing inbound receiver
2022-03-16 15:06:31.701 DEBUG 38508 --- [ctor-http-nio-2] o.s.http.codec.json.Jackson2JsonDecoder  : [b0e16e46-6, L:/0:0:0:0:0:0:0:1:8700 - R:/0:0:0:0:0:0:0:1:3042] Decoded [SysQueryParam(state=1, type=22222)]
2022-03-16 15:06:36.391 DEBUG 38508 --- [ctor-http-nio-2] o.s.w.r.r.m.a.ResponseBodyResultHandler  : [b0e16e46-6, L:/0:0:0:0:0:0:0:1:8700 - R:/0:0:0:0:0:0:0:1:3042] Using 'application/json' given [*/*] and supported [application/json, application/*+json, application/x-ndjson, text/event-stream]
2022-03-16 15:06:36.399 DEBUG 38508 --- [ctor-http-nio-2] o.s.w.r.r.m.a.ResponseBodyResultHandler  : [b0e16e46-6, L:/0:0:0:0:0:0:0:1:8700 - R:/0:0:0:0:0:0:0:1:3042] 0..N [com.jundax.fluxwk.sys.entity.SysEntity]
2022-03-16 15:06:36.448 DEBUG 38508 --- [ctor-http-nio-2] a.w.r.e.AbstractErrorWebExceptionHandler : [b0e16e46-6, L:/0:0:0:0:0:0:0:1:8700 - R:/0:0:0:0:0:0:0:1:3042] Resolved [IllegalArgumentException: Value must not be null] for HTTP POST /sys/q
2022-03-16 15:06:36.506 ERROR 38508 --- [ctor-http-nio-2] a.w.r.e.AbstractErrorWebExceptionHandler : [b0e16e46-6, L:/0:0:0:0:0:0:0:1:8700 - R:/0:0:0:0:0:0:0:1:3042]  500 Server Error for HTTP POST "/sys/q"

java.lang.IllegalArgumentException: Value must not be null
    at org.springframework.util.Assert.notNull(Assert.java:201) ~[spring-core-5.3.12.jar:5.3.12]
    Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: 
Error has been observed at the following site(s):
    *__checkpoint ? Handler com.jundax.fluxwk.sys.controller.SysController#searchSys(QueryParam) [DispatcherHandler]
    *__checkpoint ? HTTP POST "/sys/sys/q" [ExceptionHandlingWebHandler]
Stack trace:
        at org.springframework.util.Assert.notNull(Assert.java:201) ~[spring-core-5.3.12.jar:5.3.12]
        at org.springframework.r2dbc.core.Parameter.from(Parameter.java:54) ~[spring-r2dbc-5.3.12.jar:5.3.12]
        at org.springframework.data.r2dbc.query.QueryMapper.getBindValue(QueryMapper.java:415) ~[spring-data-r2dbc-1.3.6.jar:1.3.6]
        at org.springframework.data.r2dbc.core.DefaultReactiveDataAccessStrategy.getBindValue(DefaultReactiveDataAccessStrategy.java:288) ~[spring-data-r2dbc-1.3.6.jar:1.3.6]
        at org.springframework.data.r2dbc.repository.query.ExpressionEvaluatingParameterBinder.getBindValue(ExpressionEvaluatingParameterBinder.java:134) ~[spring-data-r2dbc-1.3.6.jar:1.3.6]
        at org.springframework.data.r2dbc.repository.query.ExpressionEvaluatingParameterBinder.bindParameters(ExpressionEvaluatingParameterBinder.java:109) ~[spring-data-r2dbc-1.3.6.jar:1.3.6]

从日志里面也看到,传入的查询参数是有值的 Decoded [SysQueryParam(state=1, type=22222)]
但是却报“java.lang.IllegalArgumentException: Value must not be null”

这个问题拖了我差不多一整天时间了
请教,是哪里出了问题?谢谢