(免费分享)基于jsp,ssm酒店管理系统

news2024/11/16 3:50:12

开发工具:eclipse,mysql5.7

Tomcat8.0,jdk1.8

系统分用户前台和管理后台两部分

前台截图:

 

 

 

 

后台截图: 

 

 

 

 

package com.mypower.controller;

import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.mypower.po.UserInfo;
import com.mypower.service.UserInfoService;
import com.mypower.utils.ExportExcelUtil;
import com.mypower.utils.UserException;

//UserInfo管理控制层
@Controller
@RequestMapping("/UserInfo")
public class UserInfoController extends BaseController {

    /*业务层对象*/
    @Resource UserInfoService userInfoService;

	@InitBinder("userInfo")
	public void initBinderUserInfo(WebDataBinder binder) {
		binder.setFieldDefaultPrefix("userInfo.");
	}
	/*跳转到添加UserInfo视图*/
	@RequestMapping(value = "/add", method = RequestMethod.GET)
	public String add(Model model,HttpServletRequest request) throws Exception {
		model.addAttribute(new UserInfo());
		return "UserInfo_add";
	}

	/*客户端ajax方式提交添加用户信息*/
	@RequestMapping(value = "/add", method = RequestMethod.POST)
	public void add(@Validated UserInfo userInfo, BindingResult br,
			Model model, HttpServletRequest request,HttpServletResponse response) throws Exception {
		String message = "";
		boolean success = false;
		if (br.hasErrors()) {
			message = "输入信息不符合要求!";
			writeJsonResponse(response, success, message);
			return ;
		}
		if(userInfoService.getUserInfo(userInfo.getUser_name()) != null) {
			message = "用户名已经存在!";
			writeJsonResponse(response, success, message);
			return ;
		}
		try {
			userInfo.setUserPhoto(this.handlePhotoUpload(request, "userPhotoFile"));
		} catch(UserException ex) {
			message = "图片格式不正确!";
			writeJsonResponse(response, success, message);
			return ;
		}
        userInfoService.addUserInfo(userInfo);
        message = "用户添加成功!";
        success = true;
        writeJsonResponse(response, success, message);
	}
	/*ajax方式按照查询条件分页查询用户信息*/
	@RequestMapping(value = { "/list" }, method = {RequestMethod.GET,RequestMethod.POST})
	public void list(String user_name,String name,String birthDate,String cardNumber,String telephone,Integer page,Integer rows, Model model, HttpServletRequest request,HttpServletResponse response) throws Exception {
		if (page==null || page == 0) page = 1;
		if (user_name == null) user_name = "";
		if (name == null) name = "";
		if (birthDate == null) birthDate = "";
		if (cardNumber == null) cardNumber = "";
		if (telephone == null) telephone = "";
		if(rows != 0)userInfoService.setRows(rows);
		List<UserInfo> userInfoList = userInfoService.queryUserInfo(user_name, name, birthDate, cardNumber, telephone, page);
	    /*计算总的页数和总的记录数*/
	    userInfoService.queryTotalPageAndRecordNumber(user_name, name, birthDate, cardNumber, telephone);
	    /*获取到总的页码数目*/
	    int totalPage = userInfoService.getTotalPage();
	    /*当前查询条件下总记录数*/
	    int recordNumber = userInfoService.getRecordNumber();
        response.setContentType("text/json;charset=UTF-8");
		PrintWriter out = response.getWriter();
		//将要被返回到客户端的对象
		JSONObject jsonObj=new JSONObject();
		jsonObj.accumulate("total", recordNumber);
		JSONArray jsonArray = new JSONArray();
		for(UserInfo userInfo:userInfoList) {
			JSONObject jsonUserInfo = userInfo.getJsonObject();
			jsonArray.put(jsonUserInfo);
		}
		jsonObj.accumulate("rows", jsonArray);
		out.println(jsonObj.toString());
		out.flush();
		out.close();
	}

	/*ajax方式按照查询条件分页查询用户信息*/
	@RequestMapping(value = { "/listAll" }, method = {RequestMethod.GET,RequestMethod.POST})
	public void listAll(HttpServletResponse response) throws Exception {
		List<UserInfo> userInfoList = userInfoService.queryAllUserInfo();
        response.setContentType("text/json;charset=UTF-8"); 
		PrintWriter out = response.getWriter();
		JSONArray jsonArray = new JSONArray();
		for(UserInfo userInfo:userInfoList) {
			JSONObject jsonUserInfo = new JSONObject();
			jsonUserInfo.accumulate("user_name", userInfo.getUser_name());
			jsonUserInfo.accumulate("name", userInfo.getName());
			jsonArray.put(jsonUserInfo);
		}
		out.println(jsonArray.toString());
		out.flush();
		out.close();
	}

