修改部分注释,代码功能无新增

master
星期八 6 years ago
parent d37fd9b9f4
commit d1cac9240e
  1. 8
      panda-all/panda-all.iml
  2. 2
      panda-all/pom.xml
  3. 7
      panda-aop/panda-aop.iml
  4. 4
      panda-aop/src/main/java/org/panda/aop/proxy/CGLibDynamicPorxy.java
  5. 4
      panda-aop/src/main/java/org/panda/aop/util/InterfaceProxyFactoryUtil.java
  6. 7
      panda-beans/panda-beans.iml
  7. 11
      panda-beans/src/main/java/org/panda/beans/adapter/BeanAdapter.java
  8. 96
      panda-beans/src/main/java/org/panda/beans/factory/BeanFactory.java
  9. 25
      panda-beans/src/main/java/org/panda/beans/util/BeanUtil.java
  10. 1
      panda-beans/src/main/java/org/panda/beans/util/ClassUtil.java
  11. 51
      panda-beans/src/test/java/org/panda/beans/entity/SysUser.java
  12. 33
      panda-beans/src/test/java/org/panda/beans/util/BeanUtilTest.java
  13. 7
      panda-code/panda-code.iml
  14. 21
      panda-code/pom.xml
  15. 7
      panda-code/src/main/java/org/panda/code/uitl/ArrayUtil.java
  16. 1
      panda-code/src/main/java/org/panda/code/uitl/CodecUtil.java
  17. 1
      panda-code/src/main/java/org/panda/code/uitl/CollectionUtil.java
  18. 14
      panda-code/src/main/java/org/panda/code/uitl/DateUtil.java
  19. 1
      panda-code/src/main/java/org/panda/code/uitl/HttpUtil.java
  20. 1
      panda-code/src/main/java/org/panda/code/uitl/JvmUtil.java
  21. 1
      panda-code/src/main/java/org/panda/code/uitl/Md5Util.java
  22. 4
      panda-code/src/main/java/org/panda/code/uitl/ReflectionUtil.java
  23. 33
      panda-code/src/main/java/org/panda/code/uitl/StreamUtil.java
  24. 9
      panda-code/src/main/java/org/panda/code/uitl/StringUtil.java
  25. 45
      panda-code/src/main/java/org/panda/code/uitl/file/FileUtil.java
  26. 175
      panda-code/src/main/java/org/panda/code/uitl/http/HttpsClient.java
  27. 107
      panda-code/src/main/java/org/panda/code/uitl/os/JvmUtil.java
  28. 4
      panda-code/src/main/java/org/panda/code/uitl/os/NetUtil.java
  29. 52
      panda-code/src/main/java/org/panda/code/uitl/os/OsUtil.java
  30. 38
      panda-code/src/main/java/org/panda/code/uitl/os/mode/JvmInfo.java
  31. 39
      panda-code/src/main/java/org/panda/code/uitl/os/mode/OsInfo.java
  32. 6
      panda-jdbc/panda-jdbc.iml
  33. 1
      panda-jdbc/src/main/java/org/panda/jdbc/BeanHander.java
  34. 1
      panda-jdbc/src/main/java/org/panda/jdbc/BeanListHandler.java
  35. 1
      panda-jdbc/src/main/java/org/panda/jdbc/ResultSetHandler.java
  36. 1
      panda-jdbc/src/main/java/org/panda/jdbc/mode/DbInfo.java
  37. 1
      panda-jdbc/src/main/java/org/panda/jdbc/mode/Table.java
  38. 5
      panda-jdbc/src/main/java/org/panda/jdbc/sql/AbstractDbBuiler.java
  39. 1
      panda-jdbc/src/main/java/org/panda/jdbc/sql/BeanSqlUtil.java
  40. 11
      panda-jdbc/src/test/java/org/panda/entity/SysUser.java
  41. 43
      panda-jdbc/src/test/java/org/panda/jdbc/sql/MysqlBuilderTest.java
  42. 7
      pom.xml

