package com.lhp.sino.core;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Random;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGEncodeParam;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
/**
* MyUtils.java Create on 2008-9-17 下午10:45:20
*
* 工具类
*
* Copyright (c) 2008 by MTA.
*
* @author刘浩平
* @version 1.0
*/
public class MyUtils {
public static void main(String[] s) {
List conditions = new ArrayList();
MyUtils.addToCollection(conditions, MyUtils.split("a,b-c d,e f-g", " ,-"));
System.out.println(conditions);// output[a, b, c, d, e, f, g]
}
/**
* 删除文件
*
* @param filePathAndName
* String 文件路径及名称 如c:/fqf.txt
* @param fileContent
* String
* @return boolean
*/
public static boolean delFile(String filePathAndName) {
File myDelFile = new java.io.File(filePathAndName);
if (!myDelFile.exists()) {
return true;
}
return myDelFile.delete();
}
/**
* 上传文件
*
* @param uploadFileName
* 被上传的文件名称
* @param savePath
* 文件的保存路径
* @param uploadFile
* 被上传的文件
* @return newFileName
*/
public static String upload(String uploadFileName, String savePath, File uploadFile) {
String newFileName = getRandomName(uploadFileName, savePath);
try {
FileOutputStream fos = new FileOutputStream(savePath + newFileName);
FileInputStream fis = new FileInputStream(uploadFile);
byte[] buffer = new byte[1024];
int len = 0;
while ((len = fis.read(buffer)) > 0) {
fos.write(buffer, 0, len);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return newFileName;
}
/**
* 根据路径创建一系列的目录
*
* @param path
*/
public static void mkDirectory(String path) {
File file;
try {
file = new File(path);
if (!file.exists()) {
file.mkdirs();
}
} catch (RuntimeException e) {
e.printStackTrace();
} finally {
file = null;
}
}
/**
* 将对象数组的每一个元素分别添加到指定集合中,调用Apache commons collections 中的方法
*
* @param collection
* 目标集合对象
* @param arr
* 对象数组
*/
public static void addToCollection(Collection collection, Object[] arr) {
if (null != collection && null != arr) {
CollectionUtils.addAll(collection, arr);
}
}
/**
* 将字符串已多个分隔符拆分为数组,调用Apache commons lang 中的方法
*
* <pre>
* Example:
* String[] arr = StringUtils.split("a b,c d,e-f", " ,-");
* System.out.println(arr.length);//输出6
* </pre>
*
* @param str
* 目标字符串
* @param separatorChars
* 分隔符字符串
* @return 字符串数组
*/
public static String[] split(String str, String separatorChars) {
return StringUtils.split(str, separatorChars);
}
/**
* 调用指定字段的setter方法
*
* <pre>
* Example:
* User user = new User();
* MyUtils.invokeSetMethod("userName", user, new Object[] {"张三"});
* </pre>
*
* @param fieldName
* 字段(属性)名称
* @param invokeObj
* 被调用方法的对象
* @param args
* 被调用方法的参数数组
* @return 成功与否
*/
public static boolean invokeSetMethod(String fieldName, Object invokeObj, Object[] args) {
boolean flag = false;
Field[] fields = invokeObj.getClass().getDeclaredFields(); // 获得对象实体类中所有定义的字段
Method[] methods = invokeObj.getClass().getDeclaredMethods(); // 获得对象实体类中所有定义的方法
for (Field f : fields) {
String fname = f.getName();
if (fname.equals(fieldName)) {// 找到要更新的字段名
String mname = "set" + (fname.substring(0, 1).toUpperCase() + fname.substring(1));// 组建setter方法
for (Method m : methods) {
String name = m.getName();
if (mname.equals(name)) {
// 处理Integer参数
if (f.getType().getSimpleName().equalsIgnoreCase("integer") && args.length > 0) {
args[0] = Integer.valueOf(args[0].toString());
}
// 处理Boolean参数
if (f.getType().getSimpleName().equalsIgnoreCase("boolean") && args.length > 0) {
args[0] = Boolean.valueOf(args[0].toString());
}
try {
m.invoke(invokeObj, args);
flag = true;
} catch (IllegalArgumentException e) {
flag = false;
e.printStackTrace();
} catch (IllegalAccessException e) {
flag = false;
e.printStackTrace();
} catch (InvocationTargetException e) {
flag = false;
e.printStackTrace();
}
}
}
}
}
return flag;
}
/**
* 判断文件是否存在
*
* @param fileName
* @param dir
* @return
*/
public static boolean isFileExist(String fileName, String dir) {
File files = new File(dir + fileName);
return (files.exists()) ? true : false;
}
/**
* 获得随机文件名,保证在同一个文件夹下不同名
*
* @param fileName
* @param dir
* @return
*/
public static String getRandomName(String fileName, String dir) {
String[] split = fileName.split("\\.");// 将文件名已.的形式拆分
String extendFile = "." + split[split.length - 1].toLowerCase(); // 获文件的有效后缀
Random random = new Random();
int add = random.nextInt(1000000); // 产生随机数10000以内
String ret = add + extendFile;
while (isFileExist(ret, dir)) {
add = random.nextInt(1000000);
ret = fileName + add + extendFile;
}
return ret;
}
/**
* 创建缩略图
*
* @param file
* 上传的文件流
* @param height
* 最小的尺寸
* @throws IOException
*/
public static void createMiniPic(File file, float width, float height) throws IOException {
Image src = javax.imageio.ImageIO.read(file); // 构造Image对象
int old_w = src.getWidth(null); // 得到源图宽
int old_h = src.getHeight(null);
int new_w = 0;
int new_h = 0; // 得到源图长
float tempdouble;
if (old_w >= old_h) {
tempdouble = old_w / width;
} else {
tempdouble = old_h / height;
}
if (old_w >= width || old_h >= height) { // 如果文件小于锁略图的尺寸则复制即可
new_w = Math.round(old_w / tempdouble);
new_h = Math.round(old_h / tempdouble);// 计算新图长宽
while (new_w > width && new_h > height) {
if (new_w > width) {
tempdouble = new_w / width;
new_w = Math.round(new_w / tempdouble);
new_h = Math.round(new_h / tempdouble);
}
if (new_h > height) {
tempdouble = new_h / height;
new_w = Math.round(new_w / tempdouble);
new_h = Math.round(new_h / tempdouble);
}
}
BufferedImage tag = new BufferedImage(new_w, new_h, BufferedImage.TYPE_INT_RGB);
tag.getGraphics().drawImage(src, 0, 0, new_w, new_h, null); // 绘制缩小后的图
FileOutputStream newimage = new FileOutputStream(file); // 输出到文件流
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(newimage);
JPEGEncodeParam param = encoder.getDefaultJPEGEncodePar
没有合适的资源?快使用搜索试试~ 我知道了~
ibatis,spring,struts2,extjs4.2做的一个上左右的框架
共92个文件
java:21个
class:21个
xml:18个
3星 · 超过75%的资源 需积分: 4 38 下载量 135 浏览量
2014-01-08
10:00:19
上传
评论 3
收藏 113KB ZIP 举报
温馨提示
用extjs4.2做的一个左边树型菜,右边显示tappanel上面显示图片,数据库oracle,用到了ibatis,spring,struts2。jar包和数据库在下一个资料中,因extjs文件太大不能上请自已下载,带oracle数据库表。
资源推荐
资源详情
资源评论
收起资源包目录
crm.zip (92个子文件)
crm
.project 2KB
.mymetadata 282B
src
applicationContext-daos.xml 884B
applicationContext-actions.xml 928B
applicationContext-common.xml 2KB
struts.xml 2KB
com
lhp
sino
service
IMenuService.java 164B
impl
MenuService.java 565B
UserService.java 1KB
IUserService.java 1017B
action
MenuAction.java 2KB
UserAction.java 8KB
UsersAction.java 3KB
core
BaseAction.java 2KB
Page.java 1KB
MyUtils.java 9KB
dao
IMenuDao.java 165B
impl
MenuDao.java 411B
UserDao.java 1KB
IUserDao.java 1KB
po
User.java 3KB
xml
Menu.xml 395B
User.xml 7KB
Menu.java 2KB
SqlMapConfig.xml 519B
applicationContext-services.xml 888B
work
org
apache
jsp
index_jsp.java 3KB
image_jsp.class 6KB
image_jsp.java 4KB
form_jsp.class 6KB
main
manager_005findex_jsp.java 3KB
quangxian_jsp.java 3KB
manager_005findex_jsp.class 4KB
quangxian_jsp.class 4KB
form_jsp.java 7KB
index_jsp.class 4KB
WebRoot
WEB-INF
classes
applicationContext-daos.xml 884B
applicationContext-actions.xml 928B
applicationContext-common.xml 2KB
struts.xml 2KB
com
lhp
sino
service
IMenuService.class 274B
impl
UserService.class 2KB
MenuService.class 994B
IUserService.class 539B
action
UsersAction.class 3KB
MenuAction.class 3KB
UserAction.class 8KB
core
BaseAction.class 2KB
Page.class 2KB
MyUtils.class 8KB
dao
IUserDao.class 603B
impl
MenuDao.class 868B
UserDao.class 2KB
IMenuDao.class 262B
po
User.class 4KB
Menu.class 2KB
xml
Menu.xml 395B
User.xml 7KB
SqlMapConfig.xml 519B
applicationContext-services.xml 888B
lib
web.xml 833B
code.css 138B
login0.js 3KB
login.js 2KB
index.jsp 756B
login1.js 2KB
form.jsp 1KB
code.js 831B
META-INF
MANIFEST.MF 36B
image.jsp 2KB
code.jsp 1KB
main
main17.js 6KB
quangxian.js 17KB
main.js 12KB
testmain.js 8KB
User.js 29KB
App.js 3KB
quangxian.jsp 723B
usermain.js 6KB
manager_index.jsp 806B
main18.js 7KB
LoginDialog.js 5KB
.myeclipse
.settings
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.wst.common.project.facet.core.xml 252B
com.genuitec.eclipse.ws.prefs 109B
org.eclipse.jdt.core.prefs 395B
org.eclipse.wst.jsdt.ui.superType.name 6B
org.eclipse.core.resources.prefs 88B
org.eclipse.wst.common.component 447B
.jsdtscope 493B
.tomcatplugin 359B
.classpath 4KB
共 92 条
- 1
资源评论
- soya_kuen2015-06-16新手可以借鉴下
勤能补拙笨鸟先飞
- 粉丝: 2
- 资源: 28
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功