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)这件事情. 每个人都有自己的编 ...
随机推荐
- CNN深度好文
https://www.zhihu.com/question/52668301/answer/194998098?utm_medium=social&utm_source=qq
- python文件的只读,只写操作
只读:r rb(bytes类型数据) 只写:w wb(bytes类型数据) 在文件最后追加: f = open('log',mode='a',encoding='utf-8') f.write('这里 ...
- R画散点图、线型图、箱型图、直方图基本知识
1.导入数据 2.散点图 plot(iris[,1]~iris[,4],xlab='Length',ylab='Width',col='red',main='Length VS Width')
- Typora快捷键的使用
无序列表:输入-之后输入空格 有序列表:输入数字+“.”之后输入空格 任务列表:-[空格]空格 文字 标题:ctrl+数字 表格:ctrl+t 生成目录:[TOC]按回车 选中一整行:ctrl+l 选 ...
- spring boot 启动方式
一:IDE 运行Application这个类的main方法 二:在springboot的应用的根目录下运行mvn spring-boot:run 三:使用mvn install 生成jar后运行 先到 ...
- 使用Font Awesome替换你的网站图标(icons 图标)
http://www.thinkcmf.com/font/icons/ 第一次使用 Font Awesome 发现相当的爽呀!它的图标很全,能够帮你节约时间去找图片.下面就来一起学习吧: 1: 去官方 ...
- oracle查询锁表
select b.username,b.sid,b.serial#,logon_time from v$locked_object a,v$session b where a.session_id = ...
- java的Map浅析
Map<K,V>是以键-值对存储的(key-value), 而Entry<K,V>是Map中的一个接口,Map.Entry<K,V>接口主要用于获取.比较 key和 ...
- 97. Interleaving String (String; DP)
Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. For example,Given:s1 = ...
- Island Transport
Island Transport http://acm.hdu.edu.cn/showproblem.php?pid=4280 Time Limit: 20000/10000 MS (Java/Oth ...