随机数代码优化

master
星期八 3 years ago
parent 61d69e4b5f
commit a4cfec8196
  1. 43
      panda-beans/src/main/java/org/panda/beans/model/BeanAttributeMethod.java
  2. 35
      panda-beans/src/main/java/org/panda/beans/util/BeanUtil.java
  3. 66
      panda-code/src/main/java/org/panda/code/uitl/ImageUtil.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; package org.panda.beans.util;
import org.panda.beans.model.BeanAttributeMethod;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -21,6 +22,18 @@ import java.util.*;
public class BeanUtil { public class BeanUtil {
private final static Logger LOGGER = LoggerFactory.getLogger(BeanUtil.class); 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 * @param clazz
@ -279,4 +292,26 @@ public class BeanUtil {
return t; 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();
}
}
}
Loading…
Cancel
Save