ocr识别-中英文切换下划线转驼峰
This commit is contained in:
+2
-1
@@ -7,6 +7,7 @@ import com.jero.generater.modules.online.cgform.service.impl.OnlCgformFieldServi
|
|||||||
import com.jero.modules.ocr.entity.OcrRecordEO;
|
import com.jero.modules.ocr.entity.OcrRecordEO;
|
||||||
import com.jero.modules.ocr.mapper.OcrRecordEOMapper;
|
import com.jero.modules.ocr.mapper.OcrRecordEOMapper;
|
||||||
import com.jero.modules.ocr.service.IOcrRecordEOService;
|
import com.jero.modules.ocr.service.IOcrRecordEOService;
|
||||||
|
import com.jero.modules.ocr.util.LineHumpUtil;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@@ -113,7 +114,7 @@ public class OcrRecordEOServiceImpl extends ServiceImpl<OcrRecordEOMapper, OcrRe
|
|||||||
List<Map<String, Object>> list = new ArrayList<>();
|
List<Map<String, Object>> list = new ArrayList<>();
|
||||||
for (OnlCgformField onlCgformField : fieldList) {
|
for (OnlCgformField onlCgformField : fieldList) {
|
||||||
Map<String, Object> map = new HashMap<>();
|
Map<String, Object> map = new HashMap<>();
|
||||||
map.put("db_field_name", onlCgformField.getDbFieldName());//字段
|
map.put("db_field_name", LineHumpUtil.lineToHump(onlCgformField.getDbFieldName()));//字段
|
||||||
if(CutEnum.CN.getValue().equals(cut)){
|
if(CutEnum.CN.getValue().equals(cut)){
|
||||||
map.put("db_field_txt", onlCgformField.getDbFieldTxt());//字段中文名
|
map.put("db_field_txt", onlCgformField.getDbFieldTxt());//字段中文名
|
||||||
}else{
|
}else{
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package com.jero.modules.ocr.util;
|
||||||
|
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: liyawei
|
||||||
|
* @Description:
|
||||||
|
* @Date: Created in 13:38 2022/2/24
|
||||||
|
*/
|
||||||
|
public class LineHumpUtil {
|
||||||
|
private static Pattern linePattern = Pattern.compile("_(\\w)");
|
||||||
|
|
||||||
|
/** 下划线转驼峰 */
|
||||||
|
public static String lineToHump(String str) {
|
||||||
|
str = str.toLowerCase();
|
||||||
|
Matcher matcher = linePattern.matcher(str);
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
|
while (matcher.find()) {
|
||||||
|
matcher.appendReplacement(sb, matcher.group(1).toUpperCase());
|
||||||
|
}
|
||||||
|
matcher.appendTail(sb);
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 驼峰转下划线(简单写法,效率低于{@link #humpToLine2(String)}) */
|
||||||
|
public static String humpToLine(String str) {
|
||||||
|
return str.replaceAll("[A-Z]", "_$0").toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Pattern humpPattern = Pattern.compile("[A-Z]");
|
||||||
|
|
||||||
|
/** 驼峰转下划线,效率比上面高 */
|
||||||
|
public static String humpToLine2(String str) {
|
||||||
|
Matcher matcher = humpPattern.matcher(str);
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
|
while (matcher.find()) {
|
||||||
|
matcher.appendReplacement(sb, "_" + matcher.group(0).toLowerCase());
|
||||||
|
}
|
||||||
|
matcher.appendTail(sb);
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
String lineToHump = lineToHump("f_parent_no_leader");
|
||||||
|
System.out.println(lineToHump);// fParentNoLeader
|
||||||
|
System.out.println(humpToLine(lineToHump));// f_parent_no_leader
|
||||||
|
System.out.println(humpToLine2(lineToHump));// f_parent_no_leader
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user