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

  • 相关阅读:
    接口测试该怎么做
    Mac操作Github实现代码的下载、上传
    Django开发基础--操作数据库
    Django开发基础--创建项目/应用
    Python统计安卓log中Anr、Crash出现的数量
    Mac下PyCharm快捷键大全
    Selenium常用方法及函数、txt参数化
    Appium基于PO模型
    Selenium免登录、等待、unittest、PO模型
    Python接口请求及封装
  • 原文地址:https://www.cnblogs.com/zhangshitong/p/4974460.html
Copyright © 2011-2022 走看看