每个类前要有注释,类前的注释格式是:

/**

*类是干什么的

*@author  编写该类的作者

*/

类中的每个方法前也要有注释:

/**

*该方法是干什么的

*@param 该方法中传入的参数

*@return

*/

/**
* 目录服务类
* @author X
*
*/
@Component("project.docm.catalog.CatalogService")
@SuppressWarnings("all")
public class CatalogService {
@Autowired
PlatParamItemService paramItemService;

/**
* 获取根目录
* @return
*/
private String getRootPath(){
return paramItemService.getParam("FILE_FOLDER").getEvalue();
}

private String getIndexPath(){
return paramItemService.getParam("INDEX_FOLDER").getEvalue();
}
/**
* 查询目录
* @param path
* @return
*/
public List getCatalogs(String path) throws Exception{
File file = new File(path);
List result = new ArrayList();
if(file.isDirectory()){
//根目录
Map m = new HashMap();
m.put("id",UUID.randomUUID().toString());
m.put("name", file.getName());
m.put("len", file.list().length);
m.put("path", ZipUtils.gzip(file.getPath()));
m.put("size", file.length());
m.put("iconCls", "fa fa-laptop");
m.put("date", new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(new Date(file.lastModified())));
m.put("children", eachCatalog(file));
result.add(m);
}else{
throw new Exception("不是一个目录");
}
return result;
}

public List getFiles(File catalog){
List result = new ArrayList();
if(catalog.isDirectory() && catalog.exists()){
File[] files = catalog.listFiles();
for(File file : files){
if(file.isFile()){
Map m = new HashMap();
m.put("id",UUID.randomUUID().toString());
m.put("name", file.getName());
m.put("path", ZipUtils.gzip(file.getPath()));
m.put("size", file.length());
m.put("iconCls", "fa fa-laptop");
m.put("date", new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(new Date(file.lastModified())));
result.add(m);
}
}
}
return result;
}

public List eachCatalog(File path){
if(path.isDirectory()){
File[] files = path.listFiles();
List dirs = new ArrayList();
for(File file : files){
if(file.isDirectory()){
Map m = new HashMap();
m.put("id",UUID.randomUUID().toString());
m.put("path", ZipUtils.gzip(file.getPath()));
m.put("name", file.getName());
m.put("len", file.list().length);
m.put("size", file.length());
m.put("iconCls", "fa fa-folder");
m.put("date", new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(new Date(file.lastModified())));
m.put("children", eachCatalog(file));
dirs.add(m);
}
}
return dirs;
}
return null;
}

//新增目录
@Transactional
public Object saveCatalogs(File file){
if(!file.exists()){
if(file.mkdir()){
Map m = new HashMap();
m.put("id",UUID.randomUUID().toString());
m.put("name", file.getName());
m.put("len", file.list().length);
m.put("path", ZipUtils.gzip(file.getPath()));
m.put("size", file.length());
m.put("iconCls", "fa fa-folder");
m.put("date", new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(new Date(file.lastModified())));
m.put("children", eachCatalog(file));
return m;
}
}
return false;
}
//删除目录
public boolean deleteCatalogs(File file) {
if(file.exists() && file.isDirectory()){
if(file.delete()){
//删除索引
try {
IndexHelper.deleteIndex(file, getIndexPath(), getRootPath());
} catch (IOException e) {
e.printStackTrace();
}
return true;
}
}
return false;
}
/**
* 删除文件
* @param file
* @return
*/
public boolean deleteFile(File file) {
if(file.exists()){
return file.delete();
}
return false;
}
}