@ -18,11 +18,16 @@
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.9.6" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.9.6" level="project" />
<orderEntry type="library" name="Maven: commons-io:commons-io:1.3.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.5.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.4.4" level="project" />
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" />
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.9" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpmime:4.5.2" level="project" />
<orderEntry type="library" name="Maven: com.alibaba:fastjson:1.2.40" level="project" />
<orderEntry type="module" module-name="panda-jdbc" />
<orderEntry type="module" module-name="panda-aop" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-dbcp2:2.5.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-pool2:2.6.0" level="project" />
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" />
<orderEntry type="library" name="Maven: commons-dbutils:commons-dbutils:1.7" level="project" />
<orderEntry type="module" module-name="panda-web" />
<orderEntry type="library" scope="RUNTIME" name="Maven: javax.servlet:jstl:1.2" level="project" />
@ -39,5 +44,6 @@
<orderEntry type="library" name="Maven: mysql:mysql-connector-java:5.1.30" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.11" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: com.github.jsonzou:jmockdata:3.0.1" level="project" />
</component>
</module>

@ -7,7 +7,7 @@
<groupId>org.panda</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<packaging>pom</packaging>
<packaging>jar</packaging>
<modelVersion>4.0.0</modelVersion>
<version>${project.version}</version>
<artifactId>panda-all</artifactId>

@ -23,11 +23,18 @@
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.9.6" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.9.6" level="project" />
<orderEntry type="library" name="Maven: commons-io:commons-io:1.3.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.5.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.4.4" level="project" />
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" />
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.9" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpmime:4.5.2" level="project" />
<orderEntry type="library" name="Maven: com.alibaba:fastjson:1.2.40" level="project" />
<orderEntry type="library" name="Maven: log4j:log4j:1.2.17" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.12" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-log4j12:1.7.12" level="project" />
<orderEntry type="library" name="Maven: mysql:mysql-connector-java:5.1.30" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.11" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: com.github.jsonzou:jmockdata:3.0.1" level="project" />
</component>
</module>

@ -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(){

@ -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

@ -18,11 +18,18 @@
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.9.6" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.9.6" level="project" />
<orderEntry type="library" name="Maven: commons-io:commons-io:1.3.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.5.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.4.4" level="project" />
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" />
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.9" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpmime:4.5.2" level="project" />
<orderEntry type="library" name="Maven: com.alibaba:fastjson:1.2.40" level="project" />
<orderEntry type="library" name="Maven: log4j:log4j:1.2.17" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.12" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-log4j12:1.7.12" level="project" />
<orderEntry type="library" name="Maven: mysql:mysql-connector-java:5.1.30" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.11" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: com.github.jsonzou:jmockdata:3.0.1" level="project" />
</component>
</module>

@ -0,0 +1,11 @@
package org.panda.beans.adapter;
/**
* @Author: qi
* @Description:
* @Date: Create in 9:29 AM 2019/2/23
*/
public interface BeanAdapter {
}

@ -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 <T>
* @return
*/
<T> T getBean(String name,Class<T> requiredType);
/**
* 通过类名查找实例
* @param name
* @param args
* @return
*/
Object getBean(String name,Object... args);
/**
* 通过class查找实例
* @param requiredType
* @param <T>
* @return
*/
<T> T getBean(Class<T> 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);
}

@ -66,12 +66,12 @@ public class BeanUtil {
public static void copyNotNull(Object targer,Object source){
Class sourceClass = source.getClass();
List<Field> fieldList = getAllField(sourceClass);
Map<String,Field> fieldMap = new HashMap<>(fieldList.size());
for (Field field: fieldList){
List<Field> sourcefieldList = getAllField(sourceClass);
Map<String,Field> fieldMap = new HashMap<>(sourcefieldList.size());
sourcefieldList.forEach(field -> {
field.setAccessible(true);
fieldMap.put(field.getName(),field);
}
});
Class targerClass = targer.getClass();
List<Field> 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;
}
/**

@ -14,6 +14,7 @@ import java.util.jar.JarEntry;
import java.util.jar.JarFile;
/**
* @author qi
* 类加载器
*/
public class ClassUtil {

@ -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;
}
}

@ -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());
}
}
}

