Skip to content

Commit 4912ab0

Browse files
author
wj596
committed
V0.0.3
1 parent b897953 commit 4912ab0

File tree

22 files changed

+690
-116
lines changed

22 files changed

+690
-116
lines changed

common/src/main/java/org/jsets/fastboot/common/util/JsonUtils.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
import com.fasterxml.jackson.core.JsonParser;
55
import com.fasterxml.jackson.core.JsonProcessingException;
66
import com.fasterxml.jackson.databind.*;
7-
import com.fasterxml.jackson.databind.node.ObjectNode;
8-
97
import java.text.SimpleDateFormat;
108
import java.util.List;
119
import java.util.Objects;

common/src/main/java/org/jsets/fastboot/common/util/StringUtils.java

Lines changed: 128 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
/**
66
* 字符串工具
7+
*
78
* @author wj596
89
*
910
*/
@@ -30,62 +31,61 @@ public class StringUtils {
3031

3132
/**
3233
* 获取UUID
34+
*
3335
* @return String
3436
*/
3537
public static String getUUID() {
3638
return UUID.randomUUID().toString().replace("-", "");
3739
}
3840

3941
/**
40-
* 去除两端空格
41-
* <br>
42+
* 去除两端空格 <br>
4243
*
4344
* @param string 字符串
4445
* @return String
4546
*/
4647
public static String trim(final String string) {
47-
if(Objects.isNull(string)){
48+
if (Objects.isNull(string)) {
4849
return "";
4950
}
5051
return string.trim();
5152
}
5253

5354
/**
54-
* 是否为空
55-
* <br>
56-
* *isEmpty(" ") = false*
55+
* 是否为空 <br>
56+
* *isEmpty(" ") = false*
5757
*
5858
* @param string 字符串
5959
* @return boolean
6060
*/
6161
public static boolean isEmpty(final String string) {
6262
return string == null || string.isEmpty();
6363
}
64-
64+
6565
/**
66-
* 是否为空
67-
* <br>
68-
* *isBlank(" ") = true*
66+
* 是否为空 <br>
67+
* *isBlank(" ") = true*
6968
*
7069
* @param string 字符串
7170
* @return boolean
7271
*/
7372
public static boolean isBlank(final String string) {
7473
int strLen;
75-
if (string != null && (strLen = string.length()) != 0) {
76-
for(int i = 0; i < strLen; ++i) {
77-
if (!Character.isWhitespace(string.charAt(i))) {
78-
return false;
79-
}
80-
}
81-
return true;
82-
} else {
83-
return true;
84-
}
85-
}
86-
74+
if (string != null && (strLen = string.length()) != 0) {
75+
for (int i = 0; i < strLen; ++i) {
76+
if (!Character.isWhitespace(string.charAt(i))) {
77+
return false;
78+
}
79+
}
80+
return true;
81+
} else {
82+
return true;
83+
}
84+
}
85+
8786
/**
8887
* 断言不为空
88+
*
8989
* @param string 字符串
9090
* @return boolean
9191
*/
@@ -95,6 +95,7 @@ public static boolean notEmpty(final String string) {
9595

9696
/**
9797
* 分割字符串,使用‘,’
98+
*
9899
* @param str 字符串
99100
* @return List<String>
100101
*/
@@ -104,10 +105,11 @@ public static List<String> split(final String str) {
104105
}
105106
return Arrays.asList(str.split(SEPARATOR));
106107
}
107-
108+
108109
/**
109110
* 分割字符串,使用指定的分隔符
110-
* @param str 字符串
111+
*
112+
* @param str 字符串
111113
* @param separatorChars 分隔符
112114
* @return List<String>
113115
*/
@@ -120,6 +122,7 @@ public static List<String> split(final String str, final String separatorChars)
120122

121123
/**
122124
* 连接字符串,使用‘,’
125+
*
123126
* @param collection 集合
124127
* @return String
125128
*/
@@ -135,6 +138,7 @@ public static String join(final Collection<String> collection) {
135138

136139
/**
137140
* 连接字符串,使用‘,’
141+
*
138142
* @param array 字符串数组
139143
* @return String
140144
*/
@@ -148,10 +152,11 @@ public static String join(final String[] array) {
148152
}
149153
return sb.toString();
150154
}
151-
155+
152156
/**
153157
* 连接字符串,使用指定分隔符
154-
* @param collection 集合
158+
*
159+
* @param collection 集合
155160
* @param separatorChars 分隔符
156161
* @return String
157162
*/
@@ -176,19 +181,113 @@ public static boolean toBoolean(final String str) {
176181
return false;
177182
}
178183

179-
if("1".equals(str)||"ok".equals(str)||"true".equals(str)){
184+
if ("1".equals(str) || "ok".equals(str) || "true".equals(str)) {
180185
return true;
181186
}
182187
return false;
183188
}
184-
189+
185190
/**
186191
* 字符串"null"转为""
187192
*
188193
* @param string 字符串
189194
* @return string
190195
*/
191196
public static String nullToBlank(final String string) {
192-
return string==null?"":string;
197+
return string == null ? "" : string;
198+
}
199+
200+
/**
201+
* 字符串转小写(null安全)
202+
*
203+
* @param string 字符串
204+
* @return string
205+
*/
206+
public static String toLowerCase(final String string) {
207+
return string == null ? "" : string.toLowerCase();
208+
}
209+
210+
/**
211+
* 字符串转大写(null安全)
212+
*
213+
* @param string 字符串
214+
* @return string
215+
*/
216+
public static String toUpperCase(final String string) {
217+
return string == null ? "" : string.toUpperCase();
218+
}
219+
220+
/**
221+
* 首字母大写
222+
*
223+
* @param str 字符串
224+
* @return String
225+
*/
226+
public static String capitalize(final String str) {
227+
int strLen;
228+
if (str == null || (strLen = str.length()) == 0) {
229+
return str;
230+
}
231+
232+
final char firstChar = str.charAt(0);
233+
final char newChar = Character.toTitleCase(firstChar);
234+
if (firstChar == newChar) {
235+
// already capitalized
236+
return str;
237+
}
238+
239+
char[] newChars = new char[strLen];
240+
newChars[0] = newChar;
241+
str.getChars(1, strLen, newChars, 1);
242+
return String.valueOf(newChars);
243+
}
244+
245+
/**
246+
* 符串转驼峰格式转下划线格式
247+
*
248+
* @param param 字符串
249+
* @return String
250+
*/
251+
public static String camelToUnderline(final String param) {
252+
int len = param.length();
253+
StringBuilder sb = new StringBuilder(len);
254+
for (int i = 0; i < len; i++) {
255+
char c = param.charAt(i);
256+
if (Character.isUpperCase(c)) {
257+
sb.append("_");
258+
sb.append(Character.toLowerCase(c));
259+
} else {
260+
sb.append(c);
261+
}
262+
}
263+
return sb.toString();
264+
}
265+
266+
/**
267+
* 符串下划线格式转转驼峰格式
268+
*
269+
* @param param 字符串
270+
* @return String
271+
*/
272+
public static String underlineToCamel(String param) {
273+
int len = param.length();
274+
StringBuilder sb = new StringBuilder(len);
275+
boolean flag = false; // "_" 后转大写标志,默认字符前面没有"_"
276+
for (int i = 0; i < len; i++) {
277+
char c = param.charAt(i);
278+
if (c == '_') {
279+
flag = true;
280+
continue; // 标志设置为true,跳过
281+
} else {
282+
char tt = Character.toLowerCase(param.charAt(i));
283+
if (flag && sb.length() > 0) {
284+
sb.append(Character.toUpperCase(tt));
285+
} else {
286+
sb.append(tt);
287+
}
288+
flag = false; // 重置标识
289+
}
290+
}
291+
return sb.toString();
193292
}
194293
}