	/*前台按照查询条件分页查询用户信息*/
	@RequestMapping(value = { "/frontlist" }, method = {RequestMethod.GET,RequestMethod.POST})
	public String frontlist(String user_name,String name,String birthDate,String cardNumber,String telephone,Integer currentPage, Model model, HttpServletRequest request) throws Exception  {
		if (currentPage==null || currentPage == 0) currentPage = 1;
		if (user_name == null) user_name = "";
		if (name == null) name = "";
		if (birthDate == null) birthDate = "";
		if (cardNumber == null) cardNumber = "";
		if (telephone == null) telephone = "";
		List<UserInfo> userInfoList = userInfoService.queryUserInfo(user_name, name, birthDate, cardNumber, telephone, currentPage);
	    /*计算总的页数和总的记录数*/
	    userInfoService.queryTotalPageAndRecordNumber(user_name, name, birthDate, cardNumber, telephone);
	    /*获取到总的页码数目*/
	    int totalPage = userInfoService.getTotalPage();
	    /*当前查询条件下总记录数*/
	    int recordNumber = userInfoService.getRecordNumber();
	    request.setAttribute("userInfoList",  userInfoList);
	    request.setAttribute("totalPage", totalPage);
	    request.setAttribute("recordNumber", recordNumber);
	    request.setAttribute("currentPage", currentPage);
	    request.setAttribute("user_name", user_name);
	    request.setAttribute("name", name);
	    request.setAttribute("birthDate", birthDate);
	    request.setAttribute("cardNumber", cardNumber);
	    request.setAttribute("telephone", telephone);
		return "UserInfo/userInfo_frontquery_result"; 
	}

     /*前台查询UserInfo信息*/
	@RequestMapping(value="/{user_name}/frontshow",method=RequestMethod.GET)
	public String frontshow(@PathVariable String user_name,Model model,HttpServletRequest request) throws Exception {
		/*根据主键user_name获取UserInfo对象*/
        UserInfo userInfo = userInfoService.getUserInfo(user_name);

        request.setAttribute("userInfo",  userInfo);
        return "UserInfo/userInfo_frontshow";
	}

	/*ajax方式显示用户修改jsp视图页*/
	@RequestMapping(value="/{user_name}/update",method=RequestMethod.GET)
	public void update(@PathVariable String user_name,Model model,HttpServletRequest request,HttpServletResponse response) throws Exception {
        /*根据主键user_name获取UserInfo对象*/
        UserInfo userInfo = userInfoService.getUserInfo(user_name);

        response.setContentType("text/json;charset=UTF-8");
        PrintWriter out = response.getWriter();
		//将要被返回到客户端的对象 
		JSONObject jsonUserInfo = userInfo.getJsonObject();
		out.println(jsonUserInfo.toString());
		out.flush();
		out.close();
	}

	/*ajax方式更新用户信息*/
	@RequestMapping(value = "/{user_name}/update", method = RequestMethod.POST)
	public void update(@Validated UserInfo userInfo, BindingResult br,
			Model model, HttpServletRequest request,HttpServletResponse response) throws Exception {
		String message = "";
    	boolean success = false;
		if (br.hasErrors()) { 
			message = "输入的信息有错误!";
			writeJsonResponse(response, success, message);
			return;
		}
		String userPhotoFileName = this.handlePhotoUpload(request, "userPhotoFile");
		if(!userPhotoFileName.equals("upload/NoImage.jpg"))userInfo.setUserPhoto(userPhotoFileName); 


		try {
			userInfoService.updateUserInfo(userInfo);
			message = "用户更新成功!";
			success = true;
			writeJsonResponse(response, success, message);
		} catch (Exception e) {
			e.printStackTrace();
			message = "用户更新失败!";
			writeJsonResponse(response, success, message); 
		}
	}
    /*删除用户信息*/
	@RequestMapping(value="/{user_name}/delete",method=RequestMethod.GET)
	public String delete(@PathVariable String user_name,HttpServletRequest request) throws UnsupportedEncodingException {
		  try {
			  userInfoService.deleteUserInfo(user_name);
	            request.setAttribute("message", "用户删除成功!");
	            return "message";
	        } catch (Exception e) { 
	            e.printStackTrace();
	            request.setAttribute("error", "用户删除失败!");
				return "error";

	        }

	}

