java web代码规范_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;

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值