Commit 609ffc62 authored by yanzg's avatar yanzg

格式化

parents
Pipeline #115 failed with stages
.idea
*.iml
*.suo
.vs
Debug
bin
obj
target
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.yanzuoguang</groupId>
<artifactId>yzg-util</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<spring.version>4.3.7.RELEASE</spring.version>
<fastjson.version>1.2.47</fastjson.version>
</properties>
<dependencies>
<!-- Spring依赖 -->
<!-- 1.Spring核心依赖 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- 2.Spring dao依赖 -->
<!-- spring-jdbc包括了一些如jdbcTemplate的工具类 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson.version}</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
</dependencies>
</dependencyManagement>
<build>
<directory>${project.basedir}/target/</directory>
<finalName>${project.artifactId}</finalName>
<pluginManagement>
<plugins>
<!-- ===========只打源码包,应用于公共组件打包=========== -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<overwrite>true</overwrite>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<!-- ===========可运行Jar包=========== -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.10.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<testResources>
<testResource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</testResource>
<testResource>
<directory>src/main/resources</directory>
</testResource>
</testResources>
</build>
</project>
\ No newline at end of file
工具类
\ No newline at end of file
This diff is collapsed.
//package com.yanzuoguang.util.cache;
//
//import com.tourbida.sys.core.util.StringHelper;
//
//import java.util.Date;
//import java.util.Hashtable;
//
///**
// * 内存缓存
// *
// * @param <T>
// */
//public class MemoryCache<T> {
//
// /**
// * 缓存的对象
// */
// private Hashtable<String, MemoryCacheItem<T>> cache = new Hashtable<String, MemoryCacheItem<T>>();
//
// /**
// * 清除时间
// */
// private int clearSecond;
//
// /**
// * 是否自动清除缓存
// */
// private boolean isAutoClear;
//
// /**
// * 读取时是否激活
// */
// private boolean isGetActive;
//
// /**
// * 构造函数,不会自动清除对象
// */
// public MemoryCache() {
// this(false, 0);
// }
//
// /**
// * 构造函数
// *
// * @param clearSecond 清除缓存的时间
// */
// public MemoryCache(int clearSecond) {
// this(true, clearSecond);
// }
//
// /**
// * 构造函数
// *
// * @param isAutoClear 是否自动清除
// * @param clearSecond 清除缓存的时间
// */
// public MemoryCache(boolean isAutoClear, int clearSecond) {
// this.isAutoClear = isAutoClear;
// this.clearSecond = clearSecond;
// this.isGetActive = false;
// if (isAutoClear) {
// MemoryCacheCenter.CLEAR_LIST.add(this);
// }
// }
//
// public boolean isGetActive() {
// return isGetActive;
// }
//
// public void setGetActive(boolean getActive) {
// isGetActive = getActive;
// }
//
// public int getClearSecond() {
// return clearSecond;
// }
//
// public void setClearSecond(int clearSecond) {
// this.clearSecond = clearSecond;
// }
//
// /**
// * 写入数据
// *
// * @param key 关键字
// * @param data 数据
// */
// public synchronized T put(String key, T data) {
// if (this.isAutoClear && this.clearSecond < 1) {
// return data;
// }
// MemoryCacheItem<T> item = cache.getOrDefault(key, new MemoryCacheItem<T>());
// item.setData(data);
// if (StringHelper.IsEmpty(item.getName())) {
// item.setName(key);
// cache.put(key, item);
// }
// return item.getData();
// }
//
// /**
// * 读取数据
// *
// * @param key 关键字
// */
// public synchronized T get(String key) {
// if (this.isAutoClear && this.clearSecond < 1) {
// return null;
// }
// MemoryCacheItem<T> item = cache.get(key);
// if (item == null) {
// return null;
// }
// this.getActive(item);
// return item.getData();
// }
//
// /**
// * 读取数据
// *
// * @param key 关键字
// * @param defData 默认数据
// * @return
// */
// public synchronized T get(String key, T defData) {
// if (this.isAutoClear && this.clearSecond < 1) {
// return defData;
// }
// MemoryCacheItem<T> item = cache.getOrDefault(key, new MemoryCacheItem<T>());
// if (StringHelper.IsEmpty(item.getName())) {
// item.setName(key);
// item.setData(defData);
// cache.put(key, item);
// } else {
// if (defData instanceof MemoryCache) {
// ((MemoryCache) defData).close();
// }
// }
// this.getActive(item);
// return item.getData();
// }
//
// /**
// * 在获取时重新激活数据
// */
// private void getActive(MemoryCacheItem<T> item) {
// if (isGetActive) {
// item.active();
// }
// }
//
// /**
// * 删除一个数据
// *
// * @param key 关键字
// */
// public synchronized T remove(String key) {
// MemoryCacheItem<T> item = cache.remove(key);
// if (item == null) {
// return null;
// }
// T data = item.getData();
// if (data instanceof MemoryCache) {
// ((MemoryCache) data).close();
// }
// return data;
// }
//
// /**
// * 清除所有的缓存
// */
// public synchronized void clear() {
// Object[] keys = cache.keySet().toArray();
// for (Object keyObject : keys) {
// // 关键字
// String key = keyObject.toString();
// this.remove(key);
// }
// }
//
// /**
// * 清除超时的数据
// */
// public synchronized void clearTimeout() {
// if (this.clearSecond < 0) {
// return;
// }
// Object[] keys = cache.keySet().toArray();
// Date now = new Date();
// for (Object keyObject : keys) {
// // 关键字
// String key = keyObject.toString();
// // 获取到数据
// MemoryCacheItem<T> itemValue = this.cache.get(key);
// if (itemValue == null) {
// continue;
// }
// // 判断是否过期
// if (now.getTime() - itemValue.getDate().getTime() > this.clearSecond * 1000) {
// this.remove(key);
// }
// }
// }
//
// /**
// * 将缓存对象从缓存对象中清除
// */
// public synchronized void close() {
// this.clear();
// MemoryCacheCenter.CLEAR_LIST.remove(this);
// }
//
// /**
// * 获取所有的关键字
// *
// * @return
// */
// public synchronized String[] getKeys() {
// String[] items = new String[this.cache.size()];
// return this.cache.keySet().toArray(items);
// }
//
// /**
// * 析构函数
// *
// * @throws Throwable
// */
// @Override
// protected void finalize() throws Throwable {
// this.close();
// }
//}
//package com.yanzuoguang.util.cache;
//
//import org.springframework.scheduling.annotation.Scheduled;
//import org.springframework.stereotype.Component;
//
//import java.util.List;
//import java.util.Vector;
//
//@Component
//public class MemoryCacheCenter {
//
// /**
// * 缓存的对象
// */
// public static List<MemoryCache> CLEAR_LIST = new Vector<MemoryCache>();
//
// /**
// * 间隔5秒执行
// */
// @Scheduled(cron = "0/5 * * * * ? ")
// public void clear(){
// // 死循环处理
// ThreadList<MemoryCache> threadList = new ThreadList<MemoryCache>(1) {
// @Override
// public void Execute(MemoryCache item) {
// item.clearTimeout();
// }
// };
// threadList.setPrint(false);
// threadList.add(CLEAR_LIST);
// threadList.waitSucccess(true);
// }
//}
package com.yanzuoguang.util.cache;
import java.util.Date;
/**
* 内存缓存值
* @param <T>
*/
public class MemoryCacheItem<T> {
/**
* 时间
*/
private Date date = new Date();
/**
* 名称
*/
private String name;
/**
* 数据
*/
private T data;
/**
* 激活数据
*/
public void active() {
date = new Date();
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
}
package com.yanzuoguang.util.exception;
/**
* 途比达异常信息
* Created by yanzu on 2018/7/13.
*/
public class CodeException extends RuntimeException {
private static final long serialVersionUID = -4625832188480820883L;
/**
* 错误码
*/
private String code = "99";
/**
* 包含的数据
*/
private Object target = null;
/**
* 获取错误码
*
* @return 返回的结果
*/
public String getCode() {
return this.code;
}
/**
* 来源数据
*
* @return
*/
public Object getTarget() {
return target;
}
/**
* Constructs a new runtime exception with the specified detail message and
* cause. <p>Note that the detail message associated with
* {@code cause} is <i>not</i> automatically incorporated in
* this runtime exception's detail message.
*
* @param code the detail code (which is saved for later retrieval
* by the {@link #getCode()} method).
* @param message the detail message (which is saved for later retrieval
* by the {@link #getMessage()} method).
* @param cause the cause (which is saved for later retrieval by the
* {@link #getCause()} method). (A <tt>null</tt> value is
* permitted, and indicates that the cause is nonexistent or
* unknown.)
* @since 1.4
*/
public CodeException(String code, String message, Throwable cause) {
super(message, cause);
this.code = code;
}
public CodeException(String code, String message, Object target) {
super(message);
this.code = code;
this.target = target;
}
/**
* Constructs a new runtime exception with the specified detail message and
* cause. <p>Note that the detail message associated with
* {@code cause} is <i>not</i> automatically incorporated in
* this runtime exception's detail message.
*
* @param message the detail message (which is saved for later retrieval
* by the {@link #getMessage()} method).
* @param cause the cause (which is saved for later retrieval by the
* {@link #getCause()} method). (A <tt>null</tt> value is
* permitted, and indicates that the cause is nonexistent or
* unknown.)
* @since 1.4
*/
public CodeException(String message, Throwable cause) {
super(message, cause);
}
/**
* Constructs a new runtime exception with {@code null} as its
* detail message. The cause is not initialized, and may subsequently be
* initialized by a call to {@link #initCause}.
*/
public CodeException() {
super();
}
/**
* Constructs a new runtime exception with the specified detail message.
* The cause is not initialized, and may subsequently be initialized by a
* call to {@link #initCause}.
*
* @param code the detail code (which is saved for later retrieval
* by the {@link #getCode()} method).
* @param message the detail message. The detail message is saved for
* later retrieval by the {@link #getMessage()} method.
*/
public CodeException(String code, String message) {
super(message);
this.code = code;
}
/**
* Constructs a new runtime exception with the specified detail message.
* The cause is not initialized, and may subsequently be initialized by a
* call to {@link #initCause}.
*
* @param message the detail message. The detail message is saved for
* later retrieval by the {@link #getMessage()} method.
*/
public CodeException(String message) {
super(message);
}
/**
* Constructs a new runtime exception with the specified detail message and
* cause. <p>Note that the detail message associated with
* {@code cause} is <i>not</i> automatically incorporated in
* this runtime exception's detail message.
*
* @param cause the cause (which is saved for later retrieval by the
* {@link #getCause()} method). (A <tt>null</tt> value is
* permitted, and indicates that the cause is nonexistent or
* unknown.)
* @since 1.4
*/
public CodeException(Throwable cause) {
super(cause);
}
}
package com.yanzuoguang.util.exception;
/**
* 状态异常错误
*/
public class StatusException extends RuntimeException {
/**
* 错误状态码
*/
private int code;
/**
* 错误结果
*/
private Object result;
/**
* 状态异常错误
*/
public StatusException() {
super();
}
/**
* Constructs a new runtime exception with the specified detail message.
* The cause is not initialized, and may subsequently be initialized by a
* call to {@link #initCause}.
*
* @param message the detail message. The detail message is saved for
* later retrieval by the {@link #getMessage()} method.
*/
public StatusException(String message) {
super(message);
}
/**
* Constructs a new runtime exception with the specified detail message and
* cause. <p>Note that the detail message associated with
* {@code cause} is <i>not</i> automatically incorporated in
* this runtime exception's detail message.
*
* @param message the detail message (which is saved for later retrieval
* by the {@link #getMessage()} method).
* @param cause the cause (which is saved for later retrieval by the
* {@link #getCause()} method). (A <tt>null</tt> value is
* permitted, and indicates that the cause is nonexistent or
* unknown.)
* @since 1.4
*/
public StatusException(String message, Throwable cause) {
super(message, cause);
}
/**
* Constructs a new runtime exception with the specified cause and a
* detail message of <tt>(cause==null ? null : cause.toString())</tt>
* (which typically contains the class and detail message of
* <tt>cause</tt>). This constructor is useful for runtime exceptions
* that are little more than wrappers for other throwables.
*
* @param cause the cause (which is saved for later retrieval by the
* {@link #getCause()} method). (A <tt>null</tt> value is
* permitted, and indicates that the cause is nonexistent or
* unknown.)
* @since 1.4
*/
public StatusException(Throwable cause) {
super(cause);
}
/**
* Constructs a new runtime exception with the specified detail
* message, cause, suppression enabled or disabled, and writable
* stack trace enabled or disabled.
*
* @param message the detail message.
* @param cause the cause. (A {@code null} value is permitted,
* and indicates that the cause is nonexistent or unknown.)
* @param enableSuppression whether or not suppression is enabled
* or disabled
* @param writableStackTrace whether or not the stack trace should
* be writable
* @since 1.7
*/
protected StatusException(String message, Throwable cause,
boolean enableSuppression,
boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
/**
* 途必达自定义异常
*
* @param code 错误码
* @param format 格式化字符串
* @param paras 参数
*/
public StatusException(int code, String format, Object... paras) {
super(String.format(format, paras));
this.result = null;
this.code = code;
}
/**
* 途必达自定义异常
*
* @param result 结果
* @param code 错误码
* @param format 格式化字符串
* @param paras 参数
*/
public StatusException(Object result, int code, String format, Object... paras) {
super(String.format(format, paras));
this.result = result;
this.code = code;
}
/**
* 获取状态
* @return
*/
public int getCode() {
return code;
}
/**
* 状态码
* @param code
*/
public void setCode(int code) {
this.code = code;
}
/**
* 结果
* @return
*/
public Object getResult() {
return result;
}
/**
* 结果
* @param result
*/
public void setResult(Object result) {
this.result = result;
}
}
扩展时,需要实现的接口
\ No newline at end of file
//package com.yanzuoguang.util.vo;
//
//import com.tourbida.sys.core.util.JSONHelper;
//
//import java.io.Serializable;
//
///**
// * 基本实体
// *
// * @author: Kang
// * @time: 2018年04月27日 10:19
// */
//public class BaseVo implements Serializable {
//
// private static final long serialVersionUID = -2611225711795496063L;
//
// /**
// * over ride object toString
// *
// * @return
// */
// @Override
// public String toString() {
// return JSONHelper.SerializeObject(this);
// }
//}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment