Skip to content

Commit

Permalink
Support chinese pinyin search of mybatis flex for java generate template
Browse files Browse the repository at this point in the history
  • Loading branch information
tangllty committed Jun 28, 2024
1 parent 5ba1170 commit f8ba0f3
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.tang.extension.mybatisflex.query;

import com.mybatisflex.core.query.FunctionQueryColumn;
import com.mybatisflex.core.query.QueryColumn;
import com.mybatisflex.core.util.LambdaGetter;
import com.mybatisflex.core.util.LambdaUtil;
import com.tang.extension.mybatisflex.constants.FuncName;

/**
* 自定义查询函数
*
* @author Tang
*/
public class QueryFunctions {

private QueryFunctions() {
}

public static QueryColumn toPinyin(String columnX) {
return new FunctionQueryColumn(FuncName.TO_PINYIN, columnX);
}

public static QueryColumn toPinyin(QueryColumn columnX) {
return new FunctionQueryColumn(FuncName.TO_PINYIN, columnX);
}

public static <T> QueryColumn toPinyin(LambdaGetter<T> columnX) {
return new FunctionQueryColumn(FuncName.TO_PINYIN, LambdaUtil.getQueryColumn(columnX));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.tang.extension.mybatisflex.constants

/**
* 自定义函数名
*
* @author Tang
*/
object FuncName {

const val TO_PINYIN = "TO_PINYIN"

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.mybatisflex.core.BaseMapper;
import com.mybatisflex.core.query.QueryWrapper;
import com.tang.commons.utils.If;
import com.tang.commons.utils.page.PageResult;
import com.tang.extension.mybatisflex.query.QueryFunctions;
import com.tang.extension.mybatisflex.utils.PageUtils;
import ${packageName}.entity.$ClassName;

Expand Down Expand Up @@ -33,7 +34,8 @@ public interface ${ClassName}Mapper extends BaseMapper<$ClassName> {
queryWrapper.and(${CLASS_NAME}.${column.columnNameUpperUnderscore}.eq(${className}.get${column.columnNameUpperCamel}(), If::nonEmpty));
#end
#if($column.queryType == "fuzzy")
queryWrapper.and(${CLASS_NAME}.${column.columnNameUpperUnderscore}.like(${className}.get${column.columnNameUpperCamel}(), If::nonEmpty));
queryWrapper.and(${CLASS_NAME}.${column.columnNameUpperUnderscore}.like(${className}.get${column.columnNameUpperCamel}(), If::nonEmpty)
.or(QueryFunctions.toPinyin(${CLASS_NAME}.${column.columnNameUpperUnderscore}).like(${className}.get${column.columnNameUpperCamel}(), If::nonEmpty)));
#end
#if($column.queryType == "findInSet")
queryWrapper.and(${CLASS_NAME}.${column.columnNameUpperUnderscore}.in(${className}.get${column.columnNameUpperCamel}()));
Expand Down

0 comments on commit f8ba0f3

Please sign in to comment.