首页 前端知识 基于javaweb mysql的ssm maven民宿管理系统(java ssm jsp bootstrap jquery mysql)

基于javaweb mysql的ssm maven民宿管理系统(java ssm jsp bootstrap jquery mysql)

2024-05-03 18:05:38 前端知识 前端哥 810 962 我要收藏

基于javaweb+mysql的ssm+maven民宿管理系统(java+ssm+jsp+bootstrap+jquery+mysql)

私信源码获取及调试交流

运行环境

Java≥8、MySQL≥5.7、Tomcat≥8

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

基于javaweb的SSM+Maven民宿管理系统(java+ssm+jsp+bootstrap+jquery+mysql)

项目介绍

游客功能:用户注册、登录、登录权限拦截、按名称搜索房间、支付流程、查看订单信息和状态、评论预定过的房间,并自动修改订单状态、查看统计剩余房间数量,数量为0时不可预定 管理员功能:房间分类管理、房间管理、订单管理

高级功能:各种列表清单的导出和打印功能、订单组合条件查询

功能清单

游客功能

  • 用户注册、登录 + 登录权限拦截 + 按名称搜索房间 + 支付流程 + 查看订单信息和状态 + 评论预定过的房间,并自动修改订单状态

  • 查看统计剩余房间数量,数量为0时不可预定

管理员功能

房间分类管理 + 类型的删除、修改、查询(准备添加增添功能,即图片上传功能) + 类型所含属性的增删改查 + 房间分类图片上传 > 房间管理 + 房间增删改导印统 + 查询已上传房间的所有照片 + 房间的配套设施属性设置 + 房间价格(原价、活动价)、名称、描述等属性设置 + 房间存量统计 > 订单管理 + 订单信息修改、删除 + 订单组合条件查询

  • 筛选出超时未评论的订单

高级功能 + 各种列表清单的导出和打印功能

  • 订单组合条件查询

环境需要

1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。 2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA; 3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可 4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 5.是否Maven项目: 是;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目 6.数据库:MySql 5.7版本;

技术栈

  1. 后端:Spring SpringMVC MyBatis

  2. 前端:JSP+bootstrap+jQuery

使用说明

  1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 将项目中applicationContext.xml配置文件中的数据库配置改为自己的配置; 3. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven; 若为maven项目,导入成功后请执行maven clean;maven install命令,配置tomcat,然后运行;

  2. 运行项目,输入localhost:8080/ 登录

                    HSSFCell currentCell = currentRow.getCell(colNum);
                    if (currentCell.getCellType() == HSSFCell.CELL_TYPE_STRING) {
                        int length = currentCell.getStringCellValue() != null
                                ? currentCell.getStringCellValue().getBytes().length : 10;
                        if (columnWidth < length) {
                            columnWidth = length;
                        }
                    }
                }
            }
            if (colNum == 0) {
                sheet.setColumnWidth(colNum, (columnWidth - 2) * 256);
            } else {
                sheet.setColumnWidth(colNum, (columnWidth + 4) * 256);
            }
        }
        try {
            if (createDir(docsPath)) {
                OutputStream out = new FileOutputStream(filePath);
                workbook.write(out);
                out.close();
                download(filePath, response);// 执行下载  
                cleanFile(filePath);// 删除已完成下载的文件  
            }
        }  catch (FileNotFoundException e) {
            e.printStackTrace();
        }catch (IOException e) {
            e.printStackTrace();
        }
        return workbook;
    }

    /**
     * 导出下载,弹出下载框 
     * @param path  文件下载路径 
     * @param response
     */
    public static void download(String path, HttpServletResponse response) {
        try {
            // path是指欲下载的文件的路径。  
            File file = new File(path);
            // 取得文件名。  
            String filename = file.getName();
            // 以流的形式下载文件。  
            InputStream fis = new BufferedInputStream(new FileInputStream(path));
            byte[] buffer = new byte[fis.available()];
            fis.read(buffer);
            fis.close();
            // 清空response  
            response.reset();
            // 设置response的Header  
        for (int colNum = 0; colNum < headers.length; colNum++) {
            int columnWidth = sheet.getColumnWidth(colNum) / 256;
            for (int rowNum = 0; rowNum < sheet.getLastRowNum(); rowNum++) {
                HSSFRow currentRow;
                // 当前行未被使用过  
                if (sheet.getRow(rowNum) == null) {
                    currentRow = sheet.createRow(rowNum);
                } else {
                    currentRow = sheet.getRow(rowNum);
                }
                if (currentRow.getCell(colNum) != null) {
                    HSSFCell currentCell = currentRow.getCell(colNum);
                    if (currentCell.getCellType() == HSSFCell.CELL_TYPE_STRING) {
                        int length = currentCell.getStringCellValue() != null
                                ? currentCell.getStringCellValue().getBytes().length : 10;
                        if (columnWidth < length) {
                            columnWidth = length;
                        }
                    }
                }
            }
            if (colNum == 0) {
                sheet.setColumnWidth(colNum, (columnWidth - 2) * 256);
            } else {
                sheet.setColumnWidth(colNum, (columnWidth + 4) * 256);
            }
        }
        try {
            if (createDir(docsPath)) {
                OutputStream out = new FileOutputStream(filePath);
                workbook.write(out);
                out.close();
                download(filePath, response);// 执行下载  
                cleanFile(filePath);// 删除已完成下载的文件  
            }
        }  catch (FileNotFoundException e) {
            e.printStackTrace();
        }catch (IOException e) {
            e.printStackTrace();
        }
        return workbook;
    }
    }

    //提交编辑的属性名称
    @RequestMapping(value = "/admin_property_update",produces = "text/html;charset=UTF-8")
    @ResponseBody
    public ModelAndView admin_property_update(Property record){
        productService.updateProperty(record);
        List<Property> properties = productService.listProproty(record.getCid());
        mav.addObject("ps",properties);
        mav.setViewName("/admin/listProperty");
        return mav;
    }

    //删除属性名称
    @RequestMapping(value = "/admin_property_delete",produces = "text/html;charset=UTF-8")
    @ResponseBody
    public ModelAndView admin_property_delete(Integer id,HttpServletRequest request){
        try{
            productService.deleteProperty(id);
        }catch (Exception e){
            e.printStackTrace();
        }
        List<Property> properties = productService.listProproty((Integer)request.getSession().getAttribute("cid"));
        mav.addObject("ps",properties);
        mav.setViewName("/admin/listProperty");
        return mav;
    }

    //房间管理
    @RequestMapping(value = "/admin_product_list",produces = "text/html;charset=UTF-8")
    @ResponseBody
    public ModelAndView admin_product_list(Integer cid){
        return listProduct(cid);
    }

    //添加房间
    @RequestMapping(value = "/admin_product_add",produces = "text/html;charset=UTF-8")
    @ResponseBody
    public ModelAndView admin_product_add(Product product,HttpServletRequest request){
        productService.insert(product);
        List<Product> products = productService.listProducts(product.getCid());
        mav.addObject("ps",products);
        mav.addObject("c",categoryService.getCategory(product.getCid()));
     * @return  true 存在目录  false 不存在目录 
     */
    public static boolean createDir(String destDirName) {
        File dir = new File(destDirName);
        if (dir.exists()) {
            return true;
        }
        if (!destDirName.endsWith(File.separator)) {
            destDirName = destDirName + File.separator;
        }
        // 创建目录  
        if (dir.mkdirs()) {
            System.out.println("创建目录" + destDirName + "成功!");
            return true;
        } else {
            System.out.println("创建目录" + destDirName + "失败!");
            return false;
        }
    }
}  

@Controller
@RequestMapping("")
public class GeneralController {
    private static Logger logger = Logger.getLogger(OrderController.class);
    private ModelAndView modelAndView = new ModelAndView();

    @Autowired
    UserService userService;
    @Autowired
    CategoryService categoryService;
    @Autowired
    OrderItemService orderItemService;
    @Autowired
    OrderService orderService;
    @Autowired
    ProductService productService;
    //导出用户信息
    @RequestMapping(value = "/admin_export_user_list",produces = "text/html;charset=UTF-8")
    @ResponseBody
    public void exportUserList(HttpServletRequest request, HttpServletResponse response) throws Exception{
        List<User> users = userService.listAll();
        String []rowsName = new String[]{"id","name","password"};
        List<Object[]> dataList = new ArrayList<Object[]>();
        for(int i = 0;i < users.size();i++){
            Object[] objs = new Object[rowsName.length];
            User user = users.get(i);
            objs[0] = user.getId();
            objs[1] = user.getName();
            objs[2] = user.getPassword();
            dataList.add(objs);
        }
        String fileName = "exportUserExcel";
        //执行导出
        ExportExcel.exportExcel(request,response,fileName, rowsName, dataList, "yyyy-MM-dd HH:mm:ss");
    }

    //删除用户
    @RequestMapping(value = "/admin_user_delete",produces = "text/html;charset=UTF-8")
    @ResponseBody
    public ModelAndView admin_user_delete(Integer id, HttpServletRequest request){
        try{
            userService.deleteByPrimaryKey(id);
        }catch (Exception e){
            e.getMessage();
        }
        List<User> users = userService.listAll();
        mav.addObject("us",users);
        mav.setViewName("/admin/listUser");
        return mav;
    }

    //编辑用户信息页面
    @RequestMapping(value = "/admin_user_edit",produces = "text/html;charset=UTF-8")
    @ResponseBody
    public ModelAndView admin_user_edit(Integer id, HttpServletRequest request){
        User user = userService.getUser(id);
        mav.addObject("u",user);
        mav.setViewName("/admin/editUser");
        return mav;
    }

    //修改订单信息页面
    @RequestMapping(value = "/admin_order_edit",produces = "text/html;charset=UTF-8")
    @ResponseBody
    public ModelAndView admin_order_edit(Integer id, HttpServletRequest request){
        Order order = orderService.getOrder(id);
        request.getSession().setAttribute("oid",id);
        mav.addObject("c",order);
        mav.setViewName("/admin/editOrder");
        return mav;
    }

    //条件查询订单
    @RequestMapping(value = "/select_order_list",produces = "text/html;charset=UTF-8")
    @ResponseBody
    public ModelAndView select_order_list(@RequestParam("status") String status, @RequestParam("min") Integer min, @RequestParam("max") Integer max){
        if(status==null || status.equals("")){
            status = "%";
        }
        if(min==null){
            min = -1;
        }
        if(max==null){
            max = Integer.MAX_VALUE;
        }
        List<Order> orders = orderService.selectOrder(status,min,max);
        for(Order order:orders){
            order.setOrderItems(orderItemService.getOrderItem(order.getId()));
        }
        mav.addObject("os",orders);
        mav.setViewName("/admin/listOrder");
        return mav;
    }

    //提交修改订单信息
    @RequestMapping(value = "/admin_order_update",produces = "text/html;charset=UTF-8")
    @ResponseBody
    public ModelAndView admin_order_update(Order order){
        Order oldOrder = orderService.getOrder(order.getId());
        oldOrder.setReceiver(order.getReceiver());
        oldOrder.setTotal(order.getTotal());
        oldOrder.setStatus(order.getStatus());
        orderService.update(oldOrder);
        mav = listOrder();
        mav.setViewName("/admin/listOrder");
        return mav;
    }