frame/src/main/java/org/jsets/fastboot/frame/controller/BaseController.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ protected void argThat(final boolean expression, final String message) {
162162
* @param formatter 消息格式
163163
* @param args 消息参数
164164
*/
165-
protected void argumentThat(final boolean expression, final String formatter, final Object... args) {
165+
protected void argThat(final boolean expression, final String formatter, final Object... args) {
166166
if (!expression) {
167167
throw new IllegalArgumentException(String.format(formatter, args));
168168
}
@@ -184,7 +184,7 @@ protected void argNotNull(final Object argument, final String argumentName) {
184184
* @param argument 参数
185185
* @param argumentName 参数名称
186186
*/
187-
protected void stringArgNotEmpty(final String argument, final String argumentName) {
187+
protected void argNotEmpty(final String argument, final String argumentName) {
188188
if (StringUtils.isEmpty(argument)) {
189189
throw new IllegalArgumentException("参数["+argumentName+"],不能为空");
190190
}
@@ -195,10 +195,16 @@ protected void stringArgNotEmpty(final String argument, final String argumentNam
195195
* @param argument 参数
196196
* @param argumentName 参数名称
197197
*/
198-
protected void stringArgNotBlank(final String argument, final String argumentName) {
198+
protected void argNotBlank(final String argument, final String argumentName) {
199199
if (StringUtils.isBlank(argument)) {
200200
throw new IllegalArgumentException("参数["+argumentName+"],不能为空或空白字符串");
201201
}
202202
}
203+
204+
protected void assertThat(final boolean expression, final RuntimeException exception) {
205+
if (!expression) {
206+
throw exception;
207+
}
208+
}
203209

204210
}

generator/pom.xml

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,40 @@
1-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
2-
<modelVersion>4.0.0</modelVersion>
3-
<parent>
4-
<groupId>org.jsets</groupId>
5-
<artifactId>fastboot</artifactId>
6-
<version>0.0.1</version>
7-
</parent>
8-
<artifactId>fb-generator</artifactId>
9-
10-
11-
<dependencies>
12-
13-
<dependency>
14-
<groupId>org.springframework.boot</groupId>
15-
<artifactId>spring-boot-autoconfigure</artifactId>
16-
<optional>true</optional>
17-
</dependency>
18-
19-
<dependency>
20-
<groupId>org.springframework</groupId>
21-
<artifactId>spring-context</artifactId>
22-
<optional>true</optional>
23-
</dependency>
24-
25-
</dependencies>
26-
27-
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>org.jsets</groupId>
7+
<artifactId>fastboot</artifactId>
8+
<version>0.0.1</version>
9+
</parent>
10+
<artifactId>fb-generator</artifactId>
11+
12+
13+
<dependencies>
14+
15+
<dependency>
16+
<groupId>org.springframework.boot</groupId>
17+
<artifactId>spring-boot-autoconfigure</artifactId>
18+
<optional>true</optional>
19+
</dependency>
20+
21+
<dependency>
22+
<groupId>org.springframework</groupId>
23+
<artifactId>spring-context</artifactId>
24+
<optional>true</optional>
25+
</dependency>
26+
27+
<dependency>
28+
<groupId>org.springframework</groupId>
29+
<artifactId>spring-jdbc</artifactId>
30+
</dependency>
31+
32+
<dependency>
33+
<groupId>org.jsets</groupId>
34+
<artifactId>fb-common</artifactId>
35+
</dependency>
36+
37+
</dependencies>
38+
39+
2840
</project>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package org.jsets.fastboot.generator.model;
2+
3+
import lombok.Data;
4+
5+
@Data
6+
public class BaseEntity {
7+
8+
private String id;
9+
10+
}

0 commit comments

Comments
 (0)