Compare commits

...

8 Commits

  1. 43
      panda-beans/src/main/java/org/panda/beans/model/BeanAttributeMethod.java
  2. 63
      panda-beans/src/main/java/org/panda/beans/util/BeanUtil.java
  3. 66
      panda-code/src/main/java/org/panda/code/uitl/ImageUtil.java
  4. 6
      panda-code/src/main/java/org/panda/code/uitl/StringUtil.java
  5. 7
      panda-code/src/main/java/org/panda/code/uitl/http/HttpKit.java
  6. 4
      panda-code/src/main/java/org/panda/code/uitl/http/HttpUtil.java
  7. 4
      panda-jdbc/src/main/java/org/panda/jdbc/id/SnowflakeIdGenerate.java

@ -0,0 +1,43 @@
package org.panda.beans.model;
import java.lang.reflect.Method;
public class BeanAttributeMethod {
/**
* set方法
*/
private Method setMethod;
/**
* get方法
*/
private Method getMethod;
/**
* 属性名称
*/
private String fieldName;
public Method getSetMethod() {
return setMethod;
}
public void setSetMethod(Method setMethod) {
this.setMethod = setMethod;
}
public Method getGetMethod() {
return getMethod;
}
public void setGetMethod(Method getMethod) {
this.getMethod = getMethod;
}
public String getFieldName() {
return fieldName;
}
public void setFieldName(String fieldName) {
this.fieldName = fieldName;
}
}

