sightdao.java

来自「java+mapxtreme 开发校园房管系统」· Java 代码 · 共 93 行

JAVA
93
字号
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 + =
减小字号Ctrl + -
显示快捷键?