Spring data Spring QueryDSL谓词';snake案例的命名约定
我正在使用QueryDsl中的谓词。后端内部使用camelCase,但承诺在与客户端通信时使用snake_case 我想使用Spring data Spring QueryDSL谓词';snake案例的命名约定,spring-data,naming-conventions,querydsl,predicate,spring-data-commons,Spring Data,Naming Conventions,Querydsl,Predicate,Spring Data Commons,我正在使用QueryDsl中的谓词。后端内部使用camelCase,但承诺在与客户端通信时使用snake_case 我想使用snake\u case作为查询参数,如 http://localhost:8080/inputmethod?protocol_type=SDK 如果我将协议类型作为snake\u case传递,则查询Dsl谓词不会解析它。它只解析类型(目标实体类)的字段,如camelCase所示。因此,querydspredicatebuilder的getPredicate()跳过了协
snake\u case
作为查询参数,如
http://localhost:8080/inputmethod?protocol_type=SDK
如果我将协议类型
作为snake\u case传递,则查询Dsl谓词不会解析它。它只解析类型(目标实体类)的字段,如camelCase所示。因此,querydspredicatebuilder
的getPredicate()跳过了协议类型
/**
* Creates a Querydsl {@link Predicate} for the given values, {@link QuerydslBindings} on the given
* {@link TypeInformation}.
*
* @param type the type to create a predicate for.
* @param values the values to bind.
* @param bindings the {@link QuerydslBindings} for the predicate.
* @return
*/
@Nullable
public Predicate getPredicate(TypeInformation<?> type, MultiValueMap<String, String> values,
QuerydslBindings bindings) {
...
if (!bindings.isPathAvailable(path, type)) { // <-- here!
// path : "protocol_type"
// type : my.domain.entity.InputMethod
continue;
}
...
}
如何将谓词的命名约定设置为snake\u case
控制器
配置
杰克逊命名策略
我也有同样的问题
https://stackoverflow.com/questions/53273966/spring-jpa-querydslpredicate-snake-case
我还设置了spring.jackson.property naming strategy=SNAKE\u CASE
不幸的是,这里不能使用SNAKE\u CASE,因为\u
在spring数据映射中被视为属性拆分器。所以mapper会将其转换为协议
和类型
谢谢您的回答。我找到了另一种使用bindings.bind(path).as(alias)
的方法。我可以将每个camelCase路径别名为snake_Case路径。
http://localhost:8080/inputmethod?protocolType=SDK
@GetMapping
public List<InputMethodDto.Response> getInputMethodTypeList(
@QuerydslPredicate(root = InputMethod.class) Predicate predicate) {
return service.getInputMethodList(predicate);
}
@Getter
@NoArgsConstructor
@AllArgsConstructor
@Entity
public class InputMethod {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Enumerated(EnumType.STRING)
@Column
private RecordType recordType;
@Enumerated(EnumType.STRING)
@Column
private ProtocolType protocolType;
@Column
private String name;
@EnableWebMvc
@EnableSwagger2
@Configuration
public class SwaggerConfig implements WebMvcConfigurer {
...
}