@ -17,11 +17,18 @@
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.9.6" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.9.6" level="project" />
<orderEntry type="library" name="Maven: commons-io:commons-io:1.3.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.5.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.4.4" level="project" />
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" />
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.9" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpmime:4.5.2" level="project" />
<orderEntry type="library" name="Maven: com.alibaba:fastjson:1.2.40" level="project" />
<orderEntry type="library" name="Maven: log4j:log4j:1.2.17" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.12" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-log4j12:1.7.12" level="project" />
<orderEntry type="library" name="Maven: mysql:mysql-connector-java:5.1.30" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.11" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: com.github.jsonzou:jmockdata:3.0.1" level="project" />
</component>
</module>

@ -27,6 +27,7 @@
<properties>
<jackson.version>2.9.6</jackson.version>
<httpclient.version>4.5.2</httpclient.version>
</properties>
<dependencies>
@ -72,6 +73,26 @@
<version>1.3.2</version>
</dependency>
<!-- http 请求的jar -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${httpclient.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>${httpclient.version}</version>
</dependency>
<!--json包-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.40</version>
</dependency>
</dependencies>

@ -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<T> 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;
}
}

@ -9,6 +9,7 @@ import java.net.URLEncoder;
/**
* @author qi
* 编码与解码操作工具类
*/
public final class CodecUtil {

@ -7,6 +7,7 @@ import java.util.Collection;
import java.util.Map;
/**
* @author qi
* 集合工具类
*/
public class CollectionUtil {

@ -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;

@ -8,6 +8,7 @@ import java.util.List;
import java.util.Map;
/**
* @author qi
* Created by qi on 2017/8/9.
*/
public class HttpUtil {

@ -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 {

@ -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 {

@ -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) {

@ -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);
}
}

@ -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);

@ -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<File> findAllHiddenFile(String dirPath){
File dirFile = new File(dirPath);
return null;
}
public static void main(String[] args) {
getFileList("/Users/qi/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<String, Object> 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<String, Object> params = new HashMap<String, Object>();
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);
}
}

@ -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");
}
}

@ -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 {

@ -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;
}
}

@ -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;
}
}

@ -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;
}
}

@ -19,6 +19,11 @@
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.9.6" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.9.6" level="project" />
<orderEntry type="library" name="Maven: commons-io:commons-io:1.3.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.5.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.4.4" level="project" />
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.9" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpmime:4.5.2" level="project" />
<orderEntry type="library" name="Maven: com.alibaba:fastjson:1.2.40" level="project" />
<orderEntry type="module" module-name="panda-aop" />
<orderEntry type="library" name="Maven: cglib:cglib:3.2.9" level="project" />
<orderEntry type="library" name="Maven: org.ow2.asm:asm:7.0" level="project" />
@ -33,5 +38,6 @@
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.12" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-log4j12:1.7.12" level="project" />
<orderEntry type="library" name="Maven: mysql:mysql-connector-java:5.1.30" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: com.github.jsonzou:jmockdata:3.0.1" level="project" />
</component>
</module>

@ -11,6 +11,7 @@ import java.sql.SQLException;
/**
* @author qi
* 结果集处理类
*/
public class BeanHander implements ResultSetHandler {

@ -6,6 +6,7 @@ import java.util.List;
/**
* @author qi
* 结果集集合处理类
*/
public class BeanListHandler implements ResultSetHandler {

@ -5,7 +5,6 @@ import java.sql.ResultSet;
/**
* @author qi
* 结果集处理接口
*
*/
public interface ResultSetHandler {

@ -1,6 +1,7 @@
package org.panda.jdbc.mode;
/**
* @author qi
* 数据库详情实体
* Created by qi_liang on 2018/6/10.
*/

@ -3,6 +3,7 @@ package org.panda.jdbc.mode;
import java.util.List;
/**
* @author qi
* 数据库表实体
* Created by qi_liang on 2018/6/2.
*/

@ -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<String,Object> fieldMap);

@ -11,6 +11,7 @@ import java.util.Map;
/**
* @author qi
* 维护类名和数据库字段工具类
*/
public class BeanSqlUtil {

@ -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 +
'}';
}
}

@ -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() {
}
}

@ -59,6 +59,13 @@
<scope>test</scope>
</dependency>
<!-- 自动产生测试数据框架-->
<dependency>
<groupId>com.github.jsonzou</groupId>
<artifactId>jmockdata</artifactId>
<version>3.0.1</version>
<scope>test</scope>
</dependency>
</dependencies>

Loading…
Cancel
Save