    //超时三天未评论的订单
    @RequestMapping(value = "/outdate_order",produces = "text/html;charset=UTF-8")
    @ResponseBody
    public ModelAndView outdate_order(){
    //删除房间
    @RequestMapping(value = "/admin_product_delete",produces = "text/html;charset=UTF-8")
    @ResponseBody
    public ModelAndView admin_product_delete(Integer id,Integer cid, HttpServletRequest request){
        productService.delete(id);
        return listProduct(cid);
    }

    //房间图片管理页面
    @RequestMapping(value = "/admin_productImage_list",produces = "text/html;charset=UTF-8")
    @ResponseBody
    public ModelAndView admin_productImage_list(Integer pid, HttpServletRequest request){
        Product product = productService.getProduct(pid);
        product.setCategory(categoryService.getCategory(product.getCid()));
        List<Productimage> productimages = productService.listProductImage(product.getId());
        mav.addObject("p",product);
        mav.addObject("pisSingle",productimages.stream().filter(e -> e.getType().equals("type_single")).collect(Collectors.toList()));
        mav.addObject("pisDetail",productimages.stream().filter(e -> e.getType().equals("type_detail")).collect(Collectors.toList()));
        mav.setViewName("/admin/listProductImage");
        return mav;
    }

    //删除房间图片
    @RequestMapping(value = "/admin_productImage_delete",produces = "text/html;charset=UTF-8")
    @ResponseBody
    public ModelAndView admin_productImage_delete(Integer id,Integer pid, HttpServletRequest request, HttpServletResponse response) throws Exception {
        try {
            productService.deleteProductImage(id);
        } catch (Exception e) {
            e.getMessage();
        }
        return admin_productImage_list(pid,request);
    }

    //添加房间图片
    @RequestMapping(value = "/admin_productImage_add",produces = "text/html;charset=UTF-8")
    @ResponseBody
    public ModelAndView admin_productImage_add(@RequestParam("filepath") MultipartFile filepath,@RequestParam("type") String type,@RequestParam("pid") int pid,HttpServletRequest request) throws IOException {
        Productimage productimage = new Productimage();
        productimage.setPid(pid);
        productimage.setType(type);
        Integer imageId = productService.insertImage(productimage);
        // Mac系统参考路径 注:此处必须为本地src及target下category的路径
        String path1 = "";
        String path2 = "";
    @ResponseBody
    public ModelAndView logIn(HttpServletRequest request, HttpServletResponse response,String name, String password) throws Exception{
        User user = userService.getUser(name);
        if(user != null && user.getPassword().equals(password)){
            //登陆成功
            request.getSession(true).setAttribute("user",user);
            logger.info(request.getPathInfo());
            return home(request);
        }
        return null;
    }

    /**
     * 退出登录
     * @param request
     * @param response
     * @throws Exception
     */
    @RequestMapping(value = "/forelogout",produces = "text/html;charset=UTF-8")
    @ResponseBody
    public void logOut(HttpServletRequest request, HttpServletResponse response) throws Exception{
        request.getSession().invalidate();
        response.sendRedirect("home.jsp");
    }

    @RequestMapping(value = "/foresearch",produces = "text/html;charset=UTF-8")
    @ResponseBody
    public ModelAndView search(HttpServletRequest request, HttpServletResponse response, String keyword) throws Exception{
        List<Product> ps = productService.listProducts(keyword);

        modelAndView.addObject("ps",ps);
        modelAndView.setViewName("/searchResult");
        return modelAndView;
    }

    @RequestMapping(value = "/foreproduct",produces = "text/html;charset=UTF-8")
    @ResponseBody
    public ModelAndView product(Integer pid) throws Exception{
        Product p = productService.getProduct(pid);
        List<Propertyvalue> pvs = productService.listProprotyValue(p.getId());
        List<Review> reviews = reviewService.listReview(p.getId());
        modelAndView.addObject("pvs",productService.getPropertyvalues(pvs));
        modelAndView.addObject("p", p);
        modelAndView.addObject("reviews",reviewService.getReviews(reviews));
        modelAndView.setViewName("/product");
        return modelAndView;
    }

    @RequestMapping(value = "/forecheckLogin", produces = "text/html;charset=UTF-8")
    @ResponseBody
        if(user != null)
            return 1;
        return 0;
    }

    /**
     * 预定房间按钮点击后的操作,此时便创建了order,订单状态:waitConfirm
     * @param request
     * @param orderitem
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/forebuyone",produces = "text/html;charset=UTF-8")
    @ResponseBody
    public  ModelAndView forebuyone(HttpServletRequest request, Orderitem orderitem) throws Exception{
        User user = (User) request.getSession().getAttribute("user");
        Map map =  orderItemService.buyOne(user, orderitem);
        request.getSession(true).setAttribute("order",map.get("order"));
        request.getSession(true).setAttribute("pid",orderitem.getPid());
        Product product = productService.getProduct(orderitem.getPid());
        product.setSaleCount(product.getSaleCount()+orderitem.getNumber());
        product.setStock(product.getStock()-orderitem.getNumber());
        productService.update(product);
        modelAndView.addObject("ois",map.get("ois"));
        modelAndView.addObject("total",((Order)map.get("order")).getTotal());
        modelAndView.setViewName("/buy");
        return modelAndView;
    }

    @RequestMapping(value = "/home",produces = "text/html;charset=UTF-8")
    @ResponseBody
    public ModelAndView home(HttpServletRequest request) throws  Exception{
        List<Category> c = categoryService.listTwoCategory();
        for(Category cs: c){
            cs.setProducts(productService.listProducts(cs.getId()));
        }
        modelAndView.addObject("cs",c);
        modelAndView.setViewName("home");
        return modelAndView;
    }

    /**
     * 创建订单;订单状态:waitPay
     * @param order
        List<Category> categories = categoryService.listAll();
        mav.addObject("thecs", categories);
        mav.setViewName("admin/printListCategory");
        return mav;
    }

    //导出分类EXCEL文件
    @RequestMapping(value = "/admin_export_category_list",produces = "text/html;charset=UTF-8")
    @ResponseBody
    public void exportListCategory(HttpServletRequest request, HttpServletResponse response) throws Exception{
        List<Category> categories = categoryService.listAll();
        String []rowsName = new String[]{"id","name"};
        List<Object[]> dataList = new ArrayList<Object[]>();
        for(int i = 0;i < categories.size();i++){
            Object[] objs = new Object[rowsName.length];
            Category category = categories.get(i);
            objs[0] = category.getId();
            System.out.println(objs[0]);
            objs[1] = category.getName();
            System.out.println(objs[1]);
            dataList.add(objs);
        }
        String fileName = "exportCategoriesExcel";
        //执行导出
        ExportExcel.exportExcel(request,response,fileName, rowsName, dataList, "yyyy-MM-dd HH:mm:ss");
    }

    //添加分类
    //特别注意,由于本操作涉及图片保存,更换运行环境时需要重新配置路径
    @RequestMapping(value = "/admin_category_add",produces = "text/html;charset=UTF-8")
    @ResponseBody
    public ModelAndView admin_category_add(@RequestParam("name") String name, @RequestParam("filepath") MultipartFile filepath) throws IOException {
        Category category = new Category();
        category.setName(name);
        Integer cid = categoryService.insert(category);
        // windows系统参考路径 注:此处必须为本地src及target下category的路径
        String path1 = imgPath+"src\\main\\webapp\\img\\category\\"+cid.toString()+".jpg";
        String path2 = imgPath+"target\\project-1.0-SNAPSHOT\\img\\category\\"+cid.toString()+".jpg";
        filepath.transferTo(new File(path1));
        FileUtils.copyFile(new File(path1),new File(path2));
        mav = listCategory();
        return mav;
    }
@RequestMapping("/order")
class OrderController {

    private static Logger logger = Logger.getLogger(OrderController.class);
    //获取所有订单
    @RequestMapping(value = "/list",produces = "text/html;charset=UTF-8")
    @ResponseBody
    public List<Order> listOrder(/* @RequestParam(value = "addressId") int addressId */) throws Exception{
        SqlSession sqlSession = MybatisSessionFactory.getSession();
        OrderMapper orderMapper = sqlSession.getMapper(OrderMapper.class);
        return orderMapper.selectAll();
    }

