我是靠谱客的博主 单薄白羊,这篇文章主要介绍sql下滑转驼峰,现在分享给大家,希望可以做个参考。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; public class test1 { public static void main(String[] args) { String str = "a.id,n" + "a.id as order_material_id,n" + "k.payment_date as balance_payment_date"; String[] strings = str.split(","); List<String> stringList = new ArrayList<>(); for (String data : strings){ if(data.indexOf("a.material_id") >=0){ // System.out.println(data); } if(data.indexOf(" as ")>=0){ String[] strings1 = data.split("as"); String j = underlineToHump(strings1[1]); data = strings1[0] +" as " + j; }else { String j = data.substring(data.indexOf(".")+1); j = underlineToHump(j); data = data +" as " + j; } stringList.add(data); } String sql =stringList.stream().collect(Collectors.joining(",")); System.out.println(sql); } private static Pattern UNDERLINE_PATTERN = Pattern.compile("_([a-z])"); /** * 根据传入的带下划线的字符串转化为驼峰格式 * @param str * @author mrf * @return */ public static String underlineToHump(String str) { //正则匹配下划线及后一个字符,删除下划线并将匹配的字符转成大写 Matcher matcher = UNDERLINE_PATTERN.matcher(str); StringBuffer sb = new StringBuffer(str); if (matcher.find()) { sb = new StringBuffer(); //将当前匹配的子串替换成指定字符串,并且将替换后的子串及之前到上次匹配的子串之后的字符串添加到StringBuffer对象中 //正则之前的字符和被替换的字符 matcher.appendReplacement(sb, matcher.group(1).toUpperCase()); //把之后的字符串也添加到StringBuffer对象中 matcher.appendTail(sb); } else { //去除除字母之外的前面带的下划线 return sb.toString().replaceAll("_", ""); } return underlineToHump(sb.toString()); } }

最后

以上就是单薄白羊最近收集整理的关于sql下滑转驼峰的全部内容,更多相关sql下滑转驼峰内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(83)

评论列表共有 0 条评论

立即
投稿
返回
顶部