	/*ajax方式删除多条用户记录*/
	@RequestMapping(value="/deletes",method=RequestMethod.POST)
	public void delete(String user_names,HttpServletRequest request,HttpServletResponse response) throws IOException, JSONException {
		String message = "";
    	boolean success = false;
        try { 
        	int count = userInfoService.deleteUserInfos(user_names);
        	success = true;
        	message = count + "条记录删除成功";
        	writeJsonResponse(response, success, message);
        } catch (Exception e) { 
            //e.printStackTrace();
            message = "有记录存在外键约束,删除失败";
            writeJsonResponse(response, success, message);
        }
	}

	/*按照查询条件导出用户信息到Excel*/
	@RequestMapping(value = { "/OutToExcel" }, method = {RequestMethod.GET,RequestMethod.POST})
	public void OutToExcel(String user_name,String name,String birthDate,String cardNumber,String telephone, Model model, HttpServletRequest request,HttpServletResponse response) throws Exception {
        if(user_name == null) user_name = "";
        if(name == null) name = "";
        if(birthDate == null) birthDate = "";
        if(cardNumber == null) cardNumber = "";
        if(telephone == null) telephone = "";
        List<UserInfo> userInfoList = userInfoService.queryUserInfo(user_name,name,birthDate,cardNumber,telephone);
        ExportExcelUtil ex = new ExportExcelUtil();
        String _title = "UserInfo信息记录"; 
        String[] headers = { "用户名","姓名","性别","用户照片","出生日期","身份证号","联系电话","邮箱","注册时间"};
        List<String[]> dataset = new ArrayList<String[]>(); 
        for(int i=0;i<userInfoList.size();i++) {
        	UserInfo userInfo = userInfoList.get(i); 
        	dataset.add(new String[]{userInfo.getUser_name(),userInfo.getName(),userInfo.getGender(),userInfo.getUserPhoto(),userInfo.getBirthDate(),userInfo.getCardNumber(),userInfo.getTelephone(),userInfo.getEmail(),userInfo.getRegTime()});
        }
        /*
        OutputStream out = null;
		try {
			out = new FileOutputStream("C://output.xls");
			ex.exportExcel(title,headers, dataset, out);
		    out.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		*/
		OutputStream out = null;//创建一个输出流对象 
		try { 
			out = response.getOutputStream();//
			response.setHeader("Content-disposition","attachment; filename="+"UserInfo.xls");//filename是下载的xls的名,建议最好用英文 
			response.setContentType("application/msexcel;charset=UTF-8");//设置类型 
			response.setHeader("Pragma","No-cache");//设置头 
			response.setHeader("Cache-Control","no-cache");//设置头 
			response.setDateHeader("Expires", 0);//设置日期头  
			String rootPath = request.getSession().getServletContext().getRealPath("/");
			ex.exportExcel(rootPath,_title,headers, dataset, out);
			out.flush();
		} catch (IOException e) { 
			e.printStackTrace(); 
		}finally{
			try{
				if(out!=null){ 
					out.close(); 
				}
			}catch(IOException e){ 
				e.printStackTrace(); 
			} 
		}
    }
}

 

package com.mypower.controller;

import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.mypower.po.BookOrder;
import com.mypower.po.Room;
import com.mypower.po.RoomType;
import com.mypower.po.UserInfo;
import com.mypower.service.BookOrderService;
import com.mypower.service.RoomService;
import com.mypower.service.RoomTypeService;
import com.mypower.service.UserInfoService;
import com.mypower.utils.ExportExcelUtil;
import com.mypower.utils.UserException;

//BookOrder管理控制层
@Controller
@RequestMapping("/BookOrder")
public class BookOrderController extends BaseController {

    /*业务层对象*/
    @Resource BookOrderService bookOrderService;

