ops = rt.opsForValue();
33 | if (!rt.hasKey(key)) {
34 | ops.set(key, String.valueOf(1L));
35 | rt.expire(key, 1L, TimeUnit.DAYS);
36 | } else {
37 | newValue = ops.increment(key, 1L);
38 | }
39 | }
40 | } catch (Exception ex) {
41 | logger.error("Redis生成序列号发生错误", ex);
42 | }
43 | String zeroStr = "";
44 | if (null != newValue && prefixLen > 0 && String.valueOf(newValue).length() < prefixLen) {
45 | for (int i = 0; i < prefixLen - String.valueOf(newValue).length(); i++) {
46 | zeroStr += "0";
47 | }
48 | }
49 | return valuePrefix + zeroStr + newValue;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/com/git/comm/utils/u4os/BareBonesBrowserLaunch.java:
--------------------------------------------------------------------------------
1 | package com.git.comm.utils.u4os;
2 |
3 | import javax.swing.*;
4 | import java.lang.reflect.Method;
5 |
6 | /**
7 | * Title: BareBonesBrowserLaunch.
8 | * Description 根据系统打开浏览器
9 | * @author net ( thanks to Internet & author)
10 | * @date 2018/8/14 下午11:06
11 | */
12 | public class BareBonesBrowserLaunch {
13 | public static void openURL(String url) {
14 | try {
15 | browse(url);
16 | } catch (Exception e) {
17 | JOptionPane.showMessageDialog(null, "Error attempting to launch web browser:\n" + e.getLocalizedMessage());
18 | }
19 | }
20 |
21 | private static void browse(String url) throws Exception {
22 | String osName = System.getProperty("os.name", "");
23 | if (osName.startsWith("Mac OS")) {
24 | Class fileMgr = Class.forName("com.apple.eio.FileManager");
25 | Method openURL = fileMgr.getDeclaredMethod("openURL", new Class[] { String.class });
26 | openURL.invoke(null, new Object[] { url });
27 | } else if (osName.startsWith("Windows")) {
28 | Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
29 | } else {
30 | // assume Unix or Linux
31 | String[] browsers = { "firefox", "opera", "konqueror", "epiphany", "mozilla", "netscape" };
32 | String browser = null;
33 | for (int count = 0; count < browsers.length && browser == null; count++) {
34 | if (Runtime.getRuntime().exec(new String[] { "which", browsers[count] }).waitFor() == 0) {
35 | browser = browsers[count];
36 | }
37 | if (browser == null) {
38 | throw new NoSuchMethodException("Could not find web browser");
39 | } else {
40 | Runtime.getRuntime().exec(new String[] { browser, url });
41 | }
42 | }
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/com/git/comm/utils/u4list/ListUtils.java:
--------------------------------------------------------------------------------
1 | package com.git.comm.utils.u4list;
2 |
3 | import java.util.*;
4 |
5 | public class ListUtils {
6 |
7 | /**
8 | * 判断对象数组是否为空并且数量大于0
9 | *
10 | * @param value
11 | * @return
12 | */
13 | public static Boolean isNotNullAndNotEmpty(Object[] value) {
14 | boolean bl = false;
15 | if (null != value && 0 < value.length) {
16 | bl = true;
17 | }
18 | return bl;
19 | }
20 |
21 | /**
22 | * 判断对象集合(List,Set)是否为空并且数量大于0
23 | *
24 | * @param value
25 | * @return
26 | */
27 | public static Boolean isNotNullAndNotEmpty(Collection> value) {
28 | boolean bl = false;
29 | if (null != value && 0 < value.size()) {
30 | bl = true;
31 | }
32 | return bl;
33 | }
34 |
35 | /**
36 | * 判断集合是否为空
37 | * @param coll
38 | * @return
39 | */
40 | public static boolean isEmpty(Collection coll) {
41 | return coll == null || coll.isEmpty();
42 | }
43 |
44 | /**
45 | * 拆分list,按500条拆分
46 | * @param list
47 | * @return
48 | */
49 | public static List> splitList(List list){
50 | List> lists = new ArrayList>();
51 | List subList = new ArrayList();
52 | int size = list.size();
53 | int sum = 500;
54 | int count = size / sum;
55 | int yu = size % sum;
56 | if (count == 0) {
57 | lists.add(list);
58 | } else {
59 | if(size % sum != 0){
60 | count ++;
61 | }
62 | for (int i = 0; i < count; i++) {
63 | if(sum*(i+1) <= size){
64 | subList = list.subList(sum*i, sum*(i+1));
65 | }else{
66 | subList = list.subList(sum*i, sum*(i)+yu);
67 | }
68 | lists.add(subList);
69 | }
70 | }
71 | return lists;
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/src/main/java/com/git/comm/utils/xss/XssHttpServletRequestWrapper.java:
--------------------------------------------------------------------------------
1 | package com.git.comm.utils.xss;
2 |
3 | import javax.servlet.http.HttpServletRequest;
4 | import javax.servlet.http.HttpServletRequestWrapper;
5 |
6 | public class XssHttpServletRequestWrapper extends HttpServletRequestWrapper {
7 | HttpServletRequest orgRequest = null;
8 |
9 | public XssHttpServletRequestWrapper(HttpServletRequest request) {
10 | super(request);
11 | orgRequest = request;
12 | }
13 |
14 | @Override
15 | public String getParameter(String name) {
16 | // 返回值之前 先进行过滤
17 | return XssShieldUtil.stripXss(super.getParameter(XssShieldUtil.stripXss(name)));
18 | }
19 |
20 | @Override
21 | public String[] getParameterValues(String name) {
22 | // 返回值之前 先进行过滤
23 | String[] values = super.getParameterValues(XssShieldUtil.stripXss(name));
24 | if(values != null){
25 | for (int i = 0; i < values.length; i++) {
26 | values[i] = XssShieldUtil.stripXss(values[i]);
27 | }
28 | }
29 | return values;
30 | }
31 |
32 | /**
33 | * 覆盖getHeader方法,将参数名和参数值都做xss过滤。
34 | * 如果需要获得原始的值,则通过super.getHeaders(name)来获取
35 | * getHeaderNames 也可能需要覆盖
36 | */
37 | @Override
38 | public String getHeader(String name) {
39 |
40 | String value = super.getHeader(xssEncode(name));
41 | if (value != null) {
42 | value = xssEncode(value);
43 | }
44 | return value;
45 | }
46 |
47 | /**
48 | * 将容易引起xss漏洞的半角字符直接替换成全角字符
49 | * @param s
50 | * @return
51 | */
52 | private static String xssEncode(String s) {
53 | if (s == null || s.isEmpty()) {
54 | return s;
55 | }
56 | StringBuilder sb = new StringBuilder(s.length() + 16);
57 | for (int i = 0; i < s.length(); i++) {
58 | char c = s.charAt(i);
59 | switch (c) {
60 | case '>':
61 | sb.append(">");
62 | break;
63 | case '<':
64 | sb.append("<");
65 | break;
66 | case '\'':
67 | sb.append("'");
68 | break;
69 | case '\"':
70 | sb.append("\"");
71 | break;
72 | case '&':
73 | sb.append("&");
74 | break;
75 | default:
76 | sb.append(c);
77 | break;
78 | }
79 | }
80 | return sb.toString();
81 | }
82 | }
--------------------------------------------------------------------------------
/src/main/java/com/git/comm/utils/u4json/Wrapper.java:
--------------------------------------------------------------------------------
1 | package com.git.comm.utils.u4json;
2 |
3 | import com.github.pagehelper.Page;
4 | import java.io.Serializable;
5 | import org.codehaus.jackson.annotate.JsonIgnore;
6 | import org.codehaus.jackson.map.annotate.JsonSerialize;
7 | import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
8 |
9 | @JsonSerialize(
10 | include = Inclusion.NON_NULL
11 | )
12 | public class Wrapper implements Serializable {
13 | public static final int SUCCESS_CODE = 200;
14 | public static final String SUCCESS_MESSAGE = "操作成功";
15 | public static final int CAPTCHA_CODE_ERROR = 600;
16 | public static final int ERROR_CODE = 500;
17 | public static final String ERROR_MESSAGE = "内部异常";
18 | public static final int ILLEGAL_ARGUMENT_CODE_ = 100;
19 | public static final String ILLEGAL_ARGUMENT_MESSAGE = "参数非法";
20 | private int code;
21 | private String message;
22 | private T result;
23 |
24 | public Wrapper() {
25 | this(200, "操作成功");
26 | }
27 |
28 | public Wrapper(int code, String message) {
29 | this.code(code).message(message);
30 | }
31 |
32 | public Wrapper(int code, String message, T result) {
33 | this.code(code).message(message).result(result);
34 | }
35 |
36 | public Wrapper(int code, String message, T result, Page page) {
37 | this.code(code).message(message).result(result);
38 | }
39 |
40 | public int getCode() {
41 | return this.code;
42 | }
43 |
44 | public void setCode(int code) {
45 | this.code = code;
46 | }
47 |
48 | public String getMessage() {
49 | return this.message;
50 | }
51 |
52 | public void setMessage(String message) {
53 | this.message = message;
54 | }
55 |
56 | public T getResult() {
57 | return this.result;
58 | }
59 |
60 | public void setResult(T result) {
61 | this.result = result;
62 | }
63 |
64 | public Wrapper code(int code) {
65 | this.setCode(code);
66 | return this;
67 | }
68 |
69 | public Wrapper message(String message) {
70 | this.setMessage(message);
71 | return this;
72 | }
73 |
74 | public Wrapper result(T result) {
75 | this.setResult(result);
76 | return this;
77 | }
78 |
79 | @JsonIgnore
80 | public boolean isSuccess() {
81 | return 200 == this.code;
82 | }
83 |
84 | @JsonIgnore
85 | public boolean isFail() {
86 | return 200 != this.code;
87 | }
88 |
89 | public String toString() {
90 | return "Wrapper{code=" + this.code + ", message=\'" + this.message + '\'' + ", result=" + this.result + '}';
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/src/main/java/com/git/comm/utils/u4os/LinuxSystemTool.java:
--------------------------------------------------------------------------------
1 | package com.git.comm.utils.u4os;
2 |
3 | import java.io.*;
4 | import java.util.StringTokenizer;
5 |
6 | public final class LinuxSystemTool {
7 | /**
8 | * @return int[] result
9 | * result.length==4;int[0]=MemTotal;int[1]=MemFree;int[2]=SwapTotal;int[3]=SwapFree;
10 | */
11 | public static int[] getMemInfo() throws IOException, InterruptedException {
12 | File file = new File("/proc/meminfo");
13 | BufferedReader br = new BufferedReader(new InputStreamReader(
14 | new FileInputStream(file)));
15 | int[] result = new int[4];
16 | String str = null;
17 | StringTokenizer token = null;
18 | while((str = br.readLine()) != null) {
19 | token = new StringTokenizer(str);
20 | if(!token.hasMoreTokens())
21 | continue;
22 |
23 | str = token.nextToken();
24 | if(!token.hasMoreTokens())
25 | continue;
26 |
27 | if(str.equalsIgnoreCase("MemTotal:"))
28 | result[0] = Integer.parseInt(token.nextToken());
29 | else if(str.equalsIgnoreCase("MemFree:"))
30 | result[1] = Integer.parseInt(token.nextToken());
31 | else if(str.equalsIgnoreCase("SwapTotal:"))
32 | result[2] = Integer.parseInt(token.nextToken());
33 | else if(str.equalsIgnoreCase("SwapFree:"))
34 | result[3] = Integer.parseInt(token.nextToken());
35 | }
36 | return result;
37 | }
38 |
39 | public static float getCpuInfo() throws IOException, InterruptedException {
40 | File file = new File("/proc/stat");
41 | BufferedReader br = new BufferedReader(new InputStreamReader(
42 | new FileInputStream(file)));
43 | StringTokenizer token = new StringTokenizer(br.readLine());
44 | token.nextToken();
45 | int user1 = Integer.parseInt(token.nextToken());
46 | int nice1 = Integer.parseInt(token.nextToken());
47 | int sys1 = Integer.parseInt(token.nextToken());
48 | int idle1 = Integer.parseInt(token.nextToken());
49 |
50 | Thread.sleep(1000);
51 |
52 | br = new BufferedReader(
53 | new InputStreamReader(new FileInputStream(file)));
54 | token = new StringTokenizer(br.readLine());
55 | token.nextToken();
56 | int user2 = Integer.parseInt(token.nextToken());
57 | int nice2 = Integer.parseInt(token.nextToken());
58 | int sys2 = Integer.parseInt(token.nextToken());
59 | int idle2 = Integer.parseInt(token.nextToken());
60 |
61 | return (float)((user2 + sys2 + nice2) - (user1 + sys1 + nice1)) / (float)((user2 + nice2 + sys2 + idle2) - (user1 + nice1 + sys1 + idle1));
62 | }
63 | }
64 |
65 |
66 |
--------------------------------------------------------------------------------
/src/main/java/com/git/comm/utils/u4common/FtpUtils.java:
--------------------------------------------------------------------------------
1 | package com.git.comm.utils.u4common;
2 |
3 | import org.apache.commons.vfs2.*;
4 | import org.apache.commons.vfs2.provider.ftp.FtpFileSystemConfigBuilder;
5 | import org.apache.commons.vfs2.provider.sftp.SftpFileSystemConfigBuilder;
6 |
7 | import java.io.IOException;
8 |
9 | /**
10 | * FtpUtils
11 | */
12 | public class FtpUtils {
13 |
14 | /**
15 | * 得到远程文件列表
16 | */
17 | public static FileObject[] getFilesByFtp(String url){
18 | FileObject[] fileObjects = null;
19 | try {
20 | FileSystemManager fsManager = VFS.getManager();
21 | FileObject fo = fsManager.resolveFile(url);
22 | FileSystemOptions options = new FileSystemOptions();
23 | FtpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(options, false);
24 | fileObjects = fo.getChildren();
25 | } catch (FileSystemException e) {
26 | e.printStackTrace();
27 | } catch (IOException e) {
28 | e.printStackTrace();
29 | }
30 | return fileObjects;
31 | }
32 |
33 | /**
34 | * 筛选所需文件
35 | */
36 | public static FileObject[] getNeedFiles(String url){
37 | FileObject[] fileObjects = getFilesByFtp(url);
38 | FileObject[] newFileObjects = null;
39 | for (int i = 0; i < fileObjects.length; i++){
40 | // 在此处做文件筛选
41 | }
42 | return newFileObjects;
43 | }
44 |
45 | /**
46 | * ftp/sftp
47 | * 通过前置服务器无跳板机上传至所需服务器
48 | * @param sourcePath 前置服务器地址
49 | * @param targetPath 上传服务器地址
50 | * @throws FileSystemException
51 | */
52 | public static void copyFile(String sourcePath, String targetPath) throws FileSystemException {
53 | try {
54 | FileObject[] getDownloadFiles = null;
55 | // 获取需要上传的文件
56 | FileSystemManager fsManager = VFS.getManager();
57 | // 全部文件
58 | getDownloadFiles = getFilesByFtp(sourcePath);
59 | // 如需筛选,选用下面方法
60 | // getDownloadFiles = getNeedFiles(sourcePath);
61 | // 上传文件至服务器
62 | FileSystemOptions opts = new FileSystemOptions();;
63 | SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(opts, "no");
64 | FileObject getUploadFiles = fsManager.resolveFile(targetPath, opts);
65 | for (int i = 0; i < getDownloadFiles.length; i++) {
66 | FileObject tmp = fsManager.resolveFile(getUploadFiles, getDownloadFiles[i].getName().getBaseName());
67 | if (!tmp.exists()) {
68 | tmp.copyFrom(getDownloadFiles[i], Selectors.SELECT_SELF);
69 | }
70 | }
71 | } catch (FileSystemException e) {
72 | e.printStackTrace();
73 | }
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/src/main/java/com/git/comm/utils/u4common/DingDingMessageUtil.java:
--------------------------------------------------------------------------------
1 | package com.git.comm.utils.u4common;
2 |
3 | import com.git.comm.utils.u4json.JsonUtils;
4 | import org.springframework.beans.factory.annotation.Value;
5 | import org.springframework.stereotype.Component;
6 |
7 | import java.io.InputStream;
8 | import java.io.OutputStream;
9 | import java.net.HttpURLConnection;
10 | import java.net.URL;
11 |
12 | /**
13 | * 钉钉机器人发送消息
14 | * https://open-doc.dingtalk.com/docs/doc.htm?spm=a219a.7629140.0.0.karFPe&treeId=257&articleId=105735&docType=1
15 | *
16 | * @author github -> https://github.com/yinjihuan
17 | */
18 | @Component
19 | public class DingDingMessageUtil {
20 |
21 | @Value("${ding-access-token}")
22 | public String dingAccessToken;
23 | @Value("${ding-open}")
24 | private Boolean dingOpen;
25 |
26 | public void sendTextMessage(String msg) {
27 | try {
28 | if (dingOpen) {
29 | Message message = new Message();
30 | message.setMsgtype("text");
31 | message.setText(new MessageInfo(msg));
32 | URL url = new URL("https://oapi.dingtalk.com/robot/send?access_token=" + dingAccessToken);
33 | // 建立http连接
34 | HttpURLConnection conn = (HttpURLConnection) url.openConnection();
35 | conn.setDoOutput(true);
36 | conn.setDoInput(true);
37 | conn.setUseCaches(false);
38 | conn.setRequestMethod("POST");
39 | conn.setRequestProperty("Charset", "UTF-8");
40 | conn.setRequestProperty("Content-Type", "application/Json; charset=UTF-8");
41 | conn.connect();
42 | OutputStream out = conn.getOutputStream();
43 | String textMessage = JsonUtils.toJson(message);
44 | byte[] data = textMessage.getBytes();
45 | out.write(data);
46 | out.flush();
47 | out.close();
48 | InputStream in = conn.getInputStream();
49 | byte[] data1 = new byte[in.available()];
50 | in.read(data1);
51 | }
52 | } catch (Exception e) {
53 | // 不处理异常
54 | }
55 | }
56 | }
57 |
58 | class Message {
59 | private String msgtype;
60 | private MessageInfo text;
61 |
62 | public String getMsgtype() {
63 | return msgtype;
64 | }
65 |
66 | public MessageInfo getText() {
67 | return text;
68 | }
69 |
70 | public void setMsgtype(String msgtype) {
71 | this.msgtype = msgtype;
72 | }
73 |
74 | public void setText(MessageInfo text) {
75 | this.text = text;
76 | }
77 | }
78 |
79 | class MessageInfo {
80 | private String content;
81 |
82 | public MessageInfo(String content) {
83 | this.content = content;
84 | }
85 | }
--------------------------------------------------------------------------------
/src/main/java/com/git/comm/utils/u4net/CookieUtils.java:
--------------------------------------------------------------------------------
1 | package com.git.comm.utils.u4net;
2 |
3 | import javax.servlet.http.Cookie;
4 | import javax.servlet.http.HttpServletRequest;
5 | import javax.servlet.http.HttpServletResponse;
6 | import java.io.UnsupportedEncodingException;
7 | import java.net.URLDecoder;
8 | import java.net.URLEncoder;
9 |
10 | /**
11 | * Cookie
12 | */
13 | public class CookieUtils {
14 |
15 | /**
16 | * 设置 Cookie(生成时间为1天)
17 | * @param name 名称
18 | * @param value 值
19 | */
20 | public static void setCookie(HttpServletResponse response, String name, String value) {
21 | setCookie(response, name, value, 60*60*24);
22 | }
23 |
24 | /**
25 | * 设置 Cookie
26 | * @param name 名称
27 | * @param value 值
28 | */
29 | public static void setCookie(HttpServletResponse response, String name, String value, String path) {
30 | setCookie(response, name, value, path, 60*60*24);
31 | }
32 |
33 | /**
34 | * 设置 Cookie
35 | * @param name 名称
36 | * @param value 值
37 | * @param maxAge 生存时间(单位秒)
38 | */
39 | public static void setCookie(HttpServletResponse response, String name, String value, int maxAge) {
40 | setCookie(response, name, value, "/", maxAge);
41 | }
42 |
43 | /**
44 | * 设置 Cookie
45 | * @param name 名称
46 | * @param value 值
47 | * @param maxAge 生存时间(单位秒)
48 | */
49 | public static void setCookie(HttpServletResponse response, String name, String value, String path, int maxAge) {
50 | Cookie cookie = new Cookie(name, null);
51 | cookie.setPath(path);
52 | cookie.setMaxAge(maxAge);
53 | try {
54 | cookie.setValue(URLEncoder.encode(value, "utf-8"));
55 | } catch (UnsupportedEncodingException e) {
56 | e.printStackTrace();
57 | }
58 | response.addCookie(cookie);
59 | }
60 |
61 | /**
62 | * 获得指定Cookie的值
63 | * @param name 名称
64 | * @return 值
65 | */
66 | public static String getCookie(HttpServletRequest request, String name) {
67 | return getCookie(request, null, name, false);
68 | }
69 | /**
70 | * 获得指定Cookie的值,并删除。
71 | * @param name 名称
72 | * @return 值
73 | */
74 | public static String getCookie(HttpServletRequest request, HttpServletResponse response, String name) {
75 | return getCookie(request, response, name, true);
76 | }
77 | /**
78 | * 获得指定Cookie的值
79 | * @param request 请求对象
80 | * @param response 响应对象
81 | * @param name 名字
82 | * @param isRemove 是否移除
83 | * @return 值
84 | */
85 | public static String getCookie(HttpServletRequest request, HttpServletResponse response, String name, boolean isRemove) {
86 | String value = null;
87 | Cookie[] cookies = request.getCookies();
88 | if (cookies != null) {
89 | for (Cookie cookie : cookies) {
90 | if (cookie.getName().equals(name)) {
91 | try {
92 | value = URLDecoder.decode(cookie.getValue(), "utf-8");
93 | } catch (UnsupportedEncodingException e) {
94 | e.printStackTrace();
95 | }
96 | if (isRemove) {
97 | cookie.setMaxAge(0);
98 | response.addCookie(cookie);
99 | }
100 | }
101 | }
102 | }
103 | return value;
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/src/main/java/com/git/comm/utils/u4common/PropertiesCacheUtils.java:
--------------------------------------------------------------------------------
1 | package com.git.comm.utils.u4common;
2 |
3 | import org.slf4j.Logger;
4 | import org.slf4j.LoggerFactory;
5 |
6 | import java.io.IOException;
7 | import java.io.InputStream;
8 | import java.util.Map;
9 | import java.util.Properties;
10 | import java.util.concurrent.ConcurrentHashMap;
11 |
12 | /**
13 | * 所有properties配置缓存
14 | */
15 | public class PropertiesCacheUtils {
16 |
17 | private static final Logger LOGGER = LoggerFactory.getLogger(PropertiesCacheUtils.class);
18 | private static Map propertiesAttrMap = new ConcurrentHashMap();
19 |
20 | //缓存properties文件
21 | private static Map propertiesCache = new ConcurrentHashMap();
22 |
23 | public static String getValue(String key){
24 | String value = propertiesAttrMap.get(key);
25 | if(value == null){
26 | try {
27 | throw new Exception("没有配置" + key);
28 | } catch (Exception e) {
29 | e.printStackTrace();
30 | }
31 | }
32 | return value;
33 | }
34 |
35 | public static Integer getInteger(String key){
36 | return Integer.valueOf(getValue(key));
37 |
38 | }
39 |
40 | public static Long getLong(String key){
41 | return Long.valueOf(getValue(key));
42 |
43 | }
44 |
45 | public static Boolean getBoolean(String key){
46 | return Boolean.valueOf(getValue(key));
47 |
48 | }
49 |
50 | public static Double getDouble(String key){
51 | return Double.valueOf(getValue(key));
52 |
53 | }
54 |
55 | public static Map getPropertiesMap(){
56 | return propertiesAttrMap;
57 | }
58 |
59 |
60 | public static Map getProperties() {
61 | return propertiesCache;
62 | }
63 |
64 |
65 | /**
66 | * 获取properties
67 | * @param propertiesName
68 | * @return
69 | */
70 | public static Properties getProperties(String propertiesName){
71 | InputStream inputStream;
72 | Properties properties =propertiesCache.get(propertiesName);
73 | if(properties == null){
74 | inputStream = PropertiesCacheUtils.class.getResourceAsStream("/" + propertiesName);
75 | properties = new Properties();
76 | try {
77 | properties.load(inputStream);
78 | inputStream.close();
79 | } catch (IOException e) {
80 | LOGGER.warn(e.getMessage(),e);
81 | //某些情况下释放资源;比如LOAD报错
82 | inputStream = null;
83 | }
84 | if(properties != null){
85 | propertiesCache.put(propertiesName, properties);
86 | prorsToMap(properties);
87 | }
88 | }
89 | return properties;
90 | }
91 |
92 | public static void prorsToMap(Properties properties){
93 | for(Object key:properties.keySet()){
94 | String strKey = key.toString();
95 | String value = properties.getProperty(strKey);
96 | propertiesAttrMap.put(strKey, value);
97 | }
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/src/main/java/com/git/comm/utils/u4json/JsonUtils.java:
--------------------------------------------------------------------------------
1 | package com.git.comm.utils.u4json;
2 |
3 | import org.codehaus.jackson.map.ObjectMapper;
4 |
5 | import java.io.StringWriter;
6 | import java.util.HashMap;
7 | import java.util.Map;
8 |
9 | /**
10 | * Json 工具类
11 | */
12 | public class JsonUtils {
13 | private static ObjectMapper mapper = new ObjectMapper();
14 |
15 | public static String toString(Object obj) {
16 | return toJson(obj);
17 | }
18 |
19 | public static String toJson(Object obj) {
20 | try {
21 | StringWriter writer = new StringWriter();
22 | mapper.writeValue(writer, obj);
23 | return writer.toString();
24 | } catch (Exception e) {
25 | throw new RuntimeException("序列化对象【" + obj + "】时出错", e);
26 | }
27 | }
28 |
29 | public static T toBean(Class entityClass, String jsonString) {
30 | try {
31 | return mapper.readValue(jsonString, entityClass);
32 | } catch (Exception e) {
33 | throw new RuntimeException("JSON【" + jsonString + "】转对象时出错", e);
34 | }
35 | }
36 |
37 | /**
38 | * 用于对象通过其他工具已转为JSON的字符形式,这里不需要再加上引号
39 | *
40 | * @param obj
41 | * @param isObject
42 | */
43 | public static String getJsonSuccess(String obj, boolean isObject) {
44 | String jsonString = null;
45 | if (obj == null) {
46 | jsonString = "{\"success\":true}";
47 | } else {
48 | jsonString = "{\"success\":true,\"data\":" + obj + "}";
49 | }
50 | return jsonString;
51 | }
52 |
53 | public static String getJsonSuccess(Object obj) {
54 | return getJsonSuccess(obj, null);
55 | }
56 |
57 | public static String getJsonSuccess(Object obj, String message) {
58 | if (obj == null) {
59 | return "{\"success\":true,\"message\":\"" + message + "\"}";
60 | } else {
61 | try {
62 | Map map = new HashMap();
63 | map.put("success", true);
64 | return "{\"success\":true," + toString(obj) + ",\"message\":\"" + message + "\"}";
65 | } catch (Exception e) {
66 | throw new RuntimeException("序列化对象【" + obj + "】时出错", e);
67 | }
68 | }
69 | }
70 |
71 | public static String getJsonError(Object obj) {
72 | return getJsonError(obj, null);
73 | }
74 |
75 | public static String getJsonError(Object obj, String message) {
76 | if (obj == null) {
77 | return "{\"success\":false,\"message\":\"" + message + "\"}";
78 | } else {
79 | try {
80 | obj = parseIfException(obj);
81 | return "{\"success\":false,\"data\":" + toString(obj) + ",\"message\":\"" + message + "\"}";
82 | } catch (Exception e) {
83 | throw new RuntimeException("序列化对象【" + obj + "】时出错", e);
84 | }
85 | }
86 | }
87 |
88 | public static Object parseIfException(Object obj) {
89 | if (obj instanceof Exception) {
90 | return getErrorMessage((Exception) obj, null);
91 | }
92 | return obj;
93 | }
94 |
95 | public static String getErrorMessage(Exception e, String defaultMessage) {
96 | return defaultMessage != null ? defaultMessage : null;
97 | }
98 |
99 | public static ObjectMapper getMapper() {
100 | return mapper;
101 | }
102 | }
--------------------------------------------------------------------------------
/src/main/java/com/git/comm/utils/u4img/ImageUtils.java:
--------------------------------------------------------------------------------
1 | package com.git.comm.utils.u4img;
2 |
3 | import com.git.comm.utils.u4string.StringUtils;
4 |
5 | import javax.imageio.ImageIO;
6 | import javax.imageio.stream.ImageOutputStream;
7 | import java.awt.*;
8 | import java.awt.geom.Ellipse2D;
9 | import java.awt.image.BufferedImage;
10 | import java.io.*;
11 |
12 | /**
13 | * Created by dragon on 1/21/2018.
14 | */
15 | public class ImageUtils {
16 |
17 | /**
18 | * 将文字生成图片
19 | * @param text
20 | * @param width
21 | * @param height
22 | * @param fontSize
23 | * @return
24 | */
25 | public String textToPic(String text, int width, int height, int fontSize) {
26 | String textPath = "";
27 | try {
28 | String fileName = StringUtils.getUUID() + ".png";
29 | // 修改filePath
30 | String filePath = "" + fileName;
31 | File file = new File(filePath);
32 | Font font = new Font("华文隶书", Font.BOLD, fontSize);
33 | BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);
34 | Graphics2D g2 = (Graphics2D) bi.getGraphics();
35 | g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
36 | g2.setFont(font);
37 | g2.setPaint(Color.red);
38 | paintString(g2, text,1,270, fontSize);
39 | g2.dispose();
40 | ImageIO.write(bi, "png", file);
41 | // BufferedImage 转换 InputStream
42 | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
43 | ImageOutputStream imageOutput = ImageIO.createImageOutputStream(byteArrayOutputStream);
44 | ImageIO.write(bi, "png", imageOutput);
45 | } catch (Exception e) {
46 | e.printStackTrace();
47 | }
48 | return textPath;
49 | }
50 |
51 | public static void paintString(Graphics2D g2d, String str, int x, int y, int fontSize) {
52 | FontMetrics metrics = g2d.getFontMetrics();
53 | for (char ca : str.toCharArray()) {
54 | int px = metrics.stringWidth("" + ca);
55 | g2d.drawString("" + ca, x + (fontSize - px) / 2, y);
56 | x += fontSize;
57 | }
58 | }
59 |
60 | /**
61 | * 对图片进行成比例缩小
62 | * @param originalImage 原始图片
63 | * @param times 缩小倍数
64 | * @return 缩小后的Image
65 | */
66 | public static BufferedImage zoomOutImage(BufferedImage originalImage, Integer times){
67 | // 50是自己新增的,可删除
68 | int width = originalImage.getWidth() / times + 50;
69 | int height = originalImage.getHeight() / times + 50;
70 | BufferedImage newImage = new BufferedImage(width, height, originalImage.getType());
71 | Graphics g = newImage.getGraphics();
72 | g.drawImage(originalImage, 0, 0, width, height,null);
73 | g.dispose();
74 | return newImage;
75 |
76 | }
77 |
78 | /**
79 | * 传入的图像必须是正方形的 才会 圆形 如果是长方形的比例则会变成椭圆的
80 | * @return
81 | * @throws IOException
82 | */
83 | public static BufferedImage convertCircular(BufferedImage bi1, String url) throws IOException{
84 | //透明底的图片
85 | BufferedImage bi2 = new BufferedImage(bi1.getWidth(), bi1.getHeight(), BufferedImage.TYPE_4BYTE_ABGR);
86 | // 第一个值x 和第二个值y 是圈定图片选中的位置
87 | Ellipse2D.Double shape = new Ellipse2D.Double(0, 0,bi1.getWidth(), bi1.getHeight());
88 | Graphics2D g2 = bi2.createGraphics();
89 | g2.setClip(shape);
90 | // 使用 setRenderingHint 设置抗锯齿
91 | g2.drawImage(bi1,0,0,null);
92 | g2.dispose();
93 | return bi2;
94 | }
95 |
96 | }
97 |
--------------------------------------------------------------------------------
/src/main/java/com/git/comm/utils/u4decimal/BigDemicalUtils.java:
--------------------------------------------------------------------------------
1 | package com.git.comm.utils.u4decimal;
2 |
3 | import java.math.BigDecimal;
4 |
5 | public class BigDemicalUtils {
6 | /**
7 | * 提供精确加法计算的add方法
8 | *
9 | * @param value1 被加数
10 | * @param value2 加数
11 | * @return 两个参数的和
12 | */
13 | public static double add(double value1, double value2) {
14 | BigDecimal b1 = new BigDecimal(Double.valueOf(value1));
15 | BigDecimal b2 = new BigDecimal(Double.valueOf(value2));
16 | return b1.add(b2).doubleValue();
17 | }
18 |
19 | /**
20 | * 提供精确减法运算的sub方法
21 | *
22 | * @param value1 被减数
23 | * @param value2 减数
24 | * @return 两个参数的差
25 | */
26 | public static double sub(double value1, double value2) {
27 | BigDecimal b1 = new BigDecimal(Double.valueOf(value1));
28 | BigDecimal b2 = new BigDecimal(Double.valueOf(value2));
29 | return b1.subtract(b2).doubleValue();
30 | }
31 |
32 | /**
33 | * 提供精确乘法运算的mul方法
34 | *
35 | * @param value1 被乘数
36 | * @param value2 乘数
37 | * @return 两个参数的积
38 | */
39 | public static double mul(double value1, double value2) {
40 | BigDecimal b1 = new BigDecimal(Double.valueOf(value1));
41 | BigDecimal b2 = new BigDecimal(Double.valueOf(value2));
42 | return b1.multiply(b2).doubleValue();
43 | }
44 |
45 | /**
46 | * 提供(相对)精确的除法运算。当发生除不尽的情况时,由scale参数指定精度,以后的数字四舍五入。
47 | *
48 | * @param value1 被除数
49 | * @param value2 除数
50 | * @param scale 表示表示需要精确到小数点以后几位。
51 | * @return 两个参数的商
52 | */
53 | public static BigDecimal div(double value1, double value2, int scale) throws IllegalAccessException {
54 | if (scale < 0) {
55 | //如果精确范围小于0,抛出异常信息。
56 | throw new IllegalArgumentException("精确度不能小于0");
57 | } else if (value2 == 0) {
58 | //如果除数为0,抛出异常信息。
59 | throw new IllegalArgumentException("除数不能为0");
60 | }
61 | BigDecimal b1 = new BigDecimal(Double.valueOf(value1));
62 | BigDecimal b2 = new BigDecimal(Double.valueOf(value2));
63 | return b1.divide(b2, scale, BigDecimal.ROUND_HALF_UP);
64 | }
65 |
66 | /**
67 | * 提供精确的小数位四舍五入处理。
68 | *
69 | * @param v 需要四舍五入的数字
70 | * @param scale 小数点后保留几位
71 | * @return 四舍五入后的结果
72 | */
73 | public static BigDecimal round(double v, int scale) {
74 | if (scale < 0) {
75 | throw new IllegalArgumentException("精确度不能小于0");
76 | }
77 | BigDecimal b = new BigDecimal(Double.toString(v));
78 | BigDecimal one = new BigDecimal("1");
79 | return b.divide(one, scale, BigDecimal.ROUND_HALF_UP);
80 | }
81 |
82 | /**
83 | * 提供精确加法计算的add方法,确认精确度
84 | *
85 | * @param value1 被加数
86 | * @param value2 加数
87 | * @param scale 小数点后保留几位
88 | * @return 两个参数求和之后,按精度四舍五入的结果
89 | */
90 | public static BigDecimal add(double value1, double value2, int scale) {
91 | return round(add(value1, value2), scale);
92 | }
93 |
94 | /**
95 | * 提供精确减法运算的sub方法,确认精确度
96 | *
97 | * @param value1 被减数
98 | * @param value2 减数
99 | * @param scale 小数点后保留几位
100 | * @return 两个参数的求差之后,按精度四舍五入的结果
101 | */
102 | public static BigDecimal sub(double value1, double value2, int scale) {
103 | return round(sub(value1, value2), scale);
104 | }
105 |
106 | /**
107 | * 提供精确乘法运算的mul方法,确认精确度
108 | *
109 | * @param value1 被乘数
110 | * @param value2 乘数
111 | * @param scale 小数点后保留几位
112 | * @return 两个参数的乘积之后,按精度四舍五入的结果
113 | */
114 | public static BigDecimal mul(double value1, double value2, int scale) {
115 | return round(mul(value1, value2), scale);
116 | }
117 |
118 |
119 | /**
120 | * 比较两个 BigDecimal 类型的数值 是否相等
121 | * 如果 其中一个 为null 返回 false
122 | * 如果 都为 null 返回 false
123 | * 如果 相等 返回 true
124 | * 如果 不等 返回 false
125 | */
126 | public static boolean equals(BigDecimal b1, BigDecimal b2) {
127 | if (b1 == null || b2 == null) {
128 | return false;
129 | }
130 | int i = b1.compareTo(b2);
131 | if (i != 0) {
132 | return false;
133 | }
134 | return true;
135 | }
136 |
137 | public static BigDecimal add(BigDecimal... values) {
138 | if (values.length == 0) {
139 | return null;
140 | }
141 | BigDecimal sum = BigDecimal.valueOf(0);
142 | for (BigDecimal value : values) {
143 | if (value == null) {
144 | value = BigDecimal.valueOf(0);
145 | }
146 | sum = sum.add(value);
147 | }
148 | return sum;
149 | }
150 | }
151 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 | com.git.comm.utils
7 | commutils4j
8 | 0.1
9 |
10 | org.springframework.boot
11 | spring-boot-starter-parent
12 | 1.4.2.RELEASE
13 |
14 |
15 |
16 |
17 |
18 | junit
19 | junit
20 | 4.13.1
21 |
22 |
23 |
24 | com.github.pagehelper
25 | pagehelper
26 | 5.3.1
27 |
28 |
29 |
30 | org.modelmapper
31 | modelmapper
32 | 0.7.5
33 |
34 |
35 |
36 | org.slf4j
37 | slf4j-api
38 | 1.7.25
39 |
40 |
41 |
42 | org.codehaus.jackson
43 | jackson-core-asl
44 | 1.9.13
45 |
46 |
47 | org.codehaus.jackson
48 | jackson-mapper-asl
49 | 1.9.13
50 |
51 |
52 |
53 | com.alibaba
54 | fastjson
55 | 1.2.83
56 |
57 |
58 |
59 | ant
60 | ant
61 | 1.6.5
62 |
63 |
64 |
65 | javax.servlet
66 | servlet-api
67 | 2.5
68 | provided
69 |
70 |
71 |
72 | org.apache.commons
73 | commons-vfs2
74 | 2.0
75 |
76 |
77 |
78 | commons-io
79 | commons-io
80 | 2.7
81 |
82 |
83 |
84 | commons-httpclient
85 | commons-httpclient
86 | 3.0
87 |
88 |
89 |
90 | commons-net
91 | commons-net
92 | 3.9.0
93 |
94 |
95 |
96 | org.apache.commons
97 | commons-lang3
98 | 3.4
99 |
100 |
101 |
102 | com.google.collections
103 | google-collections
104 | 1.0
105 |
106 |
107 |
108 | org.apache.commons
109 | commons-lang3
110 | 3.4
111 |
112 |
113 |
114 | org.springframework.boot
115 | spring-boot-starter-redis
116 |
117 |
118 |
119 | org.apache.httpcomponents
120 | httpclient
121 | 4.5.13
122 |
123 |
124 |
--------------------------------------------------------------------------------
/src/main/java/com/git/comm/utils/u4string/StringUtils.java:
--------------------------------------------------------------------------------
1 | package com.git.comm.utils.u4string;
2 |
3 | import com.git.comm.utils.u4list.ListUtils;
4 |
5 | import java.io.UnsupportedEncodingException;
6 | import java.net.URLEncoder;
7 | import java.util.Collection;
8 | import java.util.UUID;
9 | import java.util.regex.Matcher;
10 | import java.util.regex.Pattern;
11 |
12 | public class StringUtils {
13 |
14 | /**
15 | * 判断一个或多个对象是否为空
16 | *
17 | * @param values
18 | * 可变参数,要判断的一个或多个对象
19 | * @return 只有要判断的一个对象都为空则返回true,否则返回false
20 | */
21 | public static boolean isNull(Object... values) {
22 | if (!ListUtils.isNotNullAndNotEmpty(values)) {
23 | return true;
24 | }
25 | for (Object value : values) {
26 | boolean flag = false;
27 | if (value instanceof Object[]) {
28 | flag = !ListUtils.isNotNullAndNotEmpty((Object[]) value);
29 | } else if (value instanceof Collection>) {
30 | flag = !ListUtils.isNotNullAndNotEmpty((Collection>) value);
31 | } else if (value instanceof String) {
32 | flag = isOEmptyOrNull(value);
33 | } else {
34 | flag = (null == value);
35 | }
36 | if (flag) {
37 | return true;
38 | }
39 | }
40 | return false;
41 | }
42 |
43 | public static boolean isOEmptyOrNull(Object o) {
44 | return o == null ? true : isSEmptyOrNull(o.toString());
45 | }
46 |
47 | public static boolean isSEmptyOrNull(String s) {
48 | return trimAndNullAsEmpty(s).length() <= 0 ? true : false;
49 | }
50 |
51 | public static String trimAndNullAsEmpty(String s) {
52 | if (s != null && !s.trim().equals("-")) {
53 | return s.trim();
54 | } else {
55 | return "";
56 | }
57 | }
58 |
59 |
60 | /**
61 | * 判断字符串是否为空
62 | * @param str
63 | * @return
64 | */
65 | public static boolean isEmpty(String str) {
66 | return str == null || str.length() == 0;
67 | }
68 |
69 | /**
70 | * 判断字符串是否为空
71 | * @param str
72 | * @return
73 | */
74 | public static boolean isSNullOrEmpty(String str) {
75 | return str == null || "".equals(str.trim());
76 | }
77 |
78 | /**
79 | * 判断字符串组是否为空
80 | * @param strs
81 | * @return
82 | */
83 | public static boolean isStrsEmptyOrNull(String... strs) {
84 | if(strs != null && strs.length != 0) {
85 | String[] arr$ = strs;
86 | int len$ = strs.length;
87 | for(int i$ = 0; i$ < len$; ++i$) {
88 | String str = arr$[i$];
89 | if(str == null || str.trim().equals("")) {
90 | return true;
91 | }
92 | }
93 | return false;
94 | } else {
95 | return true;
96 | }
97 | }
98 |
99 | /**
100 | * 随机获取32位UUID字符串(无中划线)
101 | *
102 | * @return UUID字符串
103 | */
104 | public static String getUUID() {
105 | String uuid = UUID.randomUUID().toString();
106 | return uuid.substring(0, 8) + uuid.substring(9, 13) + uuid.substring(14, 18) + uuid.substring(19, 23) + uuid.substring(24);
107 | }
108 |
109 | /**
110 | * 返回一个utf8的字符串
111 | * @param str
112 | * @return str
113 | */
114 | public static String utf8Encode(String str) {
115 | if (!isEmpty(str) && str.getBytes().length != str.length()) {
116 | try {
117 | return URLEncoder.encode(str, "UTF-8");
118 | } catch (UnsupportedEncodingException e) {
119 | throw new RuntimeException("UnsupportedEncodingException occurred.", e);
120 | }
121 | }
122 | return str;
123 | }
124 |
125 | /**
126 | * 返回一个html
127 | * @param href
128 | * @return href
129 | */
130 | public static String getHrefInnerHtml(String href) {
131 | if (isEmpty(href)) {
132 | return "";
133 | }
134 | String hrefReg = ".*<[\\s]*a[\\s]*.*>(.+?)<[\\s]*/a[\\s]*>.*";
135 | Pattern hrefPattern = Pattern.compile(hrefReg,
136 | Pattern.CASE_INSENSITIVE);
137 | Matcher hrefMatcher = hrefPattern.matcher(href);
138 | if (hrefMatcher.matches()) {
139 | return hrefMatcher.group(1);
140 | }
141 | return href;
142 | }
143 |
144 | /**
145 | * 如果字符串没有超过最长显示长度返回原字符串,否则从开头截取指定长度并加...返回。
146 | * @param str
147 | * @param length
148 | * @return str
149 | */
150 | public static String trimString(String str, int length) {
151 | if (str == null) {
152 | return "";
153 | } else if (str.length() > length) {
154 | return str.substring(0, length - 3) + "...";
155 | } else {
156 | return str;
157 | }
158 | }
159 | }
160 |
--------------------------------------------------------------------------------
/src/main/java/com/git/comm/utils/u4string/ChinaUpperCaseUtil.java:
--------------------------------------------------------------------------------
1 | package com.git.comm.utils.u4string;
2 |
3 | /**
4 | * Double类型金额 转换 大写中文
5 | *
6 | * @see "调用方法getTurnMoneys"({@String})
7 | */
8 | public class ChinaUpperCaseUtil {
9 |
10 | private static String moneyD = new String();
11 | private static String moneyBefore = new String();
12 | private static String moneyAfter = new String();
13 |
14 |
15 | public static String getTurns(int i) {
16 | switch (i) {
17 | case 2:
18 | moneyD = "拾";
19 | break;
20 | case 3:
21 | moneyD = "佰";
22 | break;
23 | case 4:
24 | moneyD = "仟";
25 | break;
26 | case 5:
27 | moneyD = "万";
28 | break;
29 | case 6:
30 | moneyD = "拾";
31 | break;
32 | case 7:
33 | moneyD = "佰";
34 | break;
35 | case 8:
36 | moneyD = "仟";
37 | break;
38 | case 9:
39 | moneyD = "亿";
40 | break;
41 | case 10:
42 | moneyD = "拾";
43 | break;
44 |
45 | case 11:
46 | moneyD = "佰";
47 | break;
48 | case 12:
49 | moneyD = "仟";
50 | break;
51 | }
52 | return moneyD.toString();
53 | }
54 |
55 | public static String getTurnMoneyWord(String s) {
56 | switch (Integer.parseInt(s)) {
57 | case 0:
58 | return "零";
59 | case 1:
60 | return "壹";
61 | case 2:
62 | return "贰";
63 | case 3:
64 | return "叁";
65 | case 4:
66 | return "肆";
67 | case 5:
68 | return "伍";
69 | case 6:
70 | return "陆";
71 | case 7:
72 | return "柒";
73 | case 8:
74 | return "捌";
75 | }
76 | return "玖";
77 | }
78 |
79 | public static String getTurnMoneys(String money) {
80 | StringBuffer moneyA = new StringBuffer();
81 | try {
82 | if (money.indexOf("-") != -1) {
83 | moneyA.append("负");
84 | money = money.substring(money.indexOf("-") + 1, money.length());
85 | }
86 | if (money.indexOf(".") != -1) {
87 | moneyBefore = money.substring(0, money.indexOf("."));
88 | moneyAfter = money.substring(money.indexOf(".") + 1, money.length());
89 | } else {
90 | moneyBefore = money;
91 | moneyAfter = "none";
92 | }
93 | if (moneyBefore.length() == 1 && moneyBefore.charAt(0) == '0' && moneyAfter == "none") {
94 | moneyA.append("零");
95 | moneyA.append("圆");
96 | } else {
97 | for (int i = 0; i < moneyBefore.length(); i++) {
98 | if (moneyBefore.charAt(i) != '0') {
99 | moneyA.append(
100 | getTurnMoneyWord(String.valueOf(String.valueOf(moneyBefore.charAt(i))).concat("")));
101 | if (moneyBefore.length() != i + 1)
102 | moneyA.append(getTurns(moneyBefore.length() - i));
103 | continue;
104 | }
105 | if (moneyBefore.length() - i == 5 && (moneyBefore.length() > 5 && moneyBefore.length() <= 9))
106 | moneyA.append("万");
107 | if (moneyBefore.length() - i == 9 && moneyBefore.length() > 9)
108 | moneyA.append("亿");
109 | if (moneyBefore.length() != i + 1 && moneyBefore.charAt(i + 1) != '0')
110 | moneyA.append("零");
111 | }
112 | if (moneyBefore.length() != 1 || moneyBefore.charAt(0) != '0') {
113 | moneyA.append("圆");
114 | }
115 | }
116 | if (!moneyAfter.equals("none")) {
117 | for (int i = 0; i < moneyAfter.length(); i++) {
118 | if (i == 0)
119 | if (moneyAfter.charAt(i) != '0') {
120 | moneyA.append(
121 | getTurnMoneyWord(String.valueOf(String.valueOf(moneyAfter.charAt(i))).concat("")));
122 |
123 | moneyA.append("角");
124 | } else if (moneyBefore.charAt(0) != '0' && moneyAfter.length() > 1
125 | && (!moneyAfter.equals("00")))
126 | moneyA.append("零");
127 | if (i == 1 && moneyAfter.charAt(i) != '0') {
128 | moneyA.append(
129 | getTurnMoneyWord(String.valueOf(String.valueOf(moneyAfter.charAt(i))).concat("")));
130 | moneyA.append("分");
131 | }
132 | }
133 |
134 | }
135 | if (moneyAfter.equals("none") || moneyAfter.length() != 2 || moneyAfter.equals("00"))
136 | moneyA.append("整");
137 | } catch (Exception exception) {
138 | }
139 | return moneyA.toString();
140 | }
141 |
142 | }
143 |
144 |
--------------------------------------------------------------------------------
/src/main/java/com/git/comm/utils/xss/XssShieldUtil.java:
--------------------------------------------------------------------------------
1 | package com.git.comm.utils.xss;
2 |
3 |
4 | import org.apache.commons.lang3.StringUtils;
5 |
6 | import java.util.ArrayList;
7 | import java.util.List;
8 | import java.util.regex.Matcher;
9 | import java.util.regex.Pattern;
10 |
11 | /**
12 | * 处理非法字符
13 | * Thanks: http://blog.csdn.net/catoop/
14 | */
15 | public class XssShieldUtil {
16 |
17 | private static List patterns = null;
18 |
19 | private static List