Skip to content

Commit 8ac5559

Browse files
committed
feat, update: add one feature, update dependencies' version
1 parent 136d66c commit 8ac5559

File tree

5 files changed

+105
-10
lines changed

5 files changed

+105
-10
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
/target/
33
*.jar
44
#Test files are in this package
5-
src/Test
5+
src/test

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright (c) 2018 Luoming Xu
189+
Copyright (c) 2018-2019 Luoming Xu
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

README.md

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ java工具类
22
=
33

44
[![Build status](https://ci.appveyor.com/api/projects/status/c5uviv5vhwo07t5i?svg=true)](https://ci.appveyor.com/project/LuomingXu/javautil)
5-
[![image](https://img.shields.io/badge/maven-v2.6.0-blue.svg)](https://search.maven.org/search?q=g:com.github.luomingxuorg%20JavaUtil)
5+
[![image](https://img.shields.io/badge/maven-v2.7.0-blue.svg)](https://search.maven.org/search?q=g:com.github.luomingxuorg%20JavaUtil)
66
[![image](https://img.shields.io/badge/License-Apache__v2-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0)
77

88
储存不知道什么时候就会用到的工具类
@@ -17,6 +17,7 @@ entity之间的转化|[converter][]
1717
aop实现类|[aop]
1818
分布式ID生成类|[snowflake]
1919
全国高等学校名单(2019/6/15)|[college]
20+
mybatis column配置生成|[mybatisColumns]
2021

2122
#### Version
2223

@@ -107,6 +108,38 @@ public class ExampleConverter implements Converter
107108
}
108109
```
109110

111+
#### MyBatis columns gen
112+
```java
113+
public class gen
114+
{
115+
public static void main(String[] args)
116+
{
117+
String path = "C:\\Users\\Desktop\\script.sql";
118+
String formerColumnsResult = "<id column=\"id\" jdbcType=\"BIGINT\" property=\"id\"/>\n" +
119+
"<result column=\"comment\" jdbcType=\"VARCHAR\" property=\"comment\"/>\n" +
120+
"<result column=\"creator_id\" jdbcType=\"BIGINT\" property=\"creatorId\"/>\n" +
121+
"<result column=\"creator_name\" jdbcType=\"VARCHAR\" property=\"creatorName\"/>\n" +
122+
"<result column=\"create_time\" jdbcType=\"TIMESTAMP\" property=\"createTime\"/>";
123+
124+
CompleteFullColumns.generate(path, formerColumnsResult);
125+
}
126+
127+
/*
128+
result will like:
129+
comment.id as comment_id,
130+
comment.comment as comment_comment,
131+
comment.creator_id as comment_creator_id,
132+
comment.creator_name as comment_creator_name,
133+
comment.create_time as comment_create_time,
134+
<id column="comment_id" jdbcType="BIGINT" property="id"/>
135+
<result column="comment_comment" jdbcType="VARCHAR" property="comment"/>
136+
<result column="comment_creator_id" jdbcType="BIGINT" property="creatorId"/>
137+
<result column="comment_creator_name" jdbcType="VARCHAR" property="creatorName"/>
138+
<result column="comment_create_time" jdbcType="TIMESTAMP" property="createTime"/>
139+
*/
140+
}
141+
```
142+
110143
#### maven dependency
111144
```xml
112145
<dependency>
@@ -130,4 +163,5 @@ public class ExampleConverter implements Converter
130163
[frameworkFile]:src/main/java/com/github/luomingxuorg/javautil/util/GenerateFrameworkFile.java "groovy文件"
131164
[aop]:src/main/java/com/github/luomingxuorg/javautil/util/AspectLog.java "aop"
132165
[snowflake]:src/main/java/com/github/luomingxuorg/javautil/util/Snowflake.java "ID生成"
133-
[college]:src/main/resources/college.json "全国高等学校名单, 提供sql与json格式两种"
166+
[college]:src/main/resources/college.json "全国高等学校名单, 提供sql与json格式两种"
167+
[mybatisColumns]:src/main/java/com/github/luomingxuorg/javautil/util/CompleteFullColumns.java "column配置生成"

pom.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.github.luomingxuorg</groupId>
88
<artifactId>JavaUtil</artifactId>
9-
<version>2.6.0</version>
9+
<version>2.7.0</version>
1010
<!--发布到中央仓库需要的东西-->
1111
<packaging>jar</packaging>
1212
<name>JavaUtil</name>
@@ -132,18 +132,18 @@
132132
<dependency>
133133
<groupId>com.google.guava</groupId>
134134
<artifactId>guava</artifactId>
135-
<version>28.0-jre</version>
135+
<version>28.1-jre</version>
136136
</dependency>
137137
<!--logger-->
138138
<dependency>
139139
<groupId>org.slf4j</groupId>
140140
<artifactId>slf4j-api</artifactId>
141-
<version>1.7.26</version>
141+
<version>1.7.28</version>
142142
</dependency>
143143
<dependency>
144144
<groupId>org.slf4j</groupId>
145145
<artifactId>slf4j-simple</artifactId>
146-
<version>1.7.26</version>
146+
<version>1.7.28</version>
147147
</dependency>
148148
<!--aop-->
149149
<dependency>
@@ -155,14 +155,14 @@
155155
<dependency>
156156
<groupId>org.projectlombok</groupId>
157157
<artifactId>lombok</artifactId>
158-
<version>1.18.8</version>
158+
<version>1.18.10</version>
159159
<scope>provided</scope>
160160
</dependency>
161161
<!--sql parser-->
162162
<dependency>
163163
<groupId>com.github.jsqlparser</groupId>
164164
<artifactId>jsqlparser</artifactId>
165-
<version>2.1</version>
165+
<version>3.0</version>
166166
</dependency>
167167
<!--pagehelper-->
168168
<dependency>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright (c) 2019
3+
* Author : Luoming Xu
4+
* Project Name : JavaUtil
5+
* File Name : CompleteFullColumns.java
6+
* CreateTime: 2019/10/06 14:02:31
7+
* LastModifiedDate : 2019/10/6 下午2:02
8+
*/
9+
10+
package com.github.luomingxuorg.javautil.util;
11+
12+
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
13+
import net.sf.jsqlparser.statement.create.table.ColumnDefinition;
14+
import net.sf.jsqlparser.statement.create.table.CreateTable;
15+
16+
import java.io.File;
17+
import java.io.FileInputStream;
18+
import java.io.InputStream;
19+
import java.util.List;
20+
import java.util.regex.Matcher;
21+
import java.util.regex.Pattern;
22+
23+
/**
24+
* 用于生成mybatis的mapper.xml配置文件
25+
* 具体使用请移步README
26+
*/
27+
public class CompleteFullColumns
28+
{
29+
/**
30+
* @param filePath sql DDL文件
31+
* @param formerColumnResult 形如{@code <result column="comment" jdbcType="VARCHAR" property="comment"/>}的string
32+
*/
33+
public static void generate(String filePath, String formerColumnResult)
34+
{
35+
try
36+
{
37+
File file = new File(filePath);
38+
InputStream stream = new FileInputStream(file);
39+
40+
CreateTable createTable = (CreateTable) CCJSqlParserUtil.parse(stream);
41+
String tableName = createTable.getTable().getName();
42+
List<ColumnDefinition> columns = createTable.getColumnDefinitions();
43+
44+
Pattern pattern;
45+
String columnName;
46+
for (ColumnDefinition item : columns)
47+
{
48+
columnName = item.getColumnName();
49+
pattern = Pattern.compile(String.format("(column=\"%s\")", columnName));
50+
Matcher matcher = pattern.matcher(formerColumnResult);
51+
formerColumnResult = matcher.replaceAll(String.format("column=\"%s_%s\"", tableName, columnName));
52+
System.out.println(String.format("%s.%s as %s_%s,", tableName, columnName, tableName, columnName));
53+
}
54+
System.out.println(formerColumnResult);
55+
}
56+
catch (Exception e)
57+
{
58+
e.printStackTrace();
59+
}
60+
}
61+
}

0 commit comments

Comments
 (0)