    @Resource RoomService roomService;
    @Resource RoomTypeService roomTypeService;
    @Resource UserInfoService userInfoService;
    @InitBinder("roomObj")
    public void initBinderroomObj(WebDataBinder binder) {
        binder.setFieldDefaultPrefix("roomObj.");
    }
    @InitBinder("roomTypeObj")
    public void initBinderroomTypeObj(WebDataBinder binder) {
        binder.setFieldDefaultPrefix("roomTypeObj.");
    }
    @InitBinder("userObj")
    public void initBinderuserObj(WebDataBinder binder) {
        binder.setFieldDefaultPrefix("userObj.");
    }
    @InitBinder("bookOrder")
    public void initBinderBookOrder(WebDataBinder binder) {
        binder.setFieldDefaultPrefix("bookOrder.");
    }
    /*跳转到添加BookOrder视图*/
    @RequestMapping(value = "/add", method = RequestMethod.GET)
    public String add(Model model,HttpServletRequest request) throws Exception {
        model.addAttribute(new BookOrder());
        /*查询所有的Room信息*/
        List<Room> roomList = roomService.queryAllRoom();
        request.setAttribute("roomList", roomList);
        /*查询所有的RoomType信息*/
        List<RoomType> roomTypeList = roomTypeService.queryAllRoomType();
        request.setAttribute("roomTypeList", roomTypeList);
        /*查询所有的UserInfo信息*/
        List<UserInfo> userInfoList = userInfoService.queryAllUserInfo();
        request.setAttribute("userInfoList", userInfoList);
        return "BookOrder_add";
    }

    /*客户端ajax方式提交添加房间预订信息*/
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public void add(@Validated BookOrder bookOrder, BindingResult br,
            Model model, HttpServletRequest request,HttpServletResponse response) throws Exception {
        String message = "";
        boolean success = false;
        if (br.hasErrors()) {
            message = "输入信息不符合要求!";
            writeJsonResponse(response, success, message);
            return ;
        }
        bookOrderService.addBookOrder(bookOrder);
        message = "房间预订添加成功!";
        success = true;
        writeJsonResponse(response, success, message);
    }
    /*ajax方式按照查询条件分页查询房间预订信息*/
    @RequestMapping(value = { "/list" }, method = {RequestMethod.GET,RequestMethod.POST})
    public void list(@ModelAttribute("roomObj") Room roomObj,@ModelAttribute("roomTypeObj") RoomType roomTypeObj,@ModelAttribute("userObj") UserInfo userObj,String liveDate,String orderState,String orderTime,Integer page,Integer rows, Model model, HttpServletRequest request,HttpServletResponse response) throws Exception {
        if (page==null || page == 0) page = 1;
        if (liveDate == null) liveDate = "";
        if (orderState == null) orderState = "";
        if (orderTime == null) orderTime = "";
        if(rows != 0)bookOrderService.setRows(rows);
        List<BookOrder> bookOrderList = bookOrderService.queryBookOrder(roomObj, roomTypeObj, userObj, liveDate, orderState, orderTime, page);
        /*计算总的页数和总的记录数*/
        bookOrderService.queryTotalPageAndRecordNumber(roomObj, roomTypeObj, userObj, liveDate, orderState, orderTime);
        /*获取到总的页码数目*/
        int totalPage = bookOrderService.getTotalPage();
        /*当前查询条件下总记录数*/
        int recordNumber = bookOrderService.getRecordNumber();
        response.setContentType("text/json;charset=UTF-8");
        PrintWriter out = response.getWriter();
        //将要被返回到客户端的对象
        JSONObject jsonObj=new JSONObject();
        jsonObj.accumulate("total", recordNumber);
        JSONArray jsonArray = new JSONArray();
        for(BookOrder bookOrder:bookOrderList) {
            JSONObject jsonBookOrder = bookOrder.getJsonObject();
            jsonArray.put(jsonBookOrder);
        }
        jsonObj.accumulate("rows", jsonArray);
        out.println(jsonObj.toString());
        out.flush();
        out.close();
    }

    /*ajax方式按照查询条件分页查询房间预订信息*/
    @RequestMapping(value = { "/listAll" }, method = {RequestMethod.GET,RequestMethod.POST})
    public void listAll(HttpServletResponse response) throws Exception {
        List<BookOrder> bookOrderList = bookOrderService.queryAllBookOrder();
        response.setContentType("text/json;charset=UTF-8"); 
        PrintWriter out = response.getWriter();
        JSONArray jsonArray = new JSONArray();
        for(BookOrder bookOrder:bookOrderList) {
            JSONObject jsonBookOrder = new JSONObject();
            jsonBookOrder.accumulate("orderId", bookOrder.getOrderId());
            jsonArray.put(jsonBookOrder);
        }
        out.println(jsonArray.toString());
        out.flush();
        out.close();
    }

