菜鸟求助,代码简化一下

yifuzhiming 2006-11-30 09:46:30
下面的三个判断能不能用for循环简化一下
if (from1.getuploadfile1().getFileSize() != 0) {
System.out.println("1234");
str = com.getpicturename(from1.getuploadfile1(), path);
strpath.append(str + ",");
}

if (from1.getuploadfile2().getFileSize() != 0) {
System.out.println("1234");
str = com.getpicturename(from1.getuploadfile2(), path);
strpath.append(str + ",");
}

if (from1.getuploadfile3().getFileSize() != 0) {
System.out.println("1234");
str = com.getpicturename(from1.getuploadfile3(), path);
strpath.append(str + ",");
}
...全文
173 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
yifuzhiming 2006-12-04
  • 打赏
  • 举报
回复
谢谢pdskiller(害虫),我的问题已解决
ChenSu2008 2006-11-30
  • 打赏
  • 举报
回复
这东西如果设计程序的时候getuploadfile1(), getuploadfile2()...
设计成getuploadfile(parameter), 也许这个地方就会很简洁。

令,不知道java中有没有类似javascript的eval,呵呵。
eidolon_warrior 2006-11-30
  • 打赏
  • 举报
回复
你可以把from1.getuploadfile1() from1.getuploadfile2() from1.getuploadfile3()先放到一个file[] 里然后循环访问
pdskiller 2006-11-30
  • 打赏
  • 举报
回复
file[] uploadfile={from1.getuploadfile1(),from1.getuploadfile2() ,from1.getuploadfile3()};
for(int i=0;i<3;i++)
{
if (uploadfile[i].getFileSize()!= 0) {
System.out.println("1234");
str = com.getpicturename(file[i], path);
strpath.append(str + ",");
}
}
只是个思路,我写的不一定对。
yifuzhiming 2006-11-30
  • 打赏
  • 举报
回复
eidolon_warrior(精灵_战士)

你说的方法我试过,是行不通的,因为HTML的file不是array,不象checkbox

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