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

📄 sightdao.java

📁 java+mapxtreme 开发校园房管系统
💻 JAVA
字号:
package com.oyc.mapxtreme.dao;

import java.util.List;

import com.oyc.mapxtreme.beans.SightBean;
import com.oyc.wakeup.Session;

/**
 * 景点dao,操作数据库,查询景点
 * @author 三峡大学理学院 欧阳超
 *
 */
public class SightDAO {
	
	/** 数据库会话对象 **/
	private Session sess=null;
	
	/**
	 * 构造器:根据数据库会话来创建一个通讯录管理器
	 * @param sess 数据库会话对象
	 */
	public SightDAO(Session sess){
		this.sess=sess;
	}
	
	/**
	 * 根据景点ID查找某个景点
	 * @param sightID 景点ID
	 * @return
	 */
	public SightBean getSightById(int sightID){
		List list = null;
		try {
			String sql = "select * from tb_sight where sightID="+ sightID;
			list = sess.query(sql, SightBean.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		if(list != null && list.size() > 0){
			return (SightBean) list.get(0);
		}else{
			return null;
		}
	}
	
	/**
	 * 按景点名称关键字查找所有景点
	 * @param sightName 景点名称关键字
	 * @return
	 */
	public List searchSightByName(String sightName){
		List list = null;
		try {
			String sql = "select * from tb_sight where sightName like '%"+ sightName +"%'";
			list = sess.query(sql, SightBean.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		if(list!=null && list.size()>0){
			return list;
		}else{
			return null;
		}
	}
	
	/**
	 * 根据景点ID数组查询景点,返回包含查询到的景点的list对象
	 * @param sightIDAry
	 * @return
	 */
	public List searchSightByIDAry(int[] sightIDAry){
		List list = null;
		//组装sql语句
		String sql = "select * from tb_sight where ";
		for(int i=0; i<sightIDAry.length; i++){
			sql += "sightID=" + sightIDAry[i] + " or ";
		}
		sql = sql.substring(0, sql.length()-4);
		
		try {
			list = sess.query(sql, SightBean.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		if(list != null && list.size() > 0){
			return list;
		}else{
			return null;
		}
	}

}

⌨️ 快捷键说明

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