    /*前台按照查询条件分页查询房间预订信息*/
    @RequestMapping(value = { "/frontlist" }, method = {RequestMethod.GET,RequestMethod.POST})
    public String frontlist(@ModelAttribute("roomObj") Room roomObj,@ModelAttribute("roomTypeObj") RoomType roomTypeObj,@ModelAttribute("userObj") UserInfo userObj,String liveDate,String orderState,String orderTime,Integer currentPage, Model model, HttpServletRequest request) throws Exception  {
        if (currentPage==null || currentPage == 0) currentPage = 1;
        if (liveDate == null) liveDate = "";
        if (orderState == null) orderState = "";
        if (orderTime == null) orderTime = "";
        List<BookOrder> bookOrderList = bookOrderService.queryBookOrder(roomObj, roomTypeObj, userObj, liveDate, orderState, orderTime, currentPage);
        /*计算总的页数和总的记录数*/
        bookOrderService.queryTotalPageAndRecordNumber(roomObj, roomTypeObj, userObj, liveDate, orderState, orderTime);
        /*获取到总的页码数目*/
        int totalPage = bookOrderService.getTotalPage();
        /*当前查询条件下总记录数*/
        int recordNumber = bookOrderService.getRecordNumber();
        request.setAttribute("bookOrderList",  bookOrderList);
        request.setAttribute("totalPage", totalPage);
        request.setAttribute("recordNumber", recordNumber);
        request.setAttribute("currentPage", currentPage);
        request.setAttribute("roomObj", roomObj);
        request.setAttribute("roomTypeObj", roomTypeObj);
        request.setAttribute("userObj", userObj);
        request.setAttribute("liveDate", liveDate);
        request.setAttribute("orderState", orderState);
        request.setAttribute("orderTime", orderTime);
        List<Room> roomList = roomService.queryAllRoom();
        request.setAttribute("roomList", roomList);
        List<RoomType> roomTypeList = roomTypeService.queryAllRoomType();
        request.setAttribute("roomTypeList", roomTypeList);
        List<UserInfo> userInfoList = userInfoService.queryAllUserInfo();
        request.setAttribute("userInfoList", userInfoList);
        return "BookOrder/bookOrder_frontquery_result"; 
    }

     /*前台查询BookOrder信息*/
    @RequestMapping(value="/{orderId}/frontshow",method=RequestMethod.GET)
    public String frontshow(@PathVariable Integer orderId,Model model,HttpServletRequest request) throws Exception {
        /*根据主键orderId获取BookOrder对象*/
        BookOrder bookOrder = bookOrderService.getBookOrder(orderId);

        List<Room> roomList = roomService.queryAllRoom();
        request.setAttribute("roomList", roomList);
        List<RoomType> roomTypeList = roomTypeService.queryAllRoomType();
        request.setAttribute("roomTypeList", roomTypeList);
        List<UserInfo> userInfoList = userInfoService.queryAllUserInfo();
        request.setAttribute("userInfoList", userInfoList);
        request.setAttribute("bookOrder",  bookOrder);
        return "BookOrder/bookOrder_frontshow";
    }

    /*ajax方式显示房间预订修改jsp视图页*/
    @RequestMapping(value="/{orderId}/update",method=RequestMethod.GET)
    public void update(@PathVariable Integer orderId,Model model,HttpServletRequest request,HttpServletResponse response) throws Exception {
        /*根据主键orderId获取BookOrder对象*/
        BookOrder bookOrder = bookOrderService.getBookOrder(orderId);

        response.setContentType("text/json;charset=UTF-8");
        PrintWriter out = response.getWriter();
        //将要被返回到客户端的对象 
        JSONObject jsonBookOrder = bookOrder.getJsonObject();
        out.println(jsonBookOrder.toString());
        out.flush();
        out.close();
    }