    @RequestMapping(value = "/deleteOne",produces = "text/html;charset=UTF-8")
    @ResponseBody
    public String deleteById(@RequestParam(value = "orderId") Integer orderId) throws Exception{
        SqlSession sqlSession = MybatisSessionFactory.getSession();
        OrderMapper orderMapper = sqlSession.getMapper(OrderMapper.class);
        try{
            orderMapper.deleteByPrimaryKey(orderId);
            return "删除成功";
        }catch (Exception e){
            e.printStackTrace();
            return e.getMessage();
        }
    }

    @RequestMapping(value = "/delete",produces = "text/html;charset=UTF-8")
    @ResponseBody
    public String deleteById(@RequestParam(value = "orderIds") List<Integer> orderIds) throws Exception{
        SqlSession sqlSession = MybatisSessionFactory.getSession();
        //使用mapper批量删除
        OrderMapper orderMapper = sqlSession.getMapper(OrderMapper.class);
        OrderExample orderExample = new OrderExample();
        OrderExample.Criteria criteria = orderExample.createCriteria();
        criteria.andIdIn(orderIds);
        try{
            orderMapper.deleteByExample(orderExample);
            return "删除成功";
        }catch (Exception e){
            e.printStackTrace();
        SqlSession sqlSession = MybatisSessionFactory.getSession();
        OrderMapper orderMapper = sqlSession.getMapper(OrderMapper.class);
        return orderMapper.selectAll();
    }

    @RequestMapping(value = "/deleteOne",produces = "text/html;charset=UTF-8")
    @ResponseBody
    public String deleteById(@RequestParam(value = "orderId") Integer orderId) throws Exception{
        SqlSession sqlSession = MybatisSessionFactory.getSession();
        OrderMapper orderMapper = sqlSession.getMapper(OrderMapper.class);
        try{
            orderMapper.deleteByPrimaryKey(orderId);
            return "删除成功";
        }catch (Exception e){
            e.printStackTrace();
            return e.getMessage();
        }
    }

    @RequestMapping(value = "/delete",produces = "text/html;charset=UTF-8")
    @ResponseBody
    public String deleteById(@RequestParam(value = "orderIds") List<Integer> orderIds) throws Exception{
        SqlSession sqlSession = MybatisSessionFactory.getSession();
        //使用mapper批量删除
        OrderMapper orderMapper = sqlSession.getMapper(OrderMapper.class);
        OrderExample orderExample = new OrderExample();
        OrderExample.Criteria criteria = orderExample.createCriteria();
        criteria.andIdIn(orderIds);
        try{
            orderMapper.deleteByExample(orderExample);
            return "删除成功";
        }catch (Exception e){
            e.printStackTrace();
            return e.getMessage();
        }
    }
}


@Controller
@RequestMapping("/admin")
public class AdminController {
    @Autowired
    private UserService userService;
    @Autowired
    private CategoryService categoryService;
    @Autowired
    private OrderItemService orderItemService;
    @Autowired
    private OrderService orderService;
    @Autowired
    private ProductService productService;