@ -1,6 +1,7 @@
package org.panda.beans.util;
import org.panda.beans.model.BeanAttributeMethod;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -21,6 +22,18 @@ import java.util.*;
public class BeanUtil {
private final static Logger LOGGER = LoggerFactory.getLogger(BeanUtil.class);
/**
* set方法前缀
*/
public final static String SET_PREFIX = "set";
/**
* get方法前缀
*/
public final static String GET_PREFIX = "get";
/**
* is方法前缀
*/
public final static String IS_PREFIX = "is";
/**
* 获取类属性包括父类属性
* @param clazz
@ -89,29 +102,29 @@ public class BeanUtil {
/**
* 复制属性不为空的复制为空忽略
*/
public static void copyNotNull(Object targer,Object source){
public static void copyNotNull(Object target,Object source){
Class sourceClass = source.getClass();
List<Field> sourcefieldList = getAllField(sourceClass);
Map<String,Field> fieldMap = new HashMap<>(sourcefieldList.size());
sourcefieldList.forEach(field -> {
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){
Class targetClass = target.getClass();
List<Field> targetFieldList = getAllField(targetClass);
for (Field field:targetFieldList){
field.setAccessible(true);
Field targerField = fieldMap.get(field.getName());
Field targetField = fieldMap.get(field.getName());
//判断类型是否相等
if (targerField!=null&&targerField.getGenericType().toString().equals(field.getGenericType().toString())){
if (targetField!=null&&targetField.getGenericType().toString().equals(field.getGenericType().toString())){
try {
PropertyDescriptor pd = new PropertyDescriptor(targerField.getName(), targerClass);
PropertyDescriptor pd = new PropertyDescriptor(targetField.getName(), targetClass);
//获得写方法
Method setFieldMethod = pd.getWriteMethod();
Object value = targerField.get(source);
Object value = targetField.get(source);
if (value!=null) {
setFieldMethod.invoke(targer, value);
setFieldMethod.invoke(target, value);
}
} catch (IllegalAccessException e) {
e.printStackTrace();
@ -243,9 +256,7 @@ public class BeanUtil {
T t = null;
try {
t = clazz.newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
} catch (InstantiationException | IllegalAccessException e) {
e.printStackTrace();
}
@ -281,4 +292,26 @@ public class BeanUtil {
return t;
}
/**
* 获取对象的方法
* @param clazz
* @param fieldName
* @return
*/
public static BeanAttributeMethod getAttributeMethod(Class clazz,String fieldName){
Method setMethod = null;
Method getMethod = null;
BeanAttributeMethod beanAttributeMethod = null;
try {
Field field = clazz.getDeclaredField(fieldName);
} catch (NoSuchFieldException e) {
LOGGER.error("无对应属性",e);
}
return beanAttributeMethod;
}
}

@ -0,0 +1,66 @@
package org.panda.code.uitl;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
/**
* 图片处理工具类
* @author qi
*/
public class ImageUtil {
/**
*
* @param filePath png图片路径
* @param outPrintFilePath 转换后文件输出路径
*/
public static void png2jpeg(String filePath,String outPrintFilePath) {
//读取图片
FileOutputStream fos =null;
try {
BufferedImage bufferedImage = ImageIO.read(new File(filePath));
//转成jpeg、
BufferedImage bufferedImage1 = new BufferedImage(bufferedImage.getWidth(),
bufferedImage.getHeight(),
BufferedImage.TYPE_INT_RGB);
bufferedImage1.createGraphics().drawImage(bufferedImage,0,0, Color.white,null);
fos = new FileOutputStream(outPrintFilePath);
ImageIO.write(bufferedImage,"jpg",fos);
fos.flush();
} catch (IOException e) {
e.printStackTrace();
try {
fos.close();
} catch (IOException ioException) {
ioException.printStackTrace();
}
}
}
/**
* jpg转png
* @param filePath jpg文件路径
* @param outPrintFilePath 转换后文件输出路径
*/
public static void jpeg2png(String filePath,String outPrintFilePath) {
//读取图片
try {
BufferedImage bufferedImage = ImageIO.read(new File(filePath));
//转成png、
BufferedImage bufferedImage1 = new BufferedImage(bufferedImage.getWidth(),
bufferedImage.getHeight(),
BufferedImage.TYPE_INT_ARGB);
bufferedImage1.createGraphics().drawImage(bufferedImage,0,0, Color.white,null);
FileOutputStream fos = new FileOutputStream(outPrintFilePath);
ImageIO.write(bufferedImage1,"png",fos);
} catch (IOException e) {
e.printStackTrace();
}
}
}

@ -71,11 +71,11 @@ public class StringUtil {
public static String randomString(int length){
StringBuffer randomString=new StringBuffer();
while (length>0){
Random random=new Random();
int ran=random.nextInt(3);
ThreadLocalRandom threadLocalRandom = ThreadLocalRandom.current();
int ran=threadLocalRandom.nextInt(3);
switch (ran){
case 0:
randomString.append(random.nextInt(10));
randomString.append(threadLocalRandom.nextInt(10));
break;
case 1:
randomString.append(randomLowerCase());

@ -5,8 +5,10 @@
package org.panda.code.uitl.http;
import org.apache.log4j.Logger;
import org.panda.code.uitl.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedReader;
import java.io.InputStream;
@ -32,7 +34,8 @@ public class HttpKit {
private static final String DEFAULT_CHARSET = "UTF-8";
private static final String HTTP_PARAM_SYMBOL = "?";
private static final Logger LOGGER = Logger.getLogger(HttpKit.class);
private static final Logger LOGGER = LoggerFactory.getLogger(HttpKit.class);
/**
* 发送Get请求

@ -18,8 +18,8 @@ public class HttpUtil {
BufferedReader in=null;
try {
String urlNameString=url+"?"+param;
URL reaulUrl=new URL("http://www.baidu.com");
URLConnection connection=reaulUrl.openConnection();
URL realUrl=new URL(urlNameString);
URLConnection connection=realUrl.openConnection();
// 设置通用的请求属性
connection.setRequestProperty(" ", "*/*");

@ -9,7 +9,7 @@ public class SnowflakeIdGenerate implements IdGenerate<Long> {
/**
* 开始时间戳
*/
private final long twepoch = 1420041600000L;
private final long TWEPOCH = 1420041600000L;
/**
* 机器id所占的位数
@ -107,7 +107,7 @@ public class SnowflakeIdGenerate implements IdGenerate<Long> {
}
//上次生成ID的时间戳
lastTimeStamp = timestamp;
return ((timestamp-twepoch)<<timestampLeftShift)
return ((timestamp-TWEPOCH)<<timestampLeftShift)
|(dataCenterId<<dataCenterIdShift)
|(workerId<<workerIdShift)
|sequence;

Loading…
Cancel
Save