    /*ajax方式更新房间预订信息*/
    @RequestMapping(value = "/{orderId}/update", method = RequestMethod.POST)
    public void update(@Validated BookOrder bookOrder, BindingResult br,
            Model model, HttpServletRequest request,HttpServletResponse response) throws Exception {
        String message = "";
        boolean success = false;
        if (br.hasErrors()) { 
            message = "输入的信息有错误!";
            writeJsonResponse(response, success, message);
            return;
        }
        try {
            bookOrderService.updateBookOrder(bookOrder);
            message = "房间预订更新成功!";
            success = true;
            writeJsonResponse(response, success, message);
        } catch (Exception e) {
            e.printStackTrace();
            message = "房间预订更新失败!";
            writeJsonResponse(response, success, message); 
        }
    }
    /*删除房间预订信息*/
    @RequestMapping(value="/{orderId}/delete",method=RequestMethod.GET)
    public String delete(@PathVariable Integer orderId,HttpServletRequest request) throws UnsupportedEncodingException {
          try {
              bookOrderService.deleteBookOrder(orderId);
                request.setAttribute("message", "房间预订删除成功!");
                return "message";
            } catch (Exception e) { 
                e.printStackTrace();
                request.setAttribute("error", "房间预订删除失败!");
                return "error";

            }

    }

    /*ajax方式删除多条房间预订记录*/
    @RequestMapping(value="/deletes",method=RequestMethod.POST)
    public void delete(String orderIds,HttpServletRequest request,HttpServletResponse response) throws IOException, JSONException {
        String message = "";
        boolean success = false;
        try { 
            int count = bookOrderService.deleteBookOrders(orderIds);
            success = true;
            message = count + "条记录删除成功";
            writeJsonResponse(response, success, message);
        } catch (Exception e) { 
            //e.printStackTrace();
            message = "有记录存在外键约束,删除失败";
            writeJsonResponse(response, success, message);
        }
    }

    /*按照查询条件导出房间预订信息到Excel*/
    @RequestMapping(value = { "/OutToExcel" }, method = {RequestMethod.GET,RequestMethod.POST})
    public void OutToExcel(@ModelAttribute("roomObj") Room roomObj,@ModelAttribute("roomTypeObj") RoomType roomTypeObj,@ModelAttribute("userObj") UserInfo userObj,String liveDate,String orderState,String orderTime, Model model, HttpServletRequest request,HttpServletResponse response) throws Exception {
        if(liveDate == null) liveDate = "";
        if(orderState == null) orderState = "";
        if(orderTime == null) orderTime = "";
        List<BookOrder> bookOrderList = bookOrderService.queryBookOrder(roomObj,roomTypeObj,userObj,liveDate,orderState,orderTime);
        ExportExcelUtil ex = new ExportExcelUtil();
        String _title = "BookOrder信息记录"; 
        String[] headers = { "订单id","预订房间","房间类型","预订人","入住日期","预订天数","总价","订单备注","订单状态","预订时间"};
        List<String[]> dataset = new ArrayList<String[]>(); 
        for(int i=0;i<bookOrderList.size();i++) {
            BookOrder bookOrder = bookOrderList.get(i); 
            dataset.add(new String[]{bookOrder.getOrderId() + "",bookOrder.getRoomObj().getRoomNo(),bookOrder.getRoomTypeObj().getRoomTypeName(),bookOrder.getUserObj().getName(),bookOrder.getLiveDate(),bookOrder.getDays() + "",bookOrder.getTotalMoney() + "",bookOrder.getOrderMemo(),bookOrder.getOrderState(),bookOrder.getOrderTime()});
        }
        /*
        OutputStream out = null;
        try {
            out = new FileOutputStream("C://output.xls");
            ex.exportExcel(title,headers, dataset, out);
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        */
        OutputStream out = null;//创建一个输出流对象 
        try { 
            out = response.getOutputStream();//
            response.setHeader("Content-disposition","attachment; filename="+"BookOrder.xls");//filename是下载的xls的名,建议最好用英文 
            response.setContentType("application/msexcel;charset=UTF-8");//设置类型 
            response.setHeader("Pragma","No-cache");//设置头 
            response.setHeader("Cache-Control","no-cache");//设置头 
            response.setDateHeader("Expires", 0);//设置日期头  
            String rootPath = request.getSession().getServletContext().getRealPath("/");
            ex.exportExcel(rootPath,_title,headers, dataset, out);
            out.flush();
        } catch (IOException e) { 
            e.printStackTrace(); 
        }finally{
            try{
                if(out!=null){ 
                    out.close(); 
                }
            }catch(IOException e){ 
                e.printStackTrace(); 
            } 
        }
    }
}
 