    private static Logger logger = Logger.getLogger(AdminController.class);
    private ModelAndView mav = new ModelAndView();

    // windows系统参考路径 注:此处必须为项目路径
    private static String imgPath = "C:\\Users\\51414\\Desktop\\ssm民宿管理系统\\project\\";

    private ModelAndView listProduct(Integer cid) {
        List<Product> products = productService.listProducts(cid);
        mav.addObject("ps",products);
        mav.addObject("c",categoryService.getCategory(cid));
        mav.setViewName("/admin/listProduct");
        return mav;
    }

    //查询所有房间分类
    @RequestMapping(value = "/admin_category_list",produces = "text/html;charset=UTF-8")
    @ResponseBody

@Controller
@RequestMapping("/user")
public class UserController {
    private static Logger logger = Logger.getLogger(OrderController.class);
    ModelAndView mav = new ModelAndView();
    @Autowired
    UserService userService;

    @RequestMapping(value = "/foreregister",produces = "text/html;charset=UTF-8")
    @ResponseBody
    public ModelAndView register(HttpServletRequest request, HttpServletResponse response,User user) throws Exception{
        GeneralController generalController = new GeneralController();
        try{
            userService.insert(user);
            request.getSession().setAttribute("user",user);
        }catch (Exception e){
            logger.info("用户名已存在");
            return generalController.home(request);
        }
        mav.setViewName("registerSuccess");
        return mav;
    }
}

        }
    }
}

