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

📄 articledaoim.java

📁 前台:文章浏览、发表留言、Game、Music 后台:文章相关:发表文章、修改文章、删除文章、批量移动文章 栏目相关:增加栏目、修改栏目、删除栏目、栏目链接、栏目排序系统栏目分为系统内部栏目和外部栏目
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
				curArt.setReadtimes(dbconn.getInt(7));
				
				artlist.add(curArt);
			}
		}catch(Exception e){
			e.printStackTrace();
			yhlog.warn("When get all article of system,throw an Exception!");
		}finally{
			dbconn.close();
		}
		return artlist;
	}
	
	public List getPreNextArt(int artid,int bid) throws DBConnException {
		ArrayList artlist = new ArrayList();
		PreNextDto pArt = null;
		PreNextDto nArt = null;
		
		String sqlp = "select id,ftitle from article where id =" + bid;
		String sqln = "select id,ftitle from article where bid ="+artid;
		try{
			dbconn = new DBConnect(sqlp);
			dbconn.executeQuery();
			pArt = new PreNextDto();
			if(dbconn.next()){
				pArt.setId(dbconn.getInt(1));
				pArt.setFirsttitle(dbconn.getString(2));
			}
		}catch(Exception e){
			e.printStackTrace();
			yhlog.warn("When get the previous of an article,throw an Exception!The article id is:"+artid+".");
		}finally{
			dbconn.close();
			artlist.add(pArt);
		}
		
		try{
			dbconn = new DBConnect(sqln);
			dbconn.executeQuery();
			nArt = new PreNextDto();
			if(dbconn.next()){
				nArt.setId(dbconn.getInt(1));
				nArt.setFirsttitle(dbconn.getString(2));
			}
		}catch(Exception e){
			e.printStackTrace();
			yhlog.warn("When get the next of an article,throw an Exception!The article id is:"+artid+".");
		}finally{
			dbconn.close();
			artlist.add(nArt);
		}
		return artlist;
	}

	public Article getArticleById(int id) throws DBConnException {
		Article curArt = null;
		String sql = "select a.ftitle,a.stitle,a.cmfrom,a.author,a.editor,a.bigclassid,a.bigclass," +
					 "a.content,a.ftime,a.readtimes,a.bid from article as a where a.id="+id;
		try{
			dbconn = new DBConnect(sql);
			dbconn.executeQuery();
			if(dbconn.next()){
				curArt = new Article();
				curArt.setId(id);
				curArt.setFirsttitle(dbconn.getString(1));
				curArt.setSecondtitle(dbconn.getString(2));
				curArt.setComefrom(dbconn.getString(3));
				curArt.setAuthor(dbconn.getString(4));
				curArt.setEditor(dbconn.getString(5));
				curArt.setBigclassid(dbconn.getInt(6));
				curArt.setBigclass(dbconn.getString(7));
				curArt.setContent(StringUtils.strEncode(dbconn.getString(8)));
				curArt.setFdatetime(dbconn.getString(9));
				curArt.setReadtimes(dbconn.getInt(10));
				curArt.setBid(dbconn.getInt(11));
			}
		}catch(Exception e){
			yhlog.warn("When get an article,throw an Exception!The article id is:"+id+".");
		}finally{
			dbconn.close();
		}
		return curArt;
	}

	public boolean moveAllArt(int fromId,int toId,String toCName) throws DBConnException {
		int i = 0;
		
		String sql = "update article set bigclassid="+toId+",bigclass='"+toCName+"' where bigclassid="+fromId;
		try{
			dbconn = new DBConnect(sql);
			i = dbconn.executeUpdate();
		}catch(Exception e){
			yhlog.warn("When move all the articles of a class to the other one,throw an Exception!The start " +
						"classid is:"+fromId+",the end classid is:"+toId+".");
		}finally{
			dbconn.close();
		}
		if(i>0){
			yhlog.info("Move all the articles of a class successfully.the start classid is:"+fromId+
						",the end classid is:"+toId+".");
			return true;
		}else{
			yhlog.info("move article of class failed!");
			return false;
		}
	
	}

	public int getArtMaxId() throws DBConnException {
		int maxId = 0;
		String sql = "select max(id) from article";
		try{
			dbconn = new DBConnect(sql);
			dbconn.executeQuery();
			if(dbconn.next()){
				maxId = dbconn.getInt(1);
			}
		}catch(Exception e){
			yhlog.warn("When get the max id of system article,throw an Exception!");
		}finally{
			dbconn.close();
		}
		return maxId;
	}
	
	public int getArtMaxId(int classid) throws DBConnException {
		int maxId = 0;
		String sql = "select max(id) from article where bigclassid="+classid;
		try{
			dbconn = new DBConnect(sql);
			dbconn.executeQuery();
			if(dbconn.next()){
				maxId = dbconn.getInt(1);
			}
		}catch(Exception e){
			yhlog.warn("When get the max article id of a class,throw an Exception!The class id is:"+classid+".");
		}finally{
			dbconn.close();
		}
		return maxId;
	}

	public int getArtNum(int classid) throws DBConnException {
		int num = 0;
		String sql = "select count(id) from article where bigclassid="+classid;
		try{
			dbconn = new DBConnect(sql);
			dbconn.executeQuery();
			if(dbconn.next()){
				num = dbconn.getInt(1);
			}
		}catch(Exception e){
			yhlog.warn("When get the article count of a class,throw an Exception!The class id is:"+classid+".");
		}finally{
			dbconn.close();
		}
		return num;
	}
	
	public int getArtNum() throws DBConnException {
		int num = 0;
		String sql = "select count(id) from article ";
		try{
			dbconn = new DBConnect(sql);
			dbconn.executeQuery();
			if(dbconn.next()){
				num = dbconn.getInt(1);
			}
		}catch(Exception e){
			yhlog.warn("When get the article count of system,throw an Exception!");
		}finally{
			dbconn.close();
		}
		return num;
	}
	
	public List getNewArts(int length) throws DBConnException {
		ArrayList artlist = new ArrayList();
		ArticleDto curArt = null;
		String str = "";
		String sql = "select a.id,a.ftitle,a.author,a.ftime,a.readtimes,a.bigclassid,a.bigclass from article as a order by a.id desc limit "+length;
		try{
			dbconn = new DBConnect(sql);
			dbconn.executeQuery();
			while(dbconn.next()){
				curArt = new ArticleDto();
				curArt.setId(dbconn.getInt(1));
				str = dbconn.getString(2);
				if(str.length()>16){
					curArt.setFirsttitle(str.substring(0,16)+"......");
				}else{
					curArt.setFirsttitle(str);
				}
				curArt.setAuthor(dbconn.getString(3));
				curArt.setFdatetime(dbconn.getString(4));
				curArt.setReadtimes(dbconn.getInt(5));
				curArt.setBigclassid(dbconn.getInt(6));
				curArt.setBigclass(dbconn.getString(7));
				artlist.add(curArt);
			}
		}catch(Exception e){
			yhlog.warn("When get the new article of system,throw an Exception!");
		}finally{
			dbconn.close();
		}
		return artlist;
	}
	
	public void addOneReadTime(int id) throws DBConnException{
		String sql = "update article set readtimes=readtimes+1 where id="+id;
		try{
			dbconn = new DBConnect(sql);
			dbconn.executeUpdate();
		}catch(Exception e){
			yhlog.warn("When update an article readtimes,throw an Exception!");
		}finally{
			dbconn.close();
		}
		
	}

	public List searchTitle(String content, int classid, int begin, int size) throws DBConnException {
		ArrayList artlist = new ArrayList();
		ArticleDto curArt = null;
		String str = "";
		String sql = "";
		if(classid>0){
			 sql = "select a.id,a.ftitle,a.author,a.ftime,a.readtimes from article as a " +
			 "where a.bigclassid="+classid+" and a.ftitle like'%"+content+"%' order by a.id desc limit "+begin+","+size;
		}else{
			 sql = "select a.id,a.ftitle,a.author,a.ftime,a.readtimes from article as a " +
			 "where a.ftitle like'%"+content+"%' order by a.id desc limit "+begin+","+size;
		}
		
		try{
			dbconn = new DBConnect(sql);
			dbconn.executeQuery();
			while(dbconn.next()){
				curArt = new ArticleDto();
				curArt.setId(dbconn.getInt(1));
				str = dbconn.getString(2);
				if(str.length()>16){
					curArt.setFirsttitle(str.substring(0,16)+"......");
				}else{
					curArt.setFirsttitle(str);
				}
				curArt.setAuthor(dbconn.getString(3));
				curArt.setFdatetime(dbconn.getString(4));
				curArt.setReadtimes(dbconn.getInt(5));
				
				artlist.add(curArt);
			}
		}catch(Exception e){
			e.printStackTrace();
			yhlog.warn("When get search article,throw an Exception!The class id is:"+classid+".");
		}finally{
			dbconn.close();
		}
		return artlist;
	}
	
	public int searchTitleNum(String content,int classid) throws DBConnException {
		int num = 0;
		String sql = "";
		if(classid>0){
			 sql = "select count(id) from article as a where a.bigclassid="+classid+" and a.ftitle like'%"+content+"%' ";
		}else{
			 sql = "select count(id) from article as a where a.ftitle like'%"+content+"%' ";
		}
		try{
			dbconn = new DBConnect(sql);
			dbconn.executeQuery();
			if(dbconn.next()){
				num = dbconn.getInt(1);
			}
		}catch(Exception e){
			yhlog.warn("When get the search count of a class,throw an Exception!The class id is:"+classid+".");
		}finally{
			dbconn.close();
		}
		return num;
	}
}

⌨️ 快捷键说明

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