?? sightdao.java
字號(hào):
package com.oyc.mapxtreme.dao;
import java.util.List;
import com.oyc.mapxtreme.beans.SightBean;
import com.oyc.wakeup.Session;
/**
* 景點(diǎn)dao,操作數(shù)據(jù)庫(kù),查詢景點(diǎn)
* @author 三峽大學(xué)理學(xué)院 歐陽(yáng)超
*
*/
public class SightDAO {
/** 數(shù)據(jù)庫(kù)會(huì)話對(duì)象 **/
private Session sess=null;
/**
* 構(gòu)造器:根據(jù)數(shù)據(jù)庫(kù)會(huì)話來(lái)創(chuàng)建一個(gè)通訊錄管理器
* @param sess 數(shù)據(jù)庫(kù)會(huì)話對(duì)象
*/
public SightDAO(Session sess){
this.sess=sess;
}
/**
* 根據(jù)景點(diǎn)ID查找某個(gè)景點(diǎn)
* @param sightID 景點(diǎn)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;
}
}
/**
* 按景點(diǎn)名稱關(guān)鍵字查找所有景點(diǎn)
* @param sightName 景點(diǎn)名稱關(guān)鍵字
* @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;
}
}
/**
* 根據(jù)景點(diǎn)ID數(shù)組查詢景點(diǎn),返回包含查詢到的景點(diǎn)的list對(duì)象
* @param sightIDAry
* @return
*/
public List searchSightByIDAry(int[] sightIDAry){
List list = null;
//組裝sql語(yǔ)句
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;
}
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -