zoukankan      html  css  js  c++  java
  • java web代码规范:

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

    /**

    *类是干什么的

    *@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;
    }
    }

  • 相关阅读:
    Flash Builder 使用
    解决谷歌地图偏移问题
    南京垃圾处理场分布图-益云地图
    在Oracle Spatial中增加Web Mercator投影坐标系
    学习和使用 Styled Layer Descriptor SLD样式文件
    jmeter安装教程
    Linux常见命令更新中...
    Python并发编程(线程队列,协程,Greenlet,Gevent)
    Python并发编程(线程,Threading模块,守护线程,gil锁,)
    Python并发编程(管道,数据共享,信号量,进程池)
  • 原文地址:https://www.cnblogs.com/zhangshitong/p/4974460.html
Copyright © 2011-2022 走看看