酒店管理系统

酒店管理系统,第1张

概述常量类: public interface Constants { /*************定义连接SQLServer2008字符串常量******************/ String DRIVER_NAME = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; String URL = "jdbc:sqlserver://localho

常量类:

public interface Constants {	/*************定义连接sqlServer2008字符串常量******************/	String DRIVER_name = "com.microsoft.sqlserver.jdbc.sqlServerDriver";	String URL = "jdbc:sqlserver://localhost:1433;databasename=HOTELDB";	String USERname = "sa";	String PASSWORD = "123456";		/**********定义业务类型常量***********/				/**********定义Servlet中对象key值常量********/	String ROOMS = "rooms";	String PAGE_BEAN = "pageBean";	String ROOMTYPES = "roomTypes";	String ROOMINFO = "roomInfo";}

util工具

/** *  */package com.hotel.util;import java.sql.Connection;import java.sql.DriverManager;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.ResultSetMetaData;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;import com.hotel.constant.Constants;/** * 数据库连接通用类 * 连接数据库的步骤: * 1. 导入驱动包 * 2. 加载驱动 * 3. 通过驱动管理器类获取数据库连接 * 4. 通过连接对象创建预编译对象 * 5. 通过编译对象执行sql指令并处理返回结果 * 6. 关闭相关 *** 作对象 * */public class DBUtil {				/**	 * 定义获取连接对象的方法	 * 	 */	private static Connection getConn() {				// 定义连接对象句柄		Connection conn = null;				try {			// 加载驱动			Class.forname(Constants.DRIVER_name);			// 通过驱动管理器类获取数据库连接			conn = DriverManager.getConnection(Constants.URL, Constants.USERname, Constants.PASSWORD);		} catch (Exception e) {			e.printstacktrace();		}		return conn;	}		/**	 * 定义执行简单sql的增,删,改指令	 * @param sql 调用传入的sql指令	 * @param objects 执行sql指令需要的参数	 * @return int 返回方法 *** 作后受影响的行数	 */	public static int executeMyUpdate(String sql,Object... objects) {				// 定义接受受影响行数的变量		int row = 0;		// 定义连接对象句柄		Connection conn = null;		// 定义编译对象句柄		PreparedStatement pst = null;				// 通过调用本类中的获取连接对象		conn = getConn();				try {			// 通过连接对象创建编译对象			pst = conn.prepareStatement(sql);			// 设置sql命令所需的参数			if(objects != null) {				for(int i =0 ;i<objects.length;i++) {					pst.setobject(i+1, objects[i]);				}			}						// 执行sql指令并处理返回结果			row = pst.executeUpdate();		} catch (Exception e) {			e.printstacktrace();		} finally {			cloSEObjects(pst,conn);		}				// 返回受影响行数		return row;	}		/**	 * 定义执行简单查询语句的通用方法	 * @param sql 调用传入查询的SQL指令	 * @param objects 查询所需参数	 * @return List<Map<String,Object>> 返回查询构建集合对象	 */	public static List<Map<String,Object>> executequery(String sql,Object...objects) {		// 定义表集合对象		List<Map<String,Object>> table = new ArrayList<Map<String,Object>>();		// 定义连接对象句柄		Connection conn = null;		// 定义编译对象句柄		PreparedStatement pst = null;		// 定义结果集句柄		ResultSet rs = null;				// 通过调用本类中的获取连接对象		conn = getConn();				try {			// 通过连接对象创建预编译对象			pst = conn.prepareStatement(sql);			// 为查询编译对象设置参数			if(objects != null) {				for(int i=0;i<objects.length;i++) {					pst.setobject(i+1, objects[i]);				}			}			// 通过编译对象执行SQL命令			rs = pst.executequery();						// 判断结果是否为空			if(rs != null) {				// 把得到结果集转化为一张虚拟表				ResultSetMetaData rsd = rs.getMetaData();				// 得到查询表有多少个字段(列)				int count = rsd.getColumnCount();								// 得到当前遍历的行Map(key,value)				while(rs.next()) {					// 定义存储行的Map集合对象					Map<String,Object> row = new HashMap<String,Object>();					for(int i=0;i<count;i++) {						row.put(rsd.getColumnname(i+1), rs.getobject(rsd.getColumnname(i+1)));					}										// 把每次遍历的行存储到表集合中					table.add(row);				}			}		} catch (Exception e) {			e.printstacktrace();		} finally {			cloSEObjects(rs,pst,conn);		}				return table;	}		/**	 * 释放 *** 作对象的方法	 * @param objects 需要释放对象的列表	 */	private static voID cloSEObjects(Object...objects) {		if(objects != null) {			for(Object param : objects) {				try {					if(param instanceof ResultSet) {						((ResultSet)param).close();					}										if(param instanceof PreparedStatement) {						((PreparedStatement)param).close();					}										if(param instanceof Connection) {						Connection conn = ((Connection)param);						if(!conn.isClosed()) {							conn.close();							conn = null;						}					}				} catch (Exception e) {					e.printstacktrace();				}			}		}	}	}

分页对象:

package com.hotel.entity;import java.util.List;public class PageBean {	private int pageSize; // 每页显示数	private int totalRecords; // 总记录数	private int totalPages; // 总页数	private int currentPage;// 当前页数	private List<?> List; // 存储当前页中所有的记录数	/**	 * @return the pageSize	 */	public int getPageSize() {		return pageSize;	}	/**	 * @param pageSize the pageSize to set	 */	public voID setPageSize(int pageSize) {		this.pageSize = pageSize;	}	/**	 * @return the totalRecords	 */	public int getTotalRecords() {		return totalRecords;	}	/**	 * @param totalRecords the totalRecords to set	 */	public voID setTotalRecords(int totalRecords) {		this.totalRecords = totalRecords;	}	/**	 * @return the totalPages	 */	public int getTotalPages() {		return totalPages;	}	/**	 * @param totalPages the totalPages to set	 */	public voID setTotalPages(int totalPages) {		this.totalPages = totalPages;	}	/**	 * @return the currentPage	 */	public int getCurrentPage() {		return currentPage;	}	/**	 * @param currentPage the currentPage to set	 */	public voID setCurrentPage(int currentPage) {		this.currentPage = currentPage;	}	/**	 * @return the List	 */	public List<?> getList() {		return List;	}	/**	 * @param List the List to set	 */	public voID setList(List<?> List) {		this.List = List;	}}

 房间信息实体类:

package com.hotel.entity;/** * 房间信息实体类 * @author administrator * */public class RoomInfo {	private String roomID="";	private String roomeType="";	private String roomPositon;	private String roomDescrip;	private String roomStatus="";	private String typename;	/**	 * @return the typename	 */	public String getTypename() {		return typename;	}	/**	 * @param typename the typename to set	 */	public voID setTypename(String typename) {		this.typename = typename;	}	/**	 * @return the roomID	 */	public String getRoomID() {		return roomID;	}	/**	 * @param roomID the roomID to set	 */	public voID setRoomID(String roomID) {		this.roomID = roomID;	}	/**	 * @return the roomeType	 */	public String getRoomeType() {		return roomeType;	}	/**	 * @param roomeType the roomeType to set	 */	public voID setRoomeType(String roomeType) {		this.roomeType = roomeType;	}	/**	 * @return the roomPositon	 */	public String getRoomPositon() {		return roomPositon;	}	/**	 * @param roomPositon the roomPositon to set	 */	public voID setRoomPositon(String roomPositon) {		this.roomPositon = roomPositon;	}	/**	 * @return the roomDescrip	 */	public String getRoomDescrip() {		return roomDescrip;	}	/**	 * @param roomDescrip the roomDescrip to set	 */	public voID setRoomDescrip(String roomDescrip) {		this.roomDescrip = roomDescrip;	}	/**	 * @return the roomStatus	 */	public String getRoomStatus() {		return roomStatus;	}	/**	 * @param roomStatus the roomStatus to set	 */	public voID setRoomStatus(String roomStatus) {		this.roomStatus = roomStatus;	}}

房间类型实体:

/** * 房间类型实体类 * @author administrator * */public class RoomType {	private String typeID;    private String typename;    private String area;    private String bednum;    private String price;    private String airCondition;	/**	 * @return the typeID	 */	public String getTypeID() {		return typeID;	}	/**	 * @param typeID the typeID to set	 */	public voID setTypeID(String typeID) {		this.typeID = typeID;	}	/**	 * @return the typename	 */	public String getTypename() {		return typename;	}	/**	 * @param typename the typename to set	 */	public voID setTypename(String typename) {		this.typename = typename;	}	/**	 * @return the area	 */	public String getArea() {		return area;	}	/**	 * @param area the area to set	 */	public voID setArea(String area) {		this.area = area;	}	/**	 * @return the bednum	 */	public String getBednum() {		return bednum;	}	/**	 * @param bednum the bednum to set	 */	public voID setBednum(String bednum) {		this.bednum = bednum;	}	/**	 * @return the price	 */	public String getPrice() {		return price;	}	/**	 * @param price the price to set	 */	public voID setPrice(String price) {		this.price = price;	}	/**	 * @return the airCondition	 */	public String getAirCondition() {		return airCondition;	}	/**	 * @param airCondition the airCondition to set	 */	public voID setAirCondition(String airCondition) {		this.airCondition = airCondition;	}}

com.hotel.dao.RoomInfoDao:

package com.hotel.dao;import java.util.ArrayList;import java.util.List;import java.util.Map;import com.hotel.entity.PageBean;import com.hotel.entity.RoomInfo;import com.hotel.util.DBUtil;public class RoomInfoDao {	/**	 * 查询所有的房间信息	 * @return 返回查询的房间信息	 */	public List<RoomInfo> getRoomInfos() {		// 定义存储ROomInfo对象的集合		List<RoomInfo> rooms = new ArrayList<RoomInfo>();		// 定义查询所有房间信息的SQL命令		String sql = "select * from roomInfo where 1=1";				List<Map<String,Object>> lst = DBUtil.executequery(sql);		if(lst!=null && lst.size()>0) {			for(Map<String,Object> map : lst) {				// 创建一个房间对象				RoomInfo room = new RoomInfo();				room.setRoomID(map.get("RoomID").toString());				room.setRoomDescrip(map.get("RoomDescrip").toString());				room.setRoomeType(map.get("RoomeType").toString());				room.setRoomPositon(map.get("RoomPositon").toString());				room.setRoomStatus(map.get("RoomStatus").toString());								// 把房间对象添加到房间集合对象中				rooms.add(room);			}		}				return rooms;	}		/**	 * 定义分页的查询方法	 * @param page 接收分页对象封装的条件	 * @return	 */	public List<RoomInfo> getRoomInfosByPaging(PageBean page,RoomInfo roomInfo) {		// 定义存储ROomInfo对象的集合		List<RoomInfo> rooms = new ArrayList<RoomInfo>();		// 定义查询所有房间信息的SQL命令		String sql = "select top (?) * from (select row_number() " +				"over(order by roomID) rowID,* from roomInfo where 1=1";		// 构建查询SQL命令		if(roomInfo != null) {			if(!"".equals(roomInfo.getRoomID())) {				sql+=" and roomID like '%"+roomInfo.getRoomID()+"%'";			} 						if(!"".equals(roomInfo.getRoomeType())) {				sql+=" and roomeType='"+roomInfo.getRoomeType()+"'";			}						if(!"".equals(roomInfo.getRoomStatus())) {				sql+=" and roomStatus='"+roomInfo.getRoomStatus()+"'";			}		}		sql+=") room where rowID>?*(?-1)";		// 构建一个参数列表数组		Object[] params = {				page.getPageSize(),page.getPageSize(),page.getCurrentPage()		};				List<Map<String,Object>> lst = DBUtil.executequery(sql,params);		if(lst!=null && lst.size()>0) {			for(Map<String,Object> map : lst) {				// 创建一个房间对象				RoomInfo room = new RoomInfo();				room.setRoomID(map.get("RoomID").toString());				room.setRoomDescrip(map.get("RoomDescrip").toString());				room.setRoomeType(map.get("RoomeType").toString());				room.setRoomPositon(map.get("RoomPositon").toString());				room.setRoomStatus(map.get("RoomStatus").toString());								// 把房间对象添加到房间集合对象中				rooms.add(room);			}		}				return rooms;	}		/**	 * 获取总的记录数	 */	public int getTotalRecords(RoomInfo roomInfo) {		// 定义查询总记录数的sql命令		String sql = "select count(*) as totalRecords from roomInfo where 1=1";		// 构建查询SQL命令		if(roomInfo != null) {			if(!"".equals(roomInfo.getRoomID())) {				sql+=" and roomID like '%"+roomInfo.getRoomID()+"%'";			} 						if(!"".equals(roomInfo.getRoomeType())) {				sql+=" and roomeType='"+roomInfo.getRoomeType()+"'";			}						if(!"".equals(roomInfo.getRoomStatus())) {				sql+=" and roomStatus='"+roomInfo.getRoomStatus()+"'";			}		}		List<Map<String,Object>> List = DBUtil.executequery(sql);				return List!=null && List.size()>0 ? 				Integer.parseInt(						List.get(0).get("totalRecords").toString()				):0;			}		/**	 * 根据房间编号删除房间信息	 */	public int deleteRoomInfoByID(RoomInfo room) {		int row = 0;		// 定义删除的sql命令		String sql = "delete from roomInfo where roomID=?";		row = DBUtil.executeMyUpdate(sql, room.getRoomID());				return row;	}		/**	 * 根据房间编号获取房间信息的方法	 */	public RoomInfo getRoomByID(RoomInfo room) {		RoomInfo roomInfo = null;		// 定义查询的SQL语句		String sql = "select * from roomInfo where roomID=?";		List<Map<String,room.getRoomID());		if(lst!=null && lst.size()>0) {			for(Map<String,Object> map : lst) {				// 创建一个房间对象				roomInfo = new RoomInfo();				roomInfo.setRoomID(map.get("RoomID").toString());				roomInfo.setRoomDescrip(map.get("RoomDescrip").toString());				roomInfo.setRoomeType(map.get("RoomeType").toString());				roomInfo.setRoomPositon(map.get("RoomPositon").toString());				roomInfo.setRoomStatus(map.get("RoomStatus").toString());			}		}		return roomInfo;	}		/**	 * 修改房间信息	 * @param room 已经更改的房间信息对象	 * @return 返回是否修改成功	 */	public int upadateRoomInfo(RoomInfo room) {		int row = 0;		// 定义修改的sql命令		String sql = "update roomInfo set " +				"roomeType=?,RoomDescrip=?," +				"RoomPositon=?,RoomStatus=? " +				"where RoomID=?";		// 构建参数列表		Object[] params = {				room.getRoomeType(),room.getRoomDescrip(),room.getRoomPositon(),room.getRoomStatus(),room.getRoomID()		};				// 调用通用数据访问层的 *** 作方法		row = DBUtil.executeMyUpdate(sql, params);				return row;	}	/**	 * 添加房间信息的方法	 * @param room	 * @return	 */	public int addRoomInfo(RoomInfo room) {		int row = 0;		// 定义添加的sql命令		String sql = "insert into RoomInfo values(?,?,?)";		// 构建参数列表		Object[] params = {				room.getRoomID(),room.getRoomeType(),room.getRoomStatus()		};				// 调用通用数据访问层的 *** 作方法		row = DBUtil.executeMyUpdate(sql, params);				return row;	}}

com.hotel.dao.RoomTypeDao:

package com.hotel.dao;import java.util.ArrayList;import java.util.List;import java.util.Map;import com.hotel.entity.RoomInfo;import com.hotel.entity.RoomType;import com.hotel.util.DBUtil;public class RoomTypeDao {	/**	 * 通过类型编号获取类型名称	 * @return	 */	public String getTypenameByID(RoomInfo room) {		// 定义查询sql命令		String sql = "select typename from roomType where typeID=?";		List<Map<String,Object>> List = DBUtil.executequery(sql, room.getRoomeType());				return List!=null && List.size()>0 ? List.get(0).get("typename").toString() : null;	}		/**	 * 定义查询所有房间类型信息的方法	 */	public List<RoomType> getTypes() {		List<RoomType> roomTypes = new ArrayList<RoomType>();		// 定义查询所有类型信息的sql命令		String sql = "select * from roomType";		List<Map<String,Object>> List = DBUtil.executequery(sql);		if(List != null && List.size()>0) {			for(Map<String,Object> map : List) {				RoomType type = new RoomType();				type.setTypeID(map.get("TypeID").toString());				type.setTypename(map.get("Typename").toString());								roomTypes.add(type);			}		}				return roomTypes;	}}

com.hotel.servlet.AddRoomInfoServlet:

package com.hotel.servlet;import java.io.IOException;import java.io.PrintWriter;import java.util.List;import javax.servlet.servletexception;import javax.servlet.http.httpServlet;import javax.servlet.http.httpServletRequest;import javax.servlet.http.httpServletResponse;import com.hotel.constant.Constants;import com.hotel.entity.RoomInfo;import com.hotel.entity.RoomType;import com.hotel.service.RoomInfoService;/** * Servlet implementation class AddRoomInfoServlet */public class AddRoomInfoServlet extends httpServlet {	private static final long serialVersionUID = 1L;           /**     * @see httpServlet#httpServlet()     */    public AddRoomInfoServlet() {        super();        // Todo auto-generated constructor stub    }	/**	 * @see httpServlet#doGet(httpServletRequest request, httpServletResponse response)	 */	protected voID doGet(httpServletRequest request, httpServletResponse response) throws servletexception, IOException {		doPost(request, response);	}	/**	 * @see httpServlet#doPost(httpServletRequest request, httpServletResponse response)	 */	protected voID doPost(httpServletRequest request, IOException {		// 设置编码格式		request.setCharacterEnCoding("UTF-8");		response.setCharacterEnCoding("UTF-8");		response.setContentType("text/HTML;charset=UTF-8");				String flag = request.getParameter("flag");		if("add".equals(flag)) {			init(request,response);		} else if("doAdd".equals(flag)) {			add(request,response);		}	}		//初始化添加页面的方法	private voID init(httpServletRequest request, IOException {		// 初始化房间类型列表		List<RoomType> types = new RoomInfoService().getTypes();		request.setAttribute(Constants.ROOMTYPES, types);				request.getRequestdispatcher("pages/roomInfo/addRoomInfo.Jsp").forward(request, response);	}		// 执行修改方法	private voID add(httpServletRequest request, httpServletResponse response)  throws servletexception, IOException {				PrintWriter out = response.getWriter();		// 获取要修改的数据		String roomID = request.getParameter("roomID");		String roomType = request.getParameter("roomType");		String roomposition = request.getParameter("roomposition");		String roomState = request.getParameter("roomState");		String roomDesc = request.getParameter("roomDesc");				// 把获取的数据封装到RoomInfo对象中		RoomInfo room = new RoomInfo();		room.setRoomDescrip(roomDesc);		room.setRoomeType(roomType);		room.setRoomID(roomID);		room.setRoomPositon(roomposition);		room.setRoomStatus(roomState);				// 调用修改房间信息的业务方法		int row = new RoomInfoService().addRoomInfo(room);				if(row>0) {			response.sendRedirect("init.Jsp");		} else {			out.print("<script>alert('添加失败');location.href='init.Jsp';</script>");		}				out.flush();		out.close();	}}

com.hotel.servlet.DeleteRoomInfoServelt:

package com.hotel.servlet;import java.io.IOException;import java.io.PrintWriter;import javax.servlet.servletexception;import javax.servlet.http.httpServlet;import javax.servlet.http.httpServletRequest;import javax.servlet.http.httpServletResponse;import com.hotel.entity.RoomInfo;import com.hotel.service.RoomInfoService;/** * Servlet implementation class DeleteRoomInfoServelt */public class DeleteRoomInfoServelt extends httpServlet {	private static final long serialVersionUID = 1L;           /**     * @see httpServlet#httpServlet()     */    public DeleteRoomInfoServelt() {        super();        // Todo auto-generated constructor stub    }	/**	 * @see httpServlet#doGet(httpServletRequest request, IOException {		request.setCharacterEnCoding("UTF-8");		response.setContentType("text/HTML;charset=UTF-8");		PrintWriter out = response.getWriter();				// 获取要删除的编号		String roomID = request.getParameter("roomID");		RoomInfo room = new RoomInfo();		room.setRoomID(roomID);		// 调用删除的业务方法		int row = new RoomInfoService().deleteRoomInfo(room);		if(row>0) {			response.sendRedirect("init.Jsp");		} else {			out.print("<script>alert('删除失败');location.href='init.Jsp';</script>");		}				out.flush();		out.close();	}}

com.hotel.servlet.queryRoomInfoServlet:

package com.hotel.servlet;import java.io.IOException;import java.util.List;import javax.servlet.servletexception;import javax.servlet.http.httpServlet;import javax.servlet.http.httpServletRequest;import javax.servlet.http.httpServletResponse;import com.hotel.constant.Constants;import com.hotel.entity.PageBean;import com.hotel.entity.RoomInfo;import com.hotel.entity.RoomType;import com.hotel.service.RoomInfoService;/** * Servlet implementation class queryRoomInfoServlet */public class queryRoomInfoServlet extends httpServlet {	private static final long serialVersionUID = 1L;       	// 根据是否存储检索创建RoomInfo对象	public static RoomInfo room = null;    /**     * @see httpServlet#httpServlet()     */    public queryRoomInfoServlet() {        super();        // Todo auto-generated constructor stub    }	/**	 * @see httpServlet#doGet(httpServletRequest request, IOException {		// 设置编格式		request.setCharacterEnCoding("UTF-8");		response.setContentType("text/HTML;charset=UTF-8");				// 获取当前页		String currentPage = request.getParameter("currentPage");				// 调用查询房间信息的业务方法,创建业务对象的实例		RoomInfoService service = new RoomInfoService();		//List<RoomInfo> rooms = service.getRoomInfos();		//request.setAttribute(Constants.ROOMS, rooms);				// 获取房间编号,房间类型,房间状态		String roomID = request.getParameter("roomID")==null?"":request.getParameter("roomID");		String roomType = request.getParameter("roomType")==null?"":request.getParameter("roomType");		String roomState = request.getParameter("roomState")==null?"":request.getParameter("roomState");		// 判断是否存储分页条件		if(!"".equals(roomID)|| (!"-1".equals(roomType) && !"".equals(roomType)) || (!"-1".equals(roomState) && !"".equals(roomState))) {			room = new RoomInfo();			if(!"".equals(roomID)) {				room.setRoomID(roomID);			}						if(!"-1".equals(roomType)) {				room.setRoomeType(roomType);			}						if(!"-1".equals(roomState)) {				room.setRoomStatus(roomState);			}		}		// 创建分页对象		PageBean page = new PageBean();		page.setPageSize(10);		page.setCurrentPage(Integer.parseInt(currentPage));			    PageBean pageBean = service.getRoomInfosByPaging(page,room);	    List<RoomType> types = service.getTypes();	    request.setAttribute(Constants.PAGE_BEAN, pageBean);	    request.setAttribute(Constants.ROOMTYPES, types);		request.getRequestdispatcher("pages/roomInfo/roomTypManager.Jsp?currentPage=1").forward(request, response);	}}package com.hotel.servlet;import java.io.IOException;import java.util.List;import javax.servlet.servletexception;import javax.servlet.http.httpServlet;import javax.servlet.http.httpServletRequest;import javax.servlet.http.httpServletResponse;import com.hotel.constant.Constants;import com.hotel.entity.PageBean;import com.hotel.entity.RoomInfo;import com.hotel.entity.RoomType;import com.hotel.service.RoomInfoService;/** * Servlet implementation class queryRoomInfoServlet */public class queryRoomInfoServlet extends httpServlet {	private static final long serialVersionUID = 1L;       	// 根据是否存储检索创建RoomInfo对象	public static RoomInfo room = null;    /**     * @see httpServlet#httpServlet()     */    public queryRoomInfoServlet() {        super();        // Todo auto-generated constructor stub    }	/**	 * @see httpServlet#doGet(httpServletRequest request, response);	}}

com.hotel.servlet.UpdateServlet:

package com.hotel.servlet;import java.io.IOException;import java.io.PrintWriter;import java.util.List;import javax.servlet.servletexception;import javax.servlet.http.httpServlet;import javax.servlet.http.httpServletRequest;import javax.servlet.http.httpServletResponse;import com.hotel.constant.Constants;import com.hotel.entity.RoomInfo;import com.hotel.entity.RoomType;import com.hotel.service.RoomInfoService;/** * Servlet implementation class UpdateServlet */public class UpdateServlet extends httpServlet {	private static final long serialVersionUID = 1L;           /**     * @see httpServlet#httpServlet()     */    public UpdateServlet() {        super();        // Todo auto-generated constructor stub    }	/**	 * @see httpServlet#doGet(httpServletRequest request, IOException {		// 设置参数		request.setCharacterEnCoding("UTF-8");		response.setContentType("text/HTML;charset=UTF-8");		String flag = request.getParameter("flag");		if("init".equals(flag)) {			init(request,response);		} else if("update".equals(flag)) {			update(request, response);		}	}			//初始化修改页面的方法	private voID init(httpServletRequest request, IOException {		// 获取房间编号		String roomID = request.getParameter("roomID");		RoomInfo room = new RoomInfo();		room.setRoomID(roomID);		// 调用根据房间编号查询房间信息的业务方法		RoomInfo roomInfo = new RoomInfoService().getRoomByID(room);		request.setAttribute(Constants.ROOMINFO, roomInfo);		// 初始化房间类型列表		List<RoomType> types = new RoomInfoService().getTypes();		request.setAttribute(Constants.ROOMTYPES, types);				request.getRequestdispatcher("pages/roomInfo/updateRoomInfo.Jsp").forward(request, response);	}		// 执行修改方法	private voID update(httpServletRequest request, IOException {		PrintWriter out = response.getWriter();		// 获取要修改的数据		String roomID = request.getParameter("roomID");		String roomType = request.getParameter("roomType");		String roomposition = request.getParameter("roomposition");		String roomState = request.getParameter("roomState");		String roomDesc = request.getParameter("roomDesc");				// 把获取的数据封装到RoomInfo对象中		RoomInfo room = new RoomInfo();		room.setRoomDescrip(roomDesc);		room.setRoomeType(roomType);		room.setRoomID(roomID);		room.setRoomPositon(roomposition);		room.setRoomStatus(roomState);				// 调用修改房间信息的业务方法		int row = new RoomInfoService().updateRoomInfo(room);				if(row>0) {			response.sendRedirect("init.Jsp");		} else {			out.print("<script>alert('修改失败');location.href='init.Jsp';</script>");		}				out.flush();		out.close();	}			}

com.hotel.service.RoomInfoService:

package com.hotel.service;import java.util.ArrayList;import java.util.List;import com.hotel.dao.RoomInfoDao;import com.hotel.dao.RoomTypeDao;import com.hotel.entity.PageBean;import com.hotel.entity.RoomInfo;import com.hotel.entity.RoomType;public class RoomInfoService {		// 创建RoomInfoDao对象实例	private RoomInfoDao roomDao = new RoomInfoDao();	// 创建RoomTypeDao对象实例	private RoomTypeDao typeDao = new RoomTypeDao();		/**	 * 查询所有房间信息的业务方法	 */		public List<RoomInfo> getRoomInfos() {		// 创建存储带有类型名称的房间信息集合对象		List<RoomInfo> rooms = new ArrayList<RoomInfo>();		List<RoomInfo> roomInfos = roomDao.getRoomInfos();		System.out.println(roomInfos);		for(RoomInfo room : roomInfos) {			String typename = typeDao.getTypenameByID(room);			room.setTypename(typename);						// 把处理好的房间信息对象填充到rooms集合中			rooms.add(room);		}						return rooms;	}		/**	 * 获取所有类型信息的业务方法	 * @return	 */	public List<RoomType> getTypes() {		return typeDao.getTypes();	}		/**	 * 分页查询房间信息的方法	 * @param page	 * @return	 */	public PageBean getRoomInfosByPaging(PageBean page,RoomInfo roomInfo) {				// 设置分页对象的总记录数		int totalRecords = roomDao.getTotalRecords(roomInfo);		// 计算中页数[如果不能被整除总页数加1]		int totalPages = totalRecords%page.getPageSize()==0 ? 				totalRecords/page.getPageSize(): totalRecords/page.getPageSize()+1;						int currentPage = page.getCurrentPage();		// 创建分页对象实例		PageBean pageBean = new PageBean();		pageBean.setPageSize(page.getPageSize());		pageBean.setCurrentPage(currentPage);		pageBean.setTotalPages(totalPages);		pageBean.setTotalRecords(totalRecords);		// 获取当前页分页集合[把集合中房间类型编号转化为类型名称]		List<RoomInfo> roomInfos = roomDao.getRoomInfosByPaging(pageBean,roomInfo);		// 创建存储带有类型名称的房间信息集合对象		List<RoomInfo> rooms = new ArrayList<RoomInfo>();		for(RoomInfo room  : roomInfos) {			String typename = typeDao.getTypenameByID(room);			room.setTypename(typename);			rooms.add(room);		}		pageBean.setList(rooms);				return pageBean;	}		/**	 * 删除房间信息的业务方法	 * @param room	 * @return	 */	public int deleteRoomInfo(RoomInfo room) {		return roomDao.deleteRoomInfoByID(room);	}		/**	 * 根据房间信息编号获取房间信息的业务方法	 * @param room 房间对象	 * @return 返回房间信息对象	 */	public RoomInfo getRoomByID(RoomInfo room) {		return roomDao.getRoomByID(room);	}		/**	 * 修改房间信息的业务方法	 * @param room	 * @return	 */	public int updateRoomInfo(RoomInfo room) {		return roomDao.upadateRoomInfo(room);	}		/**	 * 添加房间信息的业务方法	 * @param room	 * @return	 */	public int addRoomInfo(RoomInfo room) {		return roomDao.addRoomInfo(room);	}}

/HOTELMANAGER/WebContent/init.Jsp(初始化界面)

<%@page import="com.hotel.servlet.queryRoomInfoServlet"%><%@ page language="java" ContentType="text/HTML; charset=UTF-8"    pageEnCoding="UTF-8"%><%    queryRoomInfoServlet.room = null;	response.sendRedirect("queryRoomInfoServlet?currentPage=1");%>

/HOTELMANAGER/WebContent/pages/roomInfo/addRoomInfo.Jsp:

<%@page import="com.hotel.entity.RoomType"%><%@page import="java.util.List"%><%@ page language="java" ContentType="text/HTML; charset=UTF-8"    pageEnCoding="UTF-8"%><!DOCTYPE HTML PUBliC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/HTML4/loose.dtd"><HTML><head><Meta http-equiv="Content-Type" content="text/HTML; charset=UTF-8"><Title>Insert Title here</Title></head><body>	<fIEldset >		<legend>房间信息添加</legend>		<form action="addRoomInfoServlet?flag=doAdd" method="post">			<table wIDth="100%">				<tr>					<td>房间编号:</td>					<td>						<input type="text" name="roomID" />					</td>				</tr>				<tr>					<td>房间类型:</td>					<td>						<select name="roomType">							<option value="-1">==请选择==</option>							<%								List<RoomType> types = (List<RoomType>)request.getAttribute("roomTypes");								if(types!=null) {									for(RoomType type : types) {							%>							<option value="<%=type.getTypeID() %>"><%=type.getTypename() %></option>							<% }							}%>						</select>					</td>				</tr>				<tr>					<td>房间位置:</td>					<td><input name="roomposition" /></td>				</tr>				<tr>					<td>房间状态:</td>					<td>						<select name="roomState">							<option value="-1">==请选择==</option>							<option value="入住">入住</option>							<option value="空闲">空闲</option>						</select>					</td>				</tr>				<tr>					<td>房间描述</td>					<td><textarea name="roomDesc" cols="50" rows="5"></textarea></td>				</tr>				<tr>					<td colspan="2" align="center">						<input type="submit"  value="添加" />					</td>				</tr>			</table>		</form>	</fIEldset></body></HTML>

/HOTELMANAGER/WebContent/pages/roomInfo/roomTypManager.Jsp:

<%@page import="com.hotel.entity.RoomType"%><%@page import="com.hotel.entity.PageBean"%><%@page import="com.hotel.entity.RoomInfo"%><%@page import="java.util.List"%><%@ page language="java" ContentType="text/HTML; charset=UTF-8"    pageEnCoding="UTF-8"%><!DOCTYPE HTML PUBliC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/HTML4/loose.dtd"><HTML><head><Meta http-equiv="Content-Type" content="text/HTML; charset=UTF-8"><Title> *** 作房间信息</Title><style type="text/CSS">	* {		margin: 0px;		padding: 0px;		text-decoration: none;	}</style></head><body>	<fIEldset >		<legend>房间信息检索</legend>		<form action="queryRoomInfoServlet?currentPage=1" method="post">			<div >				房间编号:<input type="text"  name="roomID" />				房间类型:				<select name="roomType">					<option value="-1">==请选择==</option>					<%						List<RoomType> types = (List<RoomType>)request.getAttribute("roomTypes");						if(types!=null) {							for(RoomType type : types) {					%>					<option value="<%=type.getTypeID() %>"><%=type.getTypename() %></option>					<% }						}%>				</select>				房间状态:				<select name="roomState">					<option value="-1">==请选择==</option>					<option value="入住">入住</option>					<option value="空闲">空闲</option>				</select>				<input type="submit" value="检索" />				<input type="button" onclick="location.href='init.Jsp'" value="查询所有" />			</div>		</form>	</fIEldset>	<fIEldset >		<legend>房间信息列表</legend>		<table  border="1" wIDth="100%" cellpadding="0" cellspacing="0">			<tr>				<th>房间编号</th>				<th>房间类型</th>				<th>房间位置</th>				<th>房间描述</th>				<th>房间状态</th>				<th>编辑</th>			</tr>			<%				// 获取得到房间信息集合对象				PageBean pageBean = (PageBean)request.getAttribute("pageBean");				if(pageBean != null) {					for(RoomInfo room : (List<RoomInfo>)pageBean.getList()) {			%>			<tr>				<td><%=room.getRoomID() %></td>				<td><%=room.getTypename() %></td>				<td><%=room.getRoomPositon() %></td>				<td><%=room.getRoomDescrip() %></td>				<td><%=room.getRoomStatus() %></td>				<td>					<a href="updateServlet?roomID=<%=room.getRoomID() %>&flag=init">修改</a>|					<a href="deleteRoomInfoServelt?roomID=<%=room.getRoomID() %>">删除</a>				</td>			</tr>			<%					}				}			%>			<tr>				<td colspan="6"><a href="addRoomInfoServlet?flag=add">添加房间信息</a></td>			</tr>		</table>	</fIEldset>	<div >		<a href="queryRoomInfoServlet?currentPage=1">首页</a>		<a href="queryRoomInfoServlet?currentPage=<%=pageBean.getCurrentPage()-1<1? 1 : pageBean.getCurrentPage()-1 %>">上一页</a>		<a href="queryRoomInfoServlet?currentPage=<%=pageBean.getCurrentPage()+1>pageBean.getTotalPages()?pageBean.getTotalPages():pageBean.getCurrentPage()+1 %>">下一页</a>		<a href="queryRoomInfoServlet?currentPage=<%=pageBean.getTotalPages() %>">尾页</a>		<span>			总记录数:<%=pageBean.getTotalRecords() %>条			当前第<%=pageBean.getCurrentPage() %>页			总页数:<%=pageBean.getTotalPages() %>页		</span>	</div></body></HTML>

/HOTELMANAGER/WebContent/pages/roomInfo/updateRoomInfo.Jsp:

<%@page import="com.hotel.entity.RoomInfo"%><%@page import="com.hotel.entity.RoomType"%><%@page import="java.util.List"%><%@ page language="java" ContentType="text/HTML; charset=UTF-8"    pageEnCoding="UTF-8"%><!DOCTYPE HTML PUBliC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/HTML4/loose.dtd"><HTML><head><Meta http-equiv="Content-Type" content="text/HTML; charset=UTF-8"><Title>Insert Title here</Title></head><%	// 获取修改的房间信息对象	RoomInfo room = (RoomInfo)request.getAttribute("roomInfo");	if(room !=null) {%><body>	<fIEldset >		<legend>房间信息修改</legend>		<form action="updateServlet?flag=update" method="post">			<table wIDth="100%">				<tr>					<td>房间编号:</td>					<td>						<%=room.getRoomID() %>						<input type="hIDden" value="<%=room.getRoomID() %>" name="roomID" />					</td>				</tr>				<tr>					<td>房间类型:</td>					<td>						<select name="roomType">							<option value="-1">==请选择==</option>							<%								List<RoomType> types = (List<RoomType>)request.getAttribute("roomTypes");								if(types!=null) {									for(RoomType type : types) {							%>							<option <%=room.getRoomeType().equals(type.getTypeID())?"selected='selected'":"" %>  value="<%=type.getTypeID() %>"><%=type.getTypename() %></option>							<% }							}%>						</select>					</td>				</tr>				<tr>					<td>房间位置:</td>					<td><input name="roomposition" value="<%=room.getRoomPositon() %>" /></td>				</tr>				<tr>					<td>房间状态:</td>					<td>						<select name="roomState">							<option value="-1">==请选择==</option>							<option <%=room.getRoomStatus().equals("入住")?"selected='selected'":"" %> value="入住">入住</option>							<option <%=room.getRoomStatus().equals("空闲")?"selected='selected'":"" %> value="空闲">空闲</option>						</select>					</td>				</tr>				<tr>					<td>房间描述</td>					<td><textarea name="roomDesc" cols="50" rows="5"><%=room.getRoomDescrip() %></textarea></td>				</tr>				<tr>					<td colspan="2" align="center">						<input type="submit"  value="修改" />					</td>				</tr>			</table>		</form>	</fIEldset></body><% } %></HTML>
总结

以上是内存溢出为你收集整理的酒店管理系统全部内容,希望文章能够帮你解决酒店管理系统所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/1161509.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-01
下一篇 2022-06-01

发表评论

登录后才能评论

评论列表(0条)

保存