diff --git a/panda-all/panda-all.iml b/panda-all/panda-all.iml index 2a65123..606c170 100644 --- a/panda-all/panda-all.iml +++ b/panda-all/panda-all.iml @@ -18,11 +18,16 @@ + + + + + + - @@ -39,5 +44,6 @@ + \ No newline at end of file diff --git a/panda-all/pom.xml b/panda-all/pom.xml index 2834d1d..ad1c1b2 100644 --- a/panda-all/pom.xml +++ b/panda-all/pom.xml @@ -7,7 +7,7 @@ org.panda 1.0-SNAPSHOT - pom + jar 4.0.0 ${project.version} panda-all diff --git a/panda-aop/panda-aop.iml b/panda-aop/panda-aop.iml index 177fb70..73638cc 100644 --- a/panda-aop/panda-aop.iml +++ b/panda-aop/panda-aop.iml @@ -23,11 +23,18 @@ + + + + + + + \ No newline at end of file diff --git a/panda-aop/src/main/java/org/panda/aop/proxy/CGLibDynamicPorxy.java b/panda-aop/src/main/java/org/panda/aop/proxy/CGLibDynamicPorxy.java index b616172..3cb11da 100644 --- a/panda-aop/src/main/java/org/panda/aop/proxy/CGLibDynamicPorxy.java +++ b/panda-aop/src/main/java/org/panda/aop/proxy/CGLibDynamicPorxy.java @@ -3,11 +3,15 @@ package org.panda.aop.proxy; import net.sf.cglib.proxy.Enhancer; import net.sf.cglib.proxy.MethodInterceptor; import net.sf.cglib.proxy.MethodProxy; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.lang.reflect.Method; public class CGLibDynamicPorxy implements MethodInterceptor { + private static final Logger LOGGER= LoggerFactory.getLogger(CGLibDynamicPorxy.class); + private static CGLibDynamicPorxy instance = new CGLibDynamicPorxy(); private CGLibDynamicPorxy(){ diff --git a/panda-aop/src/main/java/org/panda/aop/util/InterfaceProxyFactoryUtil.java b/panda-aop/src/main/java/org/panda/aop/util/InterfaceProxyFactoryUtil.java index 856e417..8db2868 100644 --- a/panda-aop/src/main/java/org/panda/aop/util/InterfaceProxyFactoryUtil.java +++ b/panda-aop/src/main/java/org/panda/aop/util/InterfaceProxyFactoryUtil.java @@ -1,6 +1,9 @@ package org.panda.aop.util; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; @@ -11,6 +14,7 @@ import java.lang.reflect.Proxy; */ public class InterfaceProxyFactoryUtil implements InvocationHandler { + private static final Logger logger = LoggerFactory.getLogger(InterfaceProxyFactoryUtil.class); /** * * @param mammperInterface diff --git a/panda-beans/panda-beans.iml b/panda-beans/panda-beans.iml index f08ac05..cbe3627 100644 --- a/panda-beans/panda-beans.iml +++ b/panda-beans/panda-beans.iml @@ -18,11 +18,18 @@ + + + + + + + \ No newline at end of file diff --git a/panda-beans/src/main/java/org/panda/beans/adapter/BeanAdapter.java b/panda-beans/src/main/java/org/panda/beans/adapter/BeanAdapter.java new file mode 100644 index 0000000..cb0ac94 --- /dev/null +++ b/panda-beans/src/main/java/org/panda/beans/adapter/BeanAdapter.java @@ -0,0 +1,11 @@ +package org.panda.beans.adapter; + +/** + * @Author: qi + * @Description: + * @Date: Create in 9:29 AM 2019/2/23 + */ +public interface BeanAdapter { + + +} diff --git a/panda-beans/src/main/java/org/panda/beans/factory/BeanFactory.java b/panda-beans/src/main/java/org/panda/beans/factory/BeanFactory.java new file mode 100644 index 0000000..d2f87f5 --- /dev/null +++ b/panda-beans/src/main/java/org/panda/beans/factory/BeanFactory.java @@ -0,0 +1,96 @@ +package org.panda.beans.factory; + +/** + * @Author: qi + * @Description: + * @Date: Create in 9:06 AM 2019/1/29 + * 实例工厂 + */ +public interface BeanFactory { + + /** + * 实例 -> 工厂转义符 + */ + String FACTORY_BEAN_PREFIX = "&"; + + /** + * 通过类名查找实例 + * @param name + * @return + */ + Object getBean(String name); + + /** + * 通过类名查找实例并确定类型 + * @param name + * @param requiredType + * @param + * @return + */ + T getBean(String name,Class requiredType); + + /** + * 通过类名查找实例 + * @param name + * @param args + * @return + */ + Object getBean(String name,Object... args); + + /** + * 通过class查找实例 + * @param requiredType + * @param + * @return + */ + T getBean(Class requiredType); + + + /** + * 通过实例名,返回实例class + * @param name + * @return + */ + Class getType(String name); + + /** + * 通过实例名返回该实例的别名数组 + * @param name + * @return + */ + String[] getAliases(String name); + + /** + * 通过实例名判断实例是否存在 + * @param name + * @return 存在:true 不存在:false + */ + boolean containsBean(String name); + + /** + * singletion和protpType区别 + * 1.singletion在容器中只有一个实例,protoType则是每次getBean的时候创建一个实例 + */ + + /** + * 通过实例名判断实例是否是单例 + * @param name + * @return 是:true 否:false + */ + boolean isSingletion(String name); + + /** + * 通过实例名判断实例是否原型 + * @param name + * @return 是:true 否:false + */ + boolean isProtoType(String name); + + /** + * 检查实例是否与class类型是否匹配 + * @param name + * @param typeToMatch + * @return 是:true 否:false + */ + boolean isTypeMatch(String name,Class typeToMatch); +} diff --git a/panda-beans/src/main/java/org/panda/beans/util/BeanUtil.java b/panda-beans/src/main/java/org/panda/beans/util/BeanUtil.java index e400ea8..474b19c 100644 --- a/panda-beans/src/main/java/org/panda/beans/util/BeanUtil.java +++ b/panda-beans/src/main/java/org/panda/beans/util/BeanUtil.java @@ -66,12 +66,12 @@ public class BeanUtil { public static void copyNotNull(Object targer,Object source){ Class sourceClass = source.getClass(); - List fieldList = getAllField(sourceClass); - Map fieldMap = new HashMap<>(fieldList.size()); - for (Field field: fieldList){ + List sourcefieldList = getAllField(sourceClass); + Map fieldMap = new HashMap<>(sourcefieldList.size()); + sourcefieldList.forEach(field -> { field.setAccessible(true); fieldMap.put(field.getName(),field); - } + }); Class targerClass = targer.getClass(); List targerFieldList = getAllField(targerClass); for (Field field:targerFieldList){ @@ -82,10 +82,10 @@ public class BeanUtil { try { PropertyDescriptor pd = new PropertyDescriptor(targerField.getName(), targerClass); //获得写方法 - Method wM = pd.getWriteMethod(); + Method setFieldMethod = pd.getWriteMethod(); Object value = targerField.get(source); if (value!=null) { - wM.invoke(targer, value); + setFieldMethod.invoke(targer, value); } } catch (IllegalAccessException e) { e.printStackTrace(); @@ -157,7 +157,11 @@ public class BeanUtil { } - + /** + * 获取实体名称 + * @param entityClazz + * @return + */ public static String getEntityName(Class entityClazz){ String entityPath=entityClazz.getName(); String [] entityNameArray=entityPath.split("\\."); @@ -172,13 +176,12 @@ public class BeanUtil { * @return */ public static Boolean isType(Object obj,Class clazzType){ + boolean isType = false; if (obj!=null) { Class clazz = obj.getClass(); - return clazz.getTypeName().equals(clazzType.getTypeName()) ? true : false; - } - else{ - return false; + isType = clazz.getTypeName().equals(clazzType.getTypeName()) ? true : false; } + return isType; } /** diff --git a/panda-beans/src/main/java/org/panda/beans/util/ClassUtil.java b/panda-beans/src/main/java/org/panda/beans/util/ClassUtil.java index 4da11c4..e2e13fc 100644 --- a/panda-beans/src/main/java/org/panda/beans/util/ClassUtil.java +++ b/panda-beans/src/main/java/org/panda/beans/util/ClassUtil.java @@ -14,6 +14,7 @@ import java.util.jar.JarEntry; import java.util.jar.JarFile; /** + * @author qi * 类加载器 */ public class ClassUtil { diff --git a/panda-beans/src/test/java/org/panda/beans/entity/SysUser.java b/panda-beans/src/test/java/org/panda/beans/entity/SysUser.java new file mode 100644 index 0000000..e86b4e5 --- /dev/null +++ b/panda-beans/src/test/java/org/panda/beans/entity/SysUser.java @@ -0,0 +1,51 @@ +package org.panda.beans.entity; + +import java.util.Date; + +/** + * @Author: qi + * @Description: + * @Date: Create in 10:25 AM 2019/2/28 + */ +public class SysUser { + + private Long id; + + private String name; + + private Date createTime; + + private Date updateTime; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + + public Date getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(Date updateTime) { + this.updateTime = updateTime; + } +} diff --git a/panda-beans/src/test/java/org/panda/beans/util/BeanUtilTest.java b/panda-beans/src/test/java/org/panda/beans/util/BeanUtilTest.java new file mode 100644 index 0000000..b7da34c --- /dev/null +++ b/panda-beans/src/test/java/org/panda/beans/util/BeanUtilTest.java @@ -0,0 +1,33 @@ +package org.panda.beans.util; + +import org.junit.Test; +import org.panda.beans.entity.SysUser; + +import java.lang.reflect.Method; +import java.util.Date; + +import static org.junit.Assert.*; + +/** + * @Author: qi + * @Description: + * @Date: Create in 10:25 AM 2019/2/28 + */ +public class BeanUtilTest { + + @Test + public void methodTest(){ + SysUser sysUser = new SysUser(); + sysUser.setId(1L); + sysUser.setName("liangqi"); + sysUser.setCreateTime(new Date()); + sysUser.setUpdateTime(new Date()); + + Class clazz = sysUser.getClass(); + Method[] methods = clazz.getMethods(); + for (Method method:methods){ + System.out.println(method.getName()); + } + } + +} \ No newline at end of file diff --git a/panda-code/panda-code.iml b/panda-code/panda-code.iml index 819f419..9a14395 100644 --- a/panda-code/panda-code.iml +++ b/panda-code/panda-code.iml @@ -17,11 +17,18 @@ + + + + + + + \ No newline at end of file diff --git a/panda-code/pom.xml b/panda-code/pom.xml index 747dbb1..a2188a4 100644 --- a/panda-code/pom.xml +++ b/panda-code/pom.xml @@ -27,6 +27,7 @@ 2.9.6 + 4.5.2 @@ -72,6 +73,26 @@ 1.3.2 + + + org.apache.httpcomponents + httpclient + ${httpclient.version} + + + + org.apache.httpcomponents + httpmime + ${httpclient.version} + + + + + com.alibaba + fastjson + 1.2.40 + + diff --git a/panda-code/src/main/java/org/panda/code/uitl/ArrayUtil.java b/panda-code/src/main/java/org/panda/code/uitl/ArrayUtil.java index 70d1a40..046dcd0 100644 --- a/panda-code/src/main/java/org/panda/code/uitl/ArrayUtil.java +++ b/panda-code/src/main/java/org/panda/code/uitl/ArrayUtil.java @@ -3,6 +3,7 @@ package org.panda.code.uitl; import org.apache.commons.lang3.ArrayUtils; /** + * @author qi * 数组工具类 */ public class ArrayUtil { @@ -12,9 +13,9 @@ public class ArrayUtil { * @param array * @return */ - public static boolean isNotEmpty(Object[] array){ + public static boolean isNotEmpty(T[] array){ - return ArrayUtils.isNotEmpty(array); + return array!=null&&array.length>0; } /** @@ -24,7 +25,7 @@ public class ArrayUtil { */ public static boolean isEmpty(Object[] array){ - return ArrayUtils.isEmpty(array); + return array==null||array.length==0; } } diff --git a/panda-code/src/main/java/org/panda/code/uitl/CodecUtil.java b/panda-code/src/main/java/org/panda/code/uitl/CodecUtil.java index 7b9f474..c36c060 100644 --- a/panda-code/src/main/java/org/panda/code/uitl/CodecUtil.java +++ b/panda-code/src/main/java/org/panda/code/uitl/CodecUtil.java @@ -9,6 +9,7 @@ import java.net.URLEncoder; /** + * @author qi * 编码与解码操作工具类 */ public final class CodecUtil { diff --git a/panda-code/src/main/java/org/panda/code/uitl/CollectionUtil.java b/panda-code/src/main/java/org/panda/code/uitl/CollectionUtil.java index 68ff9fc..7ff7d1e 100644 --- a/panda-code/src/main/java/org/panda/code/uitl/CollectionUtil.java +++ b/panda-code/src/main/java/org/panda/code/uitl/CollectionUtil.java @@ -7,6 +7,7 @@ import java.util.Collection; import java.util.Map; /** + * @author qi * 集合工具类 */ public class CollectionUtil { diff --git a/panda-code/src/main/java/org/panda/code/uitl/DateUtil.java b/panda-code/src/main/java/org/panda/code/uitl/DateUtil.java index 500f46b..f39ed7f 100644 --- a/panda-code/src/main/java/org/panda/code/uitl/DateUtil.java +++ b/panda-code/src/main/java/org/panda/code/uitl/DateUtil.java @@ -50,7 +50,13 @@ public class DateUtil { return str; } - + /** + * 通过日期字符串返回时间 + * @param strDate + * @param pattern + * @return + * @throws ParseException + */ public static Date strToDate(String strDate,String pattern) throws ParseException { if (StringUtil.isNull(pattern)){ pattern = DEFAULT_PATTERN; @@ -61,6 +67,12 @@ public class DateUtil { return sdf.parse(strDate); } + /** + * + * @param startDate + * @param endDate + * @return + */ public static int disparityDay(Date startDate,Date endDate){ int day = (int)(endDate.getTime()-startDate.getTime())/(24*60*60*1000); return day; diff --git a/panda-code/src/main/java/org/panda/code/uitl/HttpUtil.java b/panda-code/src/main/java/org/panda/code/uitl/HttpUtil.java index ea4b46b..d992d7b 100644 --- a/panda-code/src/main/java/org/panda/code/uitl/HttpUtil.java +++ b/panda-code/src/main/java/org/panda/code/uitl/HttpUtil.java @@ -8,6 +8,7 @@ import java.util.List; import java.util.Map; /** + * @author qi * Created by qi on 2017/8/9. */ public class HttpUtil { diff --git a/panda-code/src/main/java/org/panda/code/uitl/JvmUtil.java b/panda-code/src/main/java/org/panda/code/uitl/JvmUtil.java index 594245e..319dcda 100644 --- a/panda-code/src/main/java/org/panda/code/uitl/JvmUtil.java +++ b/panda-code/src/main/java/org/panda/code/uitl/JvmUtil.java @@ -7,6 +7,7 @@ import java.text.NumberFormat; import java.util.Locale; /** + * @author qi * Created by qi_liang on 2018/5/25. */ public class JvmUtil { diff --git a/panda-code/src/main/java/org/panda/code/uitl/Md5Util.java b/panda-code/src/main/java/org/panda/code/uitl/Md5Util.java index d1f150a..dd4e144 100644 --- a/panda-code/src/main/java/org/panda/code/uitl/Md5Util.java +++ b/panda-code/src/main/java/org/panda/code/uitl/Md5Util.java @@ -3,6 +3,7 @@ package org.panda.code.uitl; import java.security.MessageDigest; /** + * @author qi * Created by qi on 2017/8/12. */ public class Md5Util { diff --git a/panda-code/src/main/java/org/panda/code/uitl/ReflectionUtil.java b/panda-code/src/main/java/org/panda/code/uitl/ReflectionUtil.java index b92de86..5b5c2d0 100644 --- a/panda-code/src/main/java/org/panda/code/uitl/ReflectionUtil.java +++ b/panda-code/src/main/java/org/panda/code/uitl/ReflectionUtil.java @@ -8,13 +8,14 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; /** + * @author qi * 反射工具 * newInstance: 弱类型。低效率。只能调用无参构造。 new: 强类型。相对高效。能调用任何public构造。 */ public class ReflectionUtil { - private static final Logger logger = LoggerFactory.getLogger(ReflectionUtil.class); + private static final Logger LOGGER = LoggerFactory.getLogger(ReflectionUtil.class); /** * 创建实例 @@ -23,7 +24,6 @@ public class ReflectionUtil { */ public static Object newInstance(Class clazz){ Object instance = null ; - try { instance = clazz.newInstance(); } catch (InstantiationException e) { diff --git a/panda-code/src/main/java/org/panda/code/uitl/StreamUtil.java b/panda-code/src/main/java/org/panda/code/uitl/StreamUtil.java index 42887a5..f2bf8e4 100644 --- a/panda-code/src/main/java/org/panda/code/uitl/StreamUtil.java +++ b/panda-code/src/main/java/org/panda/code/uitl/StreamUtil.java @@ -13,6 +13,16 @@ public class StreamUtil { private static final Logger LOGGER = LoggerFactory.getLogger(StreamUtil.class); + /** + * 默认缓存块大小 + */ + public static final int BUFFER_SIZE = 4096; + + /** + * 输入流转换字符串 + * @param is + * @return + */ public static String getString(InputStream is){ StringBuilder sb = new StringBuilder(); try { @@ -23,14 +33,14 @@ public class StreamUtil { } }catch (IOException e){ LOGGER.error("get string failure",e); - e.printStackTrace(); + throw new RuntimeException(e); } return sb.toString(); } /** - * 将输入流负责到输出流 + * 输入流复制到输出流 */ public static void copyStream(InputStream inputStream, OutputStream outputStream){ try { @@ -49,7 +59,26 @@ public class StreamUtil { outputStream.close(); } catch (IOException e) { LOGGER.error("close stream failure",e); + throw new RuntimeException(e); } } } + + /** + * 缓存块写入输出流中 + * @param in + * @param out + * @throws IOException + */ + public static void copy(byte[] in,OutputStream out) throws IOException { + if (in==null||in.length==0){ + LOGGER.error("in is null"); + } + if (out==null){ + LOGGER.error("out is null"); + } + out.write(in); + } + + } diff --git a/panda-code/src/main/java/org/panda/code/uitl/StringUtil.java b/panda-code/src/main/java/org/panda/code/uitl/StringUtil.java index d4c2948..a200741 100644 --- a/panda-code/src/main/java/org/panda/code/uitl/StringUtil.java +++ b/panda-code/src/main/java/org/panda/code/uitl/StringUtil.java @@ -5,6 +5,7 @@ import java.util.Random; import java.util.concurrent.ThreadLocalRandom; /** + * @author qi * Created by qi on 2017/8/13. */ public class StringUtil { @@ -109,6 +110,12 @@ public class StringUtil { return randomChar((int)'A',26); } + /** + * 字符串切割 + * @param str + * @param sign + * @return + */ public static String[] splistString(String str,String sign){ return str.split(sign); @@ -125,8 +132,6 @@ public class StringUtil { } public String randomString(int length,String needRule){ - -// Random random=new Random(); //jdk 1.7 以后用来取代Random,性能会有提升 ThreadLocalRandom threadLocalRandom = ThreadLocalRandom.current(); threadLocalRandom.nextInt(100); diff --git a/panda-code/src/main/java/org/panda/code/uitl/file/FileUtil.java b/panda-code/src/main/java/org/panda/code/uitl/file/FileUtil.java index b10b92f..e1e634c 100644 --- a/panda-code/src/main/java/org/panda/code/uitl/file/FileUtil.java +++ b/panda-code/src/main/java/org/panda/code/uitl/file/FileUtil.java @@ -8,9 +8,11 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.*; +import java.util.List; /** - * Created by qi on 2018-1-20. + * @author qi + * */ public class FileUtil { @@ -133,5 +135,46 @@ public class FileUtil { return fileType; } + /** + * 获取一个文件夹下的文件目录 + * @param dirPath + * @return + */ + public static void getFileList(String dirPath){ + + File file = new File(dirPath); + if (!file.exists()){ + String msg = "file not exists,please check file !" ; + LOGGER.error(msg,new RuntimeException(msg)); + } + if (!file.isDirectory()){ + String msg = "file is not directory, please check file !"; + LOGGER.error(msg,new RuntimeException(msg)); + } + File[] files = file.listFiles(); + for (File file1:files){ + if (file1.isDirectory()){ + System.out.println(file.getName()); + getFileList(file1.getPath()); + continue; + } + System.out.println(file1.getName()); + } + } + /** + * 获取一个文件夹下的隐藏文件列表 + * @param dirPath + * @return + */ + public static List findAllHiddenFile(String dirPath){ + File dirFile = new File(dirPath); + + return null; + } + + public static void main(String[] args) { + + getFileList("/Users/qi/java"); + } } diff --git a/panda-code/src/main/java/org/panda/code/uitl/http/HttpsClient.java b/panda-code/src/main/java/org/panda/code/uitl/http/HttpsClient.java new file mode 100644 index 0000000..6280d50 --- /dev/null +++ b/panda-code/src/main/java/org/panda/code/uitl/http/HttpsClient.java @@ -0,0 +1,175 @@ +package org.panda.code.uitl.http; + +import com.alibaba.fastjson.JSONObject; +import org.apache.http.Header; +import org.apache.http.HttpEntity; +import org.apache.http.client.ClientProtocolException; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.mime.HttpMultipartMode; +import org.apache.http.entity.mime.MultipartEntityBuilder; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.net.ssl.SSLContext; +import java.io.*; +import java.nio.charset.Charset; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +public class HttpsClient { + + private static final Logger LOGGER = LoggerFactory.getLogger(HttpsClient.class); + + /** + * http 默认字符编码 + */ + public static final String DETAFILE_CHARSET = "UTF-8"; + + public static String post(String url,Map params) throws IOException{ + String boundary = getBoundaryStr(); + CloseableHttpResponse reponse =null; + CloseableHttpClient client = null; + String resultStr = ""; + try{ + // 获得utf-8编码的mbuilder + MultipartEntityBuilder mBuilder = get_COMPATIBLE_Builder(DETAFILE_CHARSET,boundary); + /** + * 原生的微信使用的url是https://api.weixin.qq.com/cgi-bin/media/upload? + * access_token=##ACCESS_TOKEN##&type=##TYPE## + * 一般都会使用这个把参数直接携带在url中。我个人不喜欢这样,因为既然使用了httpclient,完全可以把参数 + * 设置在我们的body体中。所以我们使用的url是这样的 + * https://api.weixin.qq.com/cgi-bin/media/upload 然后通过在body体中设置参数来设置 + * access_token和type这两个字段 + * + * */ + params.forEach((key,value)->{ + if (value instanceof String){ + mBuilder.addTextBody(key, (String) value); + } + if (value instanceof File){ + File file = (File)value; + mBuilder.addBinaryBody(key,file, + ContentType.APPLICATION_OCTET_STREAM,file + .getName()); + } + }); + + // 建造我们的http多媒体对象 + HttpEntity he = mBuilder.build(); + // 建立一个sslcontext,这里我们信任任何的证书。 + SSLContext context = getTrustAllSSLContext(); + // 建立socket工厂 + SSLConnectionSocketFactory factory = new SSLConnectionSocketFactory( + context); + // 建立连接器 + client = HttpClients.custom() + .setSSLSocketFactory(factory).build(); + // 得到一个post请求的实体 + HttpPost post = getMultipartPost(url, boundary); + // 给请求添加参数 + post.setEntity(he); + // 执行请求并获得结果 + reponse = client.execute(post); + // 获得返回的内容 + HttpEntity entity = reponse.getEntity(); + // 输出 + System.out.println(JSONObject.toJSONString(entity)); + + resultStr = JSONObject.toJSONString(entity); + + Reader reader = new BufferedReader(new InputStreamReader(entity.getContent())); + String line = null; + StringBuffer buffer = new StringBuffer(); + while (reader.ready()){ + buffer.append((char)reader.read()); + } + System.out.println(buffer.toString()); + } catch (ClientProtocolException e) { + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } finally{ + // 关闭返回的reponse + if(reponse!=null){ + reponse.close(); + } + if(client!=null){ + // 关闭client + client.close(); + } + } + return resultStr; + } + + private static String getBoundaryStr() { + String boundary = UUID.randomUUID().toString().replace("-", ""); + return boundary; + } + + + private static MultipartEntityBuilder get_COMPATIBLE_Builder(String charSet,String boundarStr) { + MultipartEntityBuilder result = MultipartEntityBuilder.create(); + result.setBoundary(boundarStr) + .setCharset(Charset.forName(charSet)) + .setMode(HttpMultipartMode.BROWSER_COMPATIBLE); + return result; + } + + + private static HttpPost getMultipartPost(String url,String boundarStr) { + /* 这里设置一些post的头部信息,具体求百度吧 */ + HttpPost post = new HttpPost(url); + post.addHeader("Connection", "keep-alive"); + post.addHeader("Accept", "*/*"); + post.addHeader("Content-Type", "multipart/form-data;boundary=" + + boundarStr); + post.addHeader("User-Agent", + "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0) "); + return post; + } + + private static HttpGet getHttpGet(String url){ + HttpGet get = new HttpGet(url); + + return get; + } + + private static SSLContext getTrustAllSSLContext() throws Exception { +// SSLContext context = SSLContexts.custom().loadTrustMaterial(null, new TrustStrategy() { +// +// @Override +// public boolean isTrusted(X509Certificate[] arg0, String arg1) +// throws java.security.cert.CertificateException { +// // 这一句就是信任任何的证书,当然你也可以去验证服务器的真实性 +// return true; +// } +// }).build(); + SSLContext context = SSLContext.getDefault(); + return context; + } + + public static void main(String[] args) throws IOException { + File file =new File("/Users/qi_liang/Downloads/timg.jpeg"); + String url = "https://api.weixin.qq.com/cgi-bin/media/upload"; + Map params = new HashMap(); + params.put("access_token", "10_0oKKCsF9JL30JeGZDyfNWDhiaRvivAL9vs9ihvaledzBuPVM6IMvwcFUc58AFwlETRdvEBAFXOYbF2GoKmbtMmopCs78m9UE8whgrYU4kJww4mSooMcq8el-qnU4JdjPGKruZLjdNS246hXyWOHbAAAHZS"); + params.put("type", "image"); + if(file.exists()){ + params.put("media", file); + } + String resultStr = post(url,params); + System.out.println(resultStr); + } + +} diff --git a/panda-code/src/main/java/org/panda/code/uitl/os/JvmUtil.java b/panda-code/src/main/java/org/panda/code/uitl/os/JvmUtil.java new file mode 100644 index 0000000..c26e523 --- /dev/null +++ b/panda-code/src/main/java/org/panda/code/uitl/os/JvmUtil.java @@ -0,0 +1,107 @@ +package org.panda.code.uitl.os; + +import org.panda.code.uitl.os.mode.JvmInfo; + +import java.text.DecimalFormat; +import java.util.Properties; +import java.util.Set; + +/** + * @author qi + * Created by qi_liang on 2018/6/9. + */ +public class JvmUtil { + + static Properties properties = System.getProperties(); + static Runtime runtime = Runtime.getRuntime(); + + /** + * 获取java版本号 + * @return + */ + public static String getVersion(){ + + return properties.getProperty("java.version"); + } + + /** + * 获取Java 环境供应商名称 + */ + public static String getVendor(){ + + return properties.getProperty("java.vendor"); + } + + /** + * 获取java 环境供应商url + */ + public static String getVendorUrl(){ + return properties.getProperty("java.vendor.url"); + } + + /** + * 获取java安装路径 + * @param + */ + public static String getHome(){ + + return properties.getProperty("java.home"); + } + + /** + * 获取虚拟机可以使用的总内存 + */ + public static Long getTotalMemory(){ + + return runtime.totalMemory(); + } + /** + * 获取虚拟机可以使用的数据器个数 + */ + private static Integer getCupNum(){ + return runtime.availableProcessors(); + } + /** + * 返回jvm 信息 + */ + + public static JvmInfo getInfo(){ + JvmInfo jvmInfo = new JvmInfo(); + jvmInfo.setVersion(getVersion()); + jvmInfo.setCupNum(getCupNum()); + jvmInfo.setTotalMemory(getTotalMemory()); + return jvmInfo; + } + + /** + * + * @param args + */ + + /** + * Starts the program + * + * @param args the command line arguments + */ + public static void main(String[] args) { + new JvmUtil().displayAvailableMemory(); + } + + /** + * 显示JVM总内存,JVM最大内存和总空闲内存 + */ + public void displayAvailableMemory() { + DecimalFormat df = new DecimalFormat("0.00") ; + + //显示JVM总内存 + long totalMem = Runtime.getRuntime().totalMemory(); + System.out.println(df.format(totalMem/1024/1024) + " MB"); + //显示JVM尝试使用的最大内存 + long maxMem = Runtime.getRuntime().maxMemory(); + System.out.println(df.format(maxMem ) + " MB"); + //空闲内存 + long freeMem = Runtime.getRuntime().freeMemory(); + System.out.println(df.format(freeMem ) + " MB"); + } + +} diff --git a/panda-code/src/main/java/org/panda/code/uitl/os/NetUtil.java b/panda-code/src/main/java/org/panda/code/uitl/os/NetUtil.java index a8d2ea0..aa4c2c2 100644 --- a/panda-code/src/main/java/org/panda/code/uitl/os/NetUtil.java +++ b/panda-code/src/main/java/org/panda/code/uitl/os/NetUtil.java @@ -3,7 +3,9 @@ package org.panda.code.uitl.os; import java.net.InetAddress; import java.net.UnknownHostException; -/** 获取计算机网络信息 +/** + * @author qi + * 获取计算机网络信息 * Created by qi_liang on 2018/6/9. */ public class NetUtil { diff --git a/panda-code/src/main/java/org/panda/code/uitl/os/OsUtil.java b/panda-code/src/main/java/org/panda/code/uitl/os/OsUtil.java new file mode 100644 index 0000000..ab90ba6 --- /dev/null +++ b/panda-code/src/main/java/org/panda/code/uitl/os/OsUtil.java @@ -0,0 +1,52 @@ +package org.panda.code.uitl.os; + +import org.panda.code.uitl.os.mode.OsInfo; + +import java.util.Properties; + +/** + * @author qi + * 获取计算机操作系统信息 + * Created by qi_liang on 2018/6/9. + */ +public class OsUtil { + static Properties properties = System.getProperties(); + + +// +// public OsUtil(OperatingSystem os){ +// this.os = os; +// +// } +// +// /** +// * 操作系统 +// */ +// public static String getArch(){ +// return os.getArch(); +// } +// +// /** +// * +// */ +// public static String getCpuEndian(){ +// return os.getCpuEndian(); +// } +// +// public static String getDateModel(){ +// +// return os.getDataModel(); +// } + + public static OsInfo getInfo(){ + OsInfo osInfo = new OsInfo(); + osInfo.setOsVersion(properties.getProperty("os.version")); + osInfo.setOsName(properties.getProperty("os.name")); + osInfo.setArch(properties.getProperty("os.arch")); + return osInfo; + } + + + + +} diff --git a/panda-code/src/main/java/org/panda/code/uitl/os/mode/JvmInfo.java b/panda-code/src/main/java/org/panda/code/uitl/os/mode/JvmInfo.java new file mode 100644 index 0000000..f376dab --- /dev/null +++ b/panda-code/src/main/java/org/panda/code/uitl/os/mode/JvmInfo.java @@ -0,0 +1,38 @@ +package org.panda.code.uitl.os.mode; + +/** + * @author qi + * Created by qi_liang on 2018/6/10. + */ +public class JvmInfo { + //版本号 + private String version; + //总内存 + private Long totalMemory; + //可以使用处理器个数 + private Integer cupNum; + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public Long getTotalMemory() { + return totalMemory; + } + + public void setTotalMemory(Long totalMemory) { + this.totalMemory = totalMemory; + } + + public Integer getCupNum() { + return cupNum; + } + + public void setCupNum(Integer cupNum) { + this.cupNum = cupNum; + } +} diff --git a/panda-code/src/main/java/org/panda/code/uitl/os/mode/OsInfo.java b/panda-code/src/main/java/org/panda/code/uitl/os/mode/OsInfo.java new file mode 100644 index 0000000..5830b4e --- /dev/null +++ b/panda-code/src/main/java/org/panda/code/uitl/os/mode/OsInfo.java @@ -0,0 +1,39 @@ +package org.panda.code.uitl.os.mode; + +/** + * @author qi + * Created by qi_liang on 2018/6/10. + */ +public class OsInfo { + + //操作系统名称 + private String osName; + //操作系统版本号 + private String osVersion; + //操作系统架构 + private String arch; + + public String getOsName() { + return osName; + } + + public void setOsName(String osName) { + this.osName = osName; + } + + public String getOsVersion() { + return osVersion; + } + + public void setOsVersion(String osVersion) { + this.osVersion = osVersion; + } + + public String getArch() { + return arch; + } + + public void setArch(String arch) { + this.arch = arch; + } +} diff --git a/panda-jdbc/panda-jdbc.iml b/panda-jdbc/panda-jdbc.iml index d2a45c7..49f74a8 100644 --- a/panda-jdbc/panda-jdbc.iml +++ b/panda-jdbc/panda-jdbc.iml @@ -19,6 +19,11 @@ + + + + + @@ -33,5 +38,6 @@ + \ No newline at end of file diff --git a/panda-jdbc/src/main/java/org/panda/jdbc/BeanHander.java b/panda-jdbc/src/main/java/org/panda/jdbc/BeanHander.java index 179da06..21c1491 100644 --- a/panda-jdbc/src/main/java/org/panda/jdbc/BeanHander.java +++ b/panda-jdbc/src/main/java/org/panda/jdbc/BeanHander.java @@ -11,6 +11,7 @@ import java.sql.SQLException; /** * @author qi + * 结果集处理类 */ public class BeanHander implements ResultSetHandler { diff --git a/panda-jdbc/src/main/java/org/panda/jdbc/BeanListHandler.java b/panda-jdbc/src/main/java/org/panda/jdbc/BeanListHandler.java index 28ca3cc..7891081 100644 --- a/panda-jdbc/src/main/java/org/panda/jdbc/BeanListHandler.java +++ b/panda-jdbc/src/main/java/org/panda/jdbc/BeanListHandler.java @@ -6,6 +6,7 @@ import java.util.List; /** * @author qi + * 结果集(集合)处理类 */ public class BeanListHandler implements ResultSetHandler { diff --git a/panda-jdbc/src/main/java/org/panda/jdbc/ResultSetHandler.java b/panda-jdbc/src/main/java/org/panda/jdbc/ResultSetHandler.java index 3252653..2a8b8da 100644 --- a/panda-jdbc/src/main/java/org/panda/jdbc/ResultSetHandler.java +++ b/panda-jdbc/src/main/java/org/panda/jdbc/ResultSetHandler.java @@ -5,7 +5,6 @@ import java.sql.ResultSet; /** * @author qi * 结果集处理接口 - * */ public interface ResultSetHandler { diff --git a/panda-jdbc/src/main/java/org/panda/jdbc/mode/DbInfo.java b/panda-jdbc/src/main/java/org/panda/jdbc/mode/DbInfo.java index 7811a15..ecc2486 100644 --- a/panda-jdbc/src/main/java/org/panda/jdbc/mode/DbInfo.java +++ b/panda-jdbc/src/main/java/org/panda/jdbc/mode/DbInfo.java @@ -1,6 +1,7 @@ package org.panda.jdbc.mode; /** + * @author qi * 数据库详情实体 * Created by qi_liang on 2018/6/10. */ diff --git a/panda-jdbc/src/main/java/org/panda/jdbc/mode/Table.java b/panda-jdbc/src/main/java/org/panda/jdbc/mode/Table.java index 813851b..da91dfe 100644 --- a/panda-jdbc/src/main/java/org/panda/jdbc/mode/Table.java +++ b/panda-jdbc/src/main/java/org/panda/jdbc/mode/Table.java @@ -3,6 +3,7 @@ package org.panda.jdbc.mode; import java.util.List; /** + * @author qi * 数据库表实体 * Created by qi_liang on 2018/6/2. */ diff --git a/panda-jdbc/src/main/java/org/panda/jdbc/sql/AbstractDbBuiler.java b/panda-jdbc/src/main/java/org/panda/jdbc/sql/AbstractDbBuiler.java index b8fbbfe..0944419 100644 --- a/panda-jdbc/src/main/java/org/panda/jdbc/sql/AbstractDbBuiler.java +++ b/panda-jdbc/src/main/java/org/panda/jdbc/sql/AbstractDbBuiler.java @@ -9,7 +9,7 @@ import java.util.Set; /** * @author qi * 抽象类-sql构造器 - * 实现的子类有: MysqlBuilder ,OragleBuilder (为应对不同数据库特色,有部分方法抽象,由子类实现) + * 实现的子类有: MysqlBuilder ,OragleBuilder (为应对不同数据库特点,有部分方法抽象,由子类实现) * Created by qi_liang on 2018/6/2. */ public abstract class AbstractDbBuiler { @@ -47,7 +47,8 @@ public abstract class AbstractDbBuiler { /** * 构建新增sql语句 - * @param obj + * @param obj + * @param fieldMap * @return */ abstract public String insertSql(Object obj, Map fieldMap); diff --git a/panda-jdbc/src/main/java/org/panda/jdbc/sql/BeanSqlUtil.java b/panda-jdbc/src/main/java/org/panda/jdbc/sql/BeanSqlUtil.java index caa4a28..19e341a 100644 --- a/panda-jdbc/src/main/java/org/panda/jdbc/sql/BeanSqlUtil.java +++ b/panda-jdbc/src/main/java/org/panda/jdbc/sql/BeanSqlUtil.java @@ -11,6 +11,7 @@ import java.util.Map; /** * @author qi + * 维护类名和数据库字段工具类 */ public class BeanSqlUtil { diff --git a/panda-jdbc/src/test/java/org/panda/entity/SysUser.java b/panda-jdbc/src/test/java/org/panda/entity/SysUser.java index 82941a9..b5a9826 100644 --- a/panda-jdbc/src/test/java/org/panda/entity/SysUser.java +++ b/panda-jdbc/src/test/java/org/panda/entity/SysUser.java @@ -53,4 +53,15 @@ public class SysUser { public void setStatus(int status) { this.status = status; } + + @Override + public String toString() { + return "SysUser{" + + "id=" + id + + ", name='" + name + '\'' + + ", createTime=" + createTime + + ", updateTime=" + updateTime + + ", status=" + status + + '}'; + } } diff --git a/panda-jdbc/src/test/java/org/panda/jdbc/sql/MysqlBuilderTest.java b/panda-jdbc/src/test/java/org/panda/jdbc/sql/MysqlBuilderTest.java index 9359b94..bf97774 100644 --- a/panda-jdbc/src/test/java/org/panda/jdbc/sql/MysqlBuilderTest.java +++ b/panda-jdbc/src/test/java/org/panda/jdbc/sql/MysqlBuilderTest.java @@ -1,5 +1,6 @@ package org.panda.jdbc.sql; +import com.github.jsonzou.jmockdata.JMockData; import org.junit.Test; import org.panda.entity.SysUser; @@ -67,4 +68,46 @@ public class MysqlBuilderTest { @Test public void deleteSql1() { } + + @Test + public void automaticUpdateDb1() { + } + + @Test + public void concatPageSql1() { + } + + @Test + public void createTableStr1() { + } + + @Test + public void insertSql2() { + AbstractDbBuiler abstractDbBuiler = new MysqlBuilder(); + SysUser sysUser = JMockData.mock(SysUser.class); + System.out.println(sysUser); + sysUser.setId(null); + String insertSql = abstractDbBuiler.insertSql(sysUser); + System.out.println(insertSql); + } + + @Test + public void insertSql3() { + } + + @Test + public void updateSql2() { + } + + @Test + public void updateSql3() { + } + + @Test + public void deleteSql2() { + } + + @Test + public void deleteSql3() { + } } \ No newline at end of file diff --git a/pom.xml b/pom.xml index 1b70e9a..c83cd47 100644 --- a/pom.xml +++ b/pom.xml @@ -59,6 +59,13 @@ test + + + com.github.jsonzou + jmockdata + 3.0.1 + test +