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;
}
}
java web代码规范:的更多相关文章
- java web 代码
原 30套JSP网站源代码合集 IT小白白 发布时间: 2012/12/28 14:30 阅读: 272 收藏: 3 点赞: 0 评论: 0 JSP技术是以Java语言作为脚本语言的,JSP网页为整个 ...
- Java&Android代码规范
项目中直接导入Square的代码风格文件.(不导入Google的原因是Square同时提供了Java和Android两套统一风格,Google只提供了一套) Square Code Styles Go ...
- Java web url 规范
设计URI应该遵循的原则 URI是网站UI的一部分,因此,可用的网站应该满足这些URL要求 简单,好记的域名 简短(short)的URI 容易录入的URI URI能反应站点的结构 URI是可以被用户猜 ...
- JAVA总结--代码规范
一.命名规范 1.标识符:统一.达意.简洁 统一:一个词有多种表达方式,不求最好,但求统一:例:供应商,既可以用supplier,也可以用provider,选择一种统一使用: 达意:明确表达其意义,正 ...
- java注释代码规范
//收集了一小部分,忘记的时候过来查一下 java--hadoop部分 /** * 此类用来处理DNS原始日志:统计给定域名平均响应时延 * @param Input * @param Output ...
- Intellij idea 中修改java web代码 ,网页不同步
问题可能出在 Intellij idea 没有将源码保存在本地,浏览器访问了缓存而没有访问最新文件 用命令行查看了源码,同步了 接着禁止浏览器缓存,网页同步了 打开火狐浏览器 输入 about:c ...
- java idea 代码规范插件
推荐阿里的 p3c https://github.com/alibaba/p3c
- Java代码规范
Java代码规范 本Java代码规范以SUN的标准Java代码规范为基础,为适应我们公司的实际需要,可能会做一些修改.本文档中没有说明的地方,请参看SUN Java标准代码规范.如果两边有冲突,以SU ...
- Java 代码规范,你应该知道的一些工具和用法
从事编程这个行业,你一定被别人说过或者说过别人这句话:代码要规范!求职面试时也能从 JD 上看到这个要求:要有良好的编程习惯.其实都是在讲代码规范(Code Style)这件事情. 每个人都有自己的编 ...
随机推荐
- fio 测试磁盘
root@rook-test:/# ceph osd status+----+-----------------------------+-------+-------+--------+------ ...
- HTTP Response Code 中文详解
引自:https://blog.csdn.net/lplj717/article/details/70053560 1xx - 信息提示这些状态代码表示临时的响应.客户端在收到常规响应之前,应 ...
- C++ 内存解析
一.内存基本构成可编程内存在基本上分为这样的几大部分:静态存储区.堆区和栈区.他们的功能不同,对他们使用方式也就不同. 静态存储区:内存在程序编译的时候就已经分配好,这块内存在程序的整个运行期间都存在 ...
- python事件驱动的小例子
首先我们写一个超级简单的web框架 event_list = [] #这个event_list中会存放所有要执行的类 def run(): for event in event_list: obj = ...
- sobel 使用说明
转自http://www.cnblogs.com/justany/archive/2012/11/23/2782660.html OpenCV 2.4+ C++ 边缘梯度计算 2012-11-23 0 ...
- 轮播图jQuery
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- iOS.AVCaptureSession
AVCaptureSession的使用容易freeze的问题 1. http://stackoverflow.com/questions/11905505/avcapturesession-stop- ...
- rpmdb open failed的解决办法
错误信息如下: “错误:无法从 /var/lib/rpm 打开软件包数据库 CRITICAL:yum.main: Error: rpmdb open failed” ...
- Jmeter获取不到cookie(备注:前面和后面的几个步骤都可以获取到cookie)
今天的一个Jmeter脚本,有一个HTTP request始终获取不到cookie,但其前面和后面的几个步骤都可以获取到cookie,报文的请求服务器地址都是照着fiddler上面填的,没有问题,后来 ...
- 记录下 UTF6 GBK 转换函数
int GBK2UTF8(char *szGbk,char *szUtf8,int Len) { // 先将多字节GBK(CP_ACP或ANSI)转换成宽字符UTF-16 // 得到转换后,所需要的内 ...