⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uploadservice.java

📁 在线考试功能
💻 JAVA
字号:
package com.onlinestudy.service;




import java.io.File;
import java.io.IOException;
import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.onlinestudy.domain.Download;
import com.onlinestudy.domain.DownloadClasses;

public class UploadService extends HibernateDaoSupport {
	
	ListForPage listForPage;
	
	public boolean uploadFiles(Download upfile){
	this.getHibernateTemplate().save(upfile);
		return true;
	}
	
	//查询所有分类
	public List selectClasses(){
		List list = this.getHibernateTemplate().find("from DownloadClasses");
		return list;
	}
	
	//ID查询分类
	public DownloadClasses selectClassesById(int id){
		List list = this.getHibernateTemplate().find("from DownloadClasses where id="+id);
			DownloadClasses dlc = (DownloadClasses)list.get(0);		
		return dlc;
	}
	
	//增加分类
	public void addClasses(DownloadClasses uploadClasses){
		this.getHibernateTemplate().save(uploadClasses);
		
	}
	
	
	//删除分类
	public void deleteClasses(DownloadClasses uploadClasses){
		this.getHibernateTemplate().delete(uploadClasses);
		
	}	
	
	//修改分类
	public void updateClasses(DownloadClasses uploadClasses){
		this.getHibernateTemplate().update(uploadClasses);
		
	}
	public int selectFileCount(){
		List list = this.getHibernateTemplate().find("select id from Download");
		int count = list.size();
		return count;
	}
	
	//分页查询全部资源
	public List selectFilesForPage(String hql,int offset,int length){
		List list = listForPage.getListForPage(hql, offset, length);
		return list;
	}
	
	//按ID查询资源
	public Download selectFilesByid(int id){
		List list = this.getHibernateTemplate().find("from Download where id="+id);
		Download d = (Download)list.get(0);
		return d;
	}
	
	//增加文件资源
	public boolean addUpload(Download download){
			this.getHibernateTemplate().save(download);
		return true;
	}
	
	//增加文件资源
	public boolean updateUpload(Download download){
			this.getHibernateTemplate().update(download);
		return true;
	}
	
	//删除单条文件资源
	public boolean deleteUploadById(int id,String path){
	Download d = (Download)this.getHibernateTemplate().find("from Download where id="+id).get(0);	
	String filepath = path+d.getUrl();	
	this.getHibernateTemplate().delete(d);
			System.out.println(filepath);
			 File file = new File(filepath);
			 if(file.exists()){
				 file.delete();
			 }
		return true;
	}
	
	//删除多条文件资源
	public boolean deleteUploadBatch(String[] array, String path){
		for(int i = 0; i < array.length; i++)
		{
			int id = Integer.parseInt(array[i]);
			Download d = (Download)this.getHibernateTemplate().find("from Download where id="+id).get(0);
			String filepath = path+d.getUrl();	
			this.getHibernateTemplate().delete(d);
					System.out.println(filepath);
					 File file = new File(filepath);
					 if(file.exists()){
						 file.delete();
					 }
		}
		return true;
	}

	public void setListForPage(ListForPage listForPage) {
		this.listForPage = listForPage;
	}


}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -