Custom default method
# Custom default method
The custom mapper inherited from BaseEsMapper has all the methods of BaseEsMapper, but in some scenarios, users hope to customize some common public methods. Currently, the framework does not support customizing xml and writing dsl into xml like Mybatis. In fact, It is not necessary to use this function because handwriting The complexity of dsl and handwritten sql are not comparable. dsl is a json tree structure. If it is defined using xml, the burden will be too heavy for users. Moreover, we also provide an API that can directly execute dsl. In addition, we provide The existing methods combined with hybrid queries can meet 99% of scenarios out of the box, and hybrid queries can satisfy 1% of scenarios. To cover all user needs, support for this feature will not be considered in the short term. Since the custom xml method is not supported, is it possible to support the custom default method? Excellent developers in our community have implemented this function. Since the PR submission location is wrong, I tried to contact but failed. The PR has not been merged yet, but the code has been It is submitted and published by the author, and the actual ownership is still owned by acmdl528 (githubID).
##use
/**
* Add default method to demo mapper
*
* @return document list
*/
default List<Document> testDefaultMethod() {
LambdaEsQueryWrapper<Document> wrapper = EsWrappers.lambdaQuery(Document.class)
.eq(Document::getTitle, "Old Man");
return selectList(wrapper);
}
2
3
4
5
6
7
8
9
10
Warm reminder
Before this, if you define the default method directly in the mapper, an error will be reported. If you want to know the reason, you can refer to the relevant code in the register package of the starter module in the source code.