java web代码规范:的更多相关文章

  1. java web 代码

    原 30套JSP网站源代码合集 IT小白白 发布时间: 2012/12/28 14:30 阅读: 272 收藏: 3 点赞: 0 评论: 0 JSP技术是以Java语言作为脚本语言的,JSP网页为整个 ...

  2. Java&Android代码规范

    项目中直接导入Square的代码风格文件.(不导入Google的原因是Square同时提供了Java和Android两套统一风格,Google只提供了一套) Square Code Styles Go ...

  3. Java web url 规范

    设计URI应该遵循的原则 URI是网站UI的一部分,因此,可用的网站应该满足这些URL要求 简单,好记的域名 简短(short)的URI 容易录入的URI URI能反应站点的结构 URI是可以被用户猜 ...

  4. JAVA总结--代码规范

    一.命名规范 1.标识符:统一.达意.简洁 统一:一个词有多种表达方式,不求最好,但求统一:例:供应商,既可以用supplier,也可以用provider,选择一种统一使用: 达意:明确表达其意义,正 ...

  5. java注释代码规范

    //收集了一小部分,忘记的时候过来查一下 java--hadoop部分 /** * 此类用来处理DNS原始日志:统计给定域名平均响应时延 * @param Input * @param Output ...

  6. Intellij idea 中修改java web代码 ,网页不同步

    问题可能出在  Intellij  idea 没有将源码保存在本地,浏览器访问了缓存而没有访问最新文件 用命令行查看了源码,同步了 接着禁止浏览器缓存,网页同步了 打开火狐浏览器 输入 about:c ...

  7. java idea 代码规范插件

    推荐阿里的 p3c https://github.com/alibaba/p3c

  8. Java代码规范

    Java代码规范 本Java代码规范以SUN的标准Java代码规范为基础,为适应我们公司的实际需要,可能会做一些修改.本文档中没有说明的地方,请参看SUN Java标准代码规范.如果两边有冲突,以SU ...

  9. Java 代码规范,你应该知道的一些工具和用法

    从事编程这个行业,你一定被别人说过或者说过别人这句话:代码要规范!求职面试时也能从 JD 上看到这个要求:要有良好的编程习惯.其实都是在讲代码规范(Code Style)这件事情. 每个人都有自己的编 ...

随机推荐

  1. 关于struts.xml配置文件的说明

    <struts> <!-- action: 对应controller 中的类的 name: 匹配url要访问的类 class:包名+类名 通过反射产生对象 method:指定默认访问 ...

  2. form表单重置、清空方法记录

    myform 是form的id属性值 1.调用reset()方法 function fomrReset() { document.getElementById("myform"). ...

  3. Windows驱动手动卸载与安装

    彻底卸载的流程 1.删除C:\windows\inf\oem.inf路径下的所有oem文件 2.删除c:\windows\system32\drivers路径下对应的sys文件 3.(重要) 第一步: ...

  4. 201671010140. 2016-2017-2 《Java程序设计》java学习第四周

    java学习第四周体会         本周,与前几周不同的是,老师没有进行课堂测试,而是上了一节课,回顾与总结了之前三周所学的知识,也是因为这节课,我注意到了之前学习中忽略的一些细节,和之前学习方法 ...

  5. Web开发: servlet的session为null?

    servlet的session(会话)显示为null,一般是web.xml中配置不对或者在浏览器输入的url不正确造成的. web.xml配置如下: <servlet> <servl ...

  6. acceleration

    acceleration - Bing dictionary US[ək.selə'reɪʃ(ə)n]UK[ək.selə'reɪʃ(ə)n] n.加速度:加快:(车辆)加速能力 网络促进:加速力:加 ...

  7. AasyncTask中执行execute()还是executeOnExecutor()

    executeOnExecutor()api 11 才出现的 并行的 效率比execute()高因为execute()是串行的 import android.app.Activity; import ...

  8. Ubuntu 下如何查看已安装的软件

    1.查看安装的所有软件 dpkg -l 例如:dpkg -l | grep ftp <span style="font-size:18px;">:~$ dpkg -l ...

  9. iOS.AddFont

    为iOS App 添加定制字体 http://www.developers-life.com/how-to-include-ttf-fonts-to-ios-app.html http://blog. ...

  10. gis笔记 wms wfs等OGC标准

    WFS 和WMS的区别 WFS是基于地理要素级别的数据共享和数据操作,WFS规范定义了若干基于地理要素(Feature)级别的数据操作接口,并以 HTTP 作为分布式计算平台.通过 WFS服务,客户端 ...