源码获取:关注底部gongzhonghao,021领取下载链接   

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/83336.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

行业如此内卷,品牌如何实现可持续招商增长?

文|螳螂观察&#xff08;TanglangFin&#xff09; 作者|陈小江 2019年&#xff0c;厦门的一位单亲妈妈&#xff0c;听了一堂课&#xff0c;驱车十几个小时抵达南京&#xff0c;就为找一个人。 找一个&#xff0c;能救企业的人。 由于股权融资对赌失败&#xff0c;这位原本坐…

【C初阶】第八篇——结构体

结构体的声明 什么是结构体 结构体的声明 结构成员的类型 结构体变量的定义和初始化 结构体成员的访问 结构体传参 结构体的声明 什么是结构体 结构体是一些值的集合,这些值称为成员变量.结构的每个成员可以是不同类型的变量. 结构体的声明 struct tag {member - list…

艾美捷人乳铁蛋白ELISA试剂盒预期用途注意事项

艾美捷Kamiya人乳铁蛋白ELISA试剂盒预期用途&#xff1a; 人乳铁蛋白ELISA是一种高度灵敏的双位点酶联免疫测定&#xff08;ELISA&#xff09;人类生物样品中乳铁蛋白的测定。仅供研究使用。不用于诊断程序。 引言 乳铁蛋白&#xff08;LF&#xff09;是一种具有抗菌活性的多…

Spring源码深度解析十六:@Aspect方式的AOP下篇 - createProxy

一、前言 文章目录&#xff1a;Spring源码深度解析&#xff1a;文章目录 我们上篇已经分析到了 Spring将已经找到所有适用于当前bean 的Advisor 集合。下面就要创建代理对象了&#xff0c;而代理对象的创建是从 AbstractAutoProxyCreator#createProxy()开始。下面我们就来看看…

微信小程序|基于小程序+C#制作一个聊天系统

此文主要基于小程序C#使用WebSocket制作一个聊天系统&#xff0c;基本实现小程序与服务端的聊天功能。用小程序自带的客服功能只能绑定微信且一对一沟通&#xff0c;接入市面上成熟的即时通讯预算又略显不足&#xff0c;干脆自己开发一个也能应对简单的业务场景。 实现流程1、服…

数据智仓功能介绍(二)

界面介绍 访问入口 具备权限的人员从系统管理后台进入界面&#xff0c;点击数据智仓&#xff0c;右侧是展示系统中已经配置的数据集。 数据集展示界面 如下图所示&#xff0c;系统中已经配置的数据集包含 数据集名称&#xff0c;修改人员&#xff0c;上次运行时间&#xff08…

matlab智能算法之遗传算法

智能算法之遗传算法智能算法之遗传算法1.背景2.算法3.案例3.1 案例求解二元函数的最大值智能算法之遗传算法 1.背景 2.算法 3.案例 3.1 案例求解二元函数的最大值 例1&#xff1a;计算二元函数f(x,y)20x2y2−10∗(cos(2πx)cos(2πy))f(x,y)20x^2y^2-10*(cos(2\pi x)cos(2…

[附源码]Node.js计算机毕业设计大学生健康系统Express

项目运行 环境配置&#xff1a; Node.js最新版 Vscode Mysql5.7 HBuilderXNavicat11Vue。 项目技术&#xff1a; Express框架 Node.js Vue 等等组成&#xff0c;B/S模式 Vscode管理前后端分离等等。 环境需要 1.运行环境&#xff1a;最好是Nodejs最新版&#xff0c;我…

Qt扫盲-QToolButton 理论总结

QToolButton 理论总结1. 概述2. 使用场景3. 外观样式4. 菜单用途1. 概述 ToolButton 是一种特殊按钮&#xff0c;用于快速访问 特定命令或选项。与普通PushButton 按钮常用显示内容不同&#xff0c;ToolButton 通常不显示文本标签&#xff0c;而是显示图标。当然&#xff0c;也…

Windows与Linux利用系统自带实现共享文件夹的功能

这里需要两台机器在同一局域网或者可互相ping通。系统以Windows11和Windows Subsystem for Linux&#xff08;Ubuntu22.04.1&#xff09;或国产Linux发行版的统信UOS&#xff08;版本号20&#xff09;为例&#xff0c;其他的版本系统也类似&#xff0c;非Linux虚拟机也测试过&a…

蚁群算法详解-解决TSP问题

文章目录前言一、蚁群算法是什么&#xff1f;算法步骤二、基本原理三、数学模型1、算法中的参数设置2、构建路径轮盘赌例子3、更新信息素浓度代码终止四、代码展示五、参数实际设定1.参数设定的准则2.蚂蚁数量3.信息素因子4.启发函数因子5.信息素挥发因子6. 最大迭代次数7. 组合…

Android 实现相机(Camera)预览

CameraX 是一个 Jetpack 库&#xff0c;旨在帮助您更轻松地开发相机应用。 对于新应用&#xff0c;我们建议从 CameraX 开始。它提供一致且易于使用的 API&#xff0c;适用于绝大多数 Android 设备&#xff0c;并向后兼容 Android 5.0&#xff08;API 级别 21&#xff09;。 Ca…

Python基础篇学习

本篇博文目录:一.Python基础语法1.Python基础知识2.了解Python的基础语法结构3.python基础知识二.数据类型1.数字2.字符串3.布尔4.空值&#xff1a;None5.列表6.元祖7.字典8.Bytes9.集合(Set)三:程序三大结构( 顺序结构&#xff0c;分支结构&#xff0c;循环结构)1.顺序结构2.分…

2022-我的秋招之旅

1. 自我介绍 ​ 版1&#xff1a;&#xff08;实习&#xff09; ​ 面试官好&#xff0c;我叫xx&#xff0c;来自xx&#xff0c;目前研究生xx&#xff0c;就读于xx&#xff0c;在研究生期间&#xff0c;担任的职务为xx&#xff0c;在校期间参加各种比赛&#xff0c;如xx等&…

MATLB|实时机会约束决策及其在电力系统中的应用

目录 一、概述 二、数学模型 2.1 机会约束决策的情景方法 2.2 带有测量的情景方法 三、 机会约束决策的一种快速方法 3.1 通过仿射变换进行近似调节 3.2 可行域的仿射变换 3.3 两阶段决策算法 四、算例——配电网 4.1 防止过电压的有功功率削减 4.2 数值模拟 4.3 运…

第二十章 多源最短路之Floyd算法的思路即实现(超强解析)

第二十章 多源最短路之Floyd算法的思路即实现一、什么是多源最短路二、Floyd算法1、算法思路2、算法模板&#xff08;1&#xff09;问题&#xff1a;&#xff08;2&#xff09;代码模板&#xff1a;&#xff08;3&#xff09;代码分析:一、什么是多源最短路 我们之前了解到的d…

远程Jenkins新增Mac电脑节点,你知道怎么操作么?

目录&#xff1a;导读 一&#xff0c;前言 二&#xff0c;Mac电脑准备 1&#xff0c;网络环境 2&#xff0c;设置允许远程登录 三&#xff0c;Jenkins新增节点 1&#xff0c;新建节点 2&#xff0c;配置节点 3&#xff0c;节点启动代理 四&#xff0c;写在最后 一&…

算法竞赛入门【码蹄集进阶塔335题】(MT2176-2200)

算法竞赛入门【码蹄集进阶塔335题】(MT2176-2200&#xff09; 文章目录算法竞赛入门【码蹄集进阶塔335题】(MT2176-2200&#xff09;前言为什么突然想学算法了&#xff1f;为什么选择码蹄集作为刷题软件&#xff1f;目录1. MT2176 围栏木桩2. MT2177 学习时间3. MT2178 最长子段…

【设计模式】观察者模式Observe(Java)

文章目录1. 观察者模式定义2. 类图3.Java实现3.1 定义主题Interface3.2 定义观察者Interface3.3 定义具体主题3.4 定义具体观察者3.5 定义测试主方法1. 观察者模式定义 观察者模式定义了对象之间的一对多依赖&#xff0c;这样以来&#xff0c;当一个对象改变状态时&#xff0c…

如何利用ArcGIS探究环境与生态因子对水体、土壤、大气污染物等?

如何利用ArcGIS实现电子地图可视化表达&#xff1f;如何利用ArcGIS分析空间数据&#xff1f;如何利用ArcGIS提升SCI论文的层次&#xff1f;制图是地理数据展现的直观形式&#xff0c;也是地理数据应用的必要基础 本文从ArcGIS的基本操作、ArcGIS 的空间数据分析及ArcGIS 的高级…