@Controller
@RequestMapping("/user")
public class UserController {
    private static Logger logger = Logger.getLogger(OrderController.class);
    ModelAndView mav = new ModelAndView();
    @Autowired
    UserService userService;

    @RequestMapping(value = "/foreregister",produces = "text/html;charset=UTF-8")
    @ResponseBody
    public ModelAndView register(HttpServletRequest request, HttpServletResponse response,User user) throws Exception{
        GeneralController generalController = new GeneralController();
        try{
            userService.insert(user);
            request.getSession().setAttribute("user",user);
        }catch (Exception e){
            logger.info("用户名已存在");

    //查询所有房间分类
    @RequestMapping(value = "/admin_category_list",produces = "text/html;charset=UTF-8")
    @ResponseBody
    public ModelAndView listCategory(){
        List<Category> categories = categoryService.listAll();
        mav.addObject("thecs", categories);
        mav.setViewName("admin/listCategory");
        return mav;
    }

    //打印页面
    @RequestMapping(value = "/admin_print_category_list",produces = "text/html;charset=UTF-8")
    @ResponseBody
    public ModelAndView printListCategory(){
        List<Category> categories = categoryService.listAll();
        mav.addObject("thecs", categories);
        mav.setViewName("admin/printListCategory");
        return mav;
    }

    //导出分类EXCEL文件
    @RequestMapping(value = "/admin_export_category_list",produces = "text/html;charset=UTF-8")
    @ResponseBody
    public void exportListCategory(HttpServletRequest request, HttpServletResponse response) throws Exception{
        List<Category> categories = categoryService.listAll();
        String []rowsName = new String[]{"id","name"};
        List<Object[]> dataList = new ArrayList<Object[]>();
        for(int i = 0;i < categories.size();i++){
            Object[] objs = new Object[rowsName.length];
            Category category = categories.get(i);
            objs[0] = category.getId();
            System.out.println(objs[0]);
            objs[1] = category.getName();
            System.out.println(objs[1]);
            dataList.add(objs);
        }
        String fileName = "exportCategoriesExcel";
        //执行导出
        ExportExcel.exportExcel(request,response,fileName, rowsName, dataList, "yyyy-MM-dd HH:mm:ss");
    }

    //添加分类
    //特别注意,由于本操作涉及图片保存,更换运行环境时需要重新配置路径
    @RequestMapping(value = "/admin_category_add",produces = "text/html;charset=UTF-8")
    @ResponseBody
    public ModelAndView admin_category_add(@RequestParam("name") String name, @RequestParam("filepath") MultipartFile filepath) throws IOException {
        Category category = new Category();
        category.setName(name);
        Integer cid = categoryService.insert(category);
        // windows系统参考路径 注:此处必须为本地src及target下category的路径
            objs[1] = user.getName();
            objs[2] = user.getPassword();
            dataList.add(objs);
        }
        String fileName = "exportUserExcel";
        //执行导出
        ExportExcel.exportExcel(request,response,fileName, rowsName, dataList, "yyyy-MM-dd HH:mm:ss");
    }

    //删除用户
    @RequestMapping(value = "/admin_user_delete",produces = "text/html;charset=UTF-8")
    @ResponseBody
    public ModelAndView admin_user_delete(Integer id, HttpServletRequest request){
        try{
            userService.deleteByPrimaryKey(id);
        }catch (Exception e){
            e.getMessage();
        }
        List<User> users = userService.listAll();
        mav.addObject("us",users);
        mav.setViewName("/admin/listUser");
        return mav;
    }

    //编辑用户信息页面
    @RequestMapping(value = "/admin_user_edit",produces = "text/html;charset=UTF-8")
    @ResponseBody
    public ModelAndView admin_user_edit(Integer id, HttpServletRequest request){
        User user = userService.getUser(id);
        mav.addObject("u",user);
        mav.setViewName("/admin/editUser");
        return mav;
    }

    //提交更新用户信息
    @RequestMapping(value = "/admin_user_update",produces = "text/html;charset=UTF-8")
    @ResponseBody
    public ModelAndView admin_user_update(User user){
        //user = userService.getUser(user.getName());
        userService.update(user);
        List<User> users = userService.listAll();
        mav.addObject("us",users);
        mav.setViewName("/admin/listUser");
        return mav;
    }

    //添加用户
    @RequestMapping(value = "/admin_user_add",produces = "text/html;charset=UTF-8")
    @ResponseBody
    public ModelAndView admin_user_add(User user,HttpServletRequest request){
        userService.insert(user);
        List<User> users = userService.listAll();
        mav.addObject("us",users);
        mav.setViewName("/admin/listUser");
    }

    //导出订单列表
    @RequestMapping(value = "/admin_export_order_list",produces = "text/html;charset=UTF-8")
    @ResponseBody
    public void exportListOrder(HttpServletRequest request, HttpServletResponse response) throws Exception{
        List<Order> orders = orderService.listAll();
        String []rowsName = new String[]{"ID", "状态", "金额", "房间数量","买家名称","支付时间"};
        List<Object[]> dataList = new ArrayList<Object[]>();
        for(int i = 0;i < orders.size();i++){
            Object[] objs = new Object[rowsName.length];
            Order order = orders.get(i);
            objs[0] = order.getId();
            objs[1] = order.getStatus();
            objs[2] = order.getTotal();
            objs[3] = order.getTotalNumber();
            objs[4] = order.getUser().getName();
            objs[5] = order.getPayDate();
            dataList.add(objs);
        }
        String fileName = "exportOrderExcel";
        //执行导出
        ExportExcel.exportExcel(request,response,fileName, rowsName, dataList, "yyyy-MM-dd HH:mm:ss");
    }

    //查询所有属性
    @RequestMapping(value = "/admin_property_list",produces = "text/html;charset=UTF-8")
    @ResponseBody
    public ModelAndView listProperty(@RequestParam(value = "cid") Integer cid,HttpServletRequest request){
        request.getSession().setAttribute("cid",cid);
        List<Property> properties = productService.listProproty(cid);
        mav.addObject("ps",properties);
        mav.addObject("c",categoryService.getCategory(cid));
        mav.setViewName("/admin/listProperty");
        return mav;
    }

    //编辑属性名称页面
    @RequestMapping(value = "/admin_property_edit",produces = "text/html;charset=UTF-8")
    @ResponseBody
    public ModelAndView admin_property_edit(@RequestParam(value = "id") Integer id){
        Property property = productService.getProperty(id);
        mav.addObject("p",property);

请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述

转载请注明出处或者链接地址:https://www.qianduange.cn//article/6829.html
标签
maven
评论
发布的文章

JQuery中的load()、$

2024-05-10 08:05:15

大家推荐的文章
会员中心 联系我 留言建议 回顶部
复制成功!