28基于java的简单酒店数据管理

yizhihongxing

本文章介绍一个基于java的简单酒店数据管理系统

项目介绍

该项目适用于初学java后,需要一个小练手的java web项目,该项目是只有一个酒店数据表,然后实现对该酒店增加,修改,删除和分页查询的小案例,虽然项目不是很复杂,但麻雀虽小但五脏俱全,适合于个人学习适用。

项目使用的技术架构

后端:java+SpringBoot + MyBatis-Plus
数据库:MySQL
前端:Vue + Element-ui + Axios
开发工具:idea或eclipse
更多项目请查看:项目帮

项目实现

  • HotelController 定义了对酒店信息的CRUD的接口:
@RestController
@RequestMapping("hotel")
public class HotelController {

    @Autowired
    private IHotelService hotelService;

    /**
     * 通过id来查询酒店数据
     * @param id 酒店id号
     * @return
     */
    @GetMapping("/{id}")
    public Hotel queryById(@PathVariable("id") Long id){
        return hotelService.getById(id);
    }

    /**
     * 分页查询数据列表出来
     * @param page 页码
     * @param size 每页的大小
     * @return
     */
    @GetMapping("/list")
    public PageResult hotelList(
            @RequestParam(value = "page", defaultValue = "1") Integer page,
            @RequestParam(value = "size", defaultValue = "1") Integer size
    ){
        Page<Hotel> result = hotelService.page(new Page<>(page, size));
        return new PageResult(result.getTotal(), result.getRecords());
    }

    /**
     * 保存酒店信息
     * @param hotel 酒店信息实体类
     */
    @PostMapping
    public void saveHotel(@RequestBody Hotel hotel){
        hotelService.save(hotel);
    }

    /**
     * 更新酒店信息
     * @param hotel 酒店信息实体类
     */
    @PutMapping()
    public void updateById(@RequestBody Hotel hotel){
        if (hotel.getId() == null) {
            throw new InvalidParameterException("id不能为空");
        }
        hotelService.updateById(hotel);
    }

    /**
     * 通过酒店id删除酒店信息
     * @param id 酒店id号
     */
    @DeleteMapping("/{id}")
    public void deleteById(@PathVariable("id") Long id) {
        hotelService.removeById(id);
    }
}
  • 前端使用的vue
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>简单酒店管理</title>
  <link href="./css/main.css" rel="stylesheet">
</head>
<body>
<div id="app">
  <h1>简单酒店增删改查项目</h1>
  <div class="add-btn" >
    <el-button type="primary" size="small" @click="beginAdd">新增酒店</el-button>
  </div>
  <el-table :data="hotels" border height="500" style="width: 100%">
    <el-table-column align="center" fixed prop="id" label="酒店房间号" width="120"></el-table-column>
    <el-table-column align="center" prop="name" label="酒店名称" width="120"></el-table-column>
    <el-table-column align="center" prop="address" label="酒店地址" width="120"></el-table-column>
    <el-table-column align="center" prop="name" label="酒店名称" width="120"></el-table-column>
    <el-table-column align="center" label="酒店图片" width="200">
      <template slot-scope="scope">
        <img :src="scope.row.pic" height="200" width="200" />
      </template>
    </el-table-column>
    <el-table-column align="center" prop="price" label="酒店价格" width="100"></el-table-column>
    <el-table-column align="center" label="酒店评分" width="200">
      <template slot-scope="scope">
        <el-rate
          v-model="scope.row.score / 10" disabled show-score text-color="#ff9900" score-template="{value}">
        </el-rate>
      </template>
    </el-table-column>
    <el-table-column align="center" prop="brand" label="酒店品牌" width="120"></el-table-column>
    <el-table-column align="center" prop="city" label="所在城市" width="120"></el-table-column>
    <el-table-column align="center" prop="starName" label="酒店星级" width="60"></el-table-column>
    <el-table-column align="center" prop="business" label="所在商圈" width="120"></el-table-column>
    <el-table-column align="center" label="操作" fixed="right" :width="150">
      <template slot-scope="scope">
        <el-button type="primary" plain icon="el-icon-edit" circle
                   @click="handleEdit(scope.$index, scope.row)"></el-button>
        <el-button type="danger" plain icon="el-icon-delete" circle
                   @click="handleDelete(scope.$index, scope.row)"></el-button>
      </template>
    </el-table-column>
  </el-table>
  <el-pagination
      @current-change="query"
      style="margin-top: 5px"
      background
      :page-size="5"
      layout="prev, pager, next"
      :total="total">
  </el-pagination>
  <el-dialog title="酒店信息" :visible.sync="formVisible" width="50%" style="padding: 0 20px;">
    <el-form :model="hotel" size="small" label-position="left" :label-width="formLabelWidth">
      <el-form-item label="酒店名称" >
        <el-input v-model="hotel.name" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="酒店地址" >
        <el-input v-model="hotel.address" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="酒店价格" >
        <el-input v-model="hotel.price" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="酒店评分">
        <el-input v-model="hotel.score" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="酒店品牌">
        <el-input v-model="hotel.brand" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="所在城市">
        <el-input v-model="hotel.city" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="所在商圈">
        <el-input v-model="hotel.business" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="酒店图片" >
        <el-input v-model="hotel.pic" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="酒店纬度" >
        <el-input v-model="hotel.latitude" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="酒店经度" >
        <el-input v-model="hotel.longitude" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="星级" >
        <el-select style="width: 263px" v-model="hotel.starName" placeholder="请选择酒店星级">
          <el-option label="一星级" value="一星级"></el-option>
          <el-option label="二星级" value="二星级"></el-option>
          <el-option label="三星级" value="三星级"></el-option>
          <el-option label="四星级" value="四星级"></el-option>
          <el-option label="五星级" value="五星级"></el-option>
          <el-option label="一钻" value="一钻"></el-option>
          <el-option label="两钻" value="两钻"></el-option>
          <el-option label="三钻" value="三钻"></el-option>
          <el-option label="四钻" value="四钻"></el-option>
          <el-option label="五钻" value="五钻"></el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="formVisible = false">取 消</el-button>
      <el-button type="primary" @click="confirmEdit">确 定</el-button>
    </div>
  </el-dialog>
</div>
<script src="./js/vue.js"></script>
<script>
  // 设置后台服务地址
  axios.defaults.baseURL = "http://localhost:8099";
  axios.defaults.timeout = 3000;

  const app = new Vue({
    el: "#app",
    data: {
      hotels: [],
      total: 1000,
      formVisible: false, // 是否显示表单
      formLabelWidth: "100px", // 表单label宽度
      hotel: {}, // 表单中的酒店数据
      isEdit: false, // 是否是更新
      lastPage: 1,// 上一次查询的页码
    },
    created() {
      this.query(1);
    },
    methods: {
      beginAdd(){
        this.isEdit = false;
        this.hotel = {};
        this.formVisible = true;
      },
      query(page){
        this.lastPage = page;
        axios.get("/hotel/list", {
            params: {
              page: page, size: 5
            }
          })
          .then(resp => {
            this.hotels = resp.data.hotels;
            this.total = resp.data.total;
          })
          .catch(err => console.log(err));
      },
      handleEdit(v1, v2) {
        this.isEdit = true;
        this.hotel = JSON.parse(JSON.stringify(v2));
        this.formVisible = true;
      },
      handleDelete(v1, v2) {
        this.$confirm('此操作将永久删除酒店信息, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.deleteById(v2.id);
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
      },
      confirmEdit(){
        if(this.isEdit){
          axios.put("/hotel", this.hotel)
            .then(resp => {
              this.$message({
                message: '更新成功',
                type: 'success'
              });
              this.formVisible = false;
              this.reload();
            })
            .catch(err => {
              this.$message({
                message: '更新失败',
                type: 'error'
              });
              console.log(err);
            })
        }else{
          axios.post("/hotel", this.hotel)
            .then(resp => {
              this.$message({
                message: '新增成功',
                type: 'success'
              });
              this.formVisible = false;
              this.reload();
            })
            .catch(err => {
              this.$message({
                message: '新增失败',
                type: 'error'
              });
              console.log(err);
            })
        }

      },
      deleteById(id){
        axios.delete("/hotel/" + id)
        .then(() => {
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
          this.reload();
        })
        .catch(err => {
          this.$message({
            type: 'error',
            message: '删除失败!'
          });
          console.log(err);
        })
      },
      reload(){
        this.query(this.lastPage);
      }
    }
  })
</script>
</body>
</html>

项目实现的效果

  • 首页
    在这里插入图片描述
  • 增加酒店信息页面
    在这里插入图片描述

原文链接:https://www.cnblogs.com/projecthelp/p/17377906.html

本站文章如无特殊说明,均为本站原创,如若转载,请注明出处:28基于java的简单酒店数据管理 - Python技术站

(0)
上一篇 2023年5月6日
下一篇 2023年5月6日

相关文章

  • java登录验证码实现代码

    实现Java登录验证码的代码,可以使用Java的第三方开源框架Kaptcha。下面是详细步骤。 Kaptcha安装 下载jar包 在Kaptcha官网上下载最新的jar包。 导入jar包 将下载的jar包导入项目的Classpath路径下。 Kaptcha使用 添加JSP页面代码 在需要验证码的登录页面的form标签中添加如下代码: “`html 验证码

    Java 2023年5月23日
    00
  • jOOQ串联字符串拒绝使用的原因实例

    标题:jOOQ串联字符串拒绝使用的原因实例 介绍:jOOQ是一个流行的Java ORM工具,可以用来进行SQL查询和数据操作,其中包括串联字符串。然而,在特定情况下,使用jOOQ串联字符串可能不是最佳选择。本篇文章将讨论jOOQ串联字符串拒绝使用的原因,并给出两个示例说明。 正文: jOOQ串联字符串使用不当可能导致性能问题 jOOQ的DSLContext类…

    Java 2023年6月15日
    00
  • 快速排序的原理及java代码实现

    下面我来详细讲解一下“快速排序的原理及Java代码实现”的完整攻略。 1. 快速排序的原理 快速排序是一种常见的排序算法,其基本思想是:选择一个基准元素,将待排序序列分成两个子序列,使得左边的子序列元素都小于等于基准元素,右边的子序列元素都大于等于基准元素,然后递归地对子序列进行排序,直到整个序列有序。 具体的实现过程如下: 从待排序序列中选择一个基准元素,…

    Java 2023年5月19日
    00
  • Linux下Tomcat8.0.44配置使用Apr的方法

    下面是详细讲解Linux下Tomcat8.0.44配置使用Apr的方法的完整攻略: 前置条件 已安装Apache Tomcat 8.0.44和相关依赖库; 已安装APR(Apache Portable Runtime)库。 步骤一:下载并解压APR 首先,需要从APR官网下载APR和APR-util压缩包,并解压到本地某个目录。以APR 1.7.0版本为例,…

    Java 2023年5月19日
    00
  • 如何使用ActiveMQ中间件方式发送邮件

    使用ActiveMQ中间件方式发送邮件可以极大地提高邮件发送的效率和可靠性,下面是详细的步骤: 前置条件 安装ActiveMQ中间件。 了解Java编程语言,并且熟悉使用Java相关工具和框架。 步骤 引入ActiveMQ相关的依赖: <dependency> <groupId>org.apache.activemq</grou…

    Java 2023年5月19日
    00
  • mybatis-plus主键生成策略

    mybatis-plus主键生成策略可以通过注解或配置文件进行设置,下面将详细讲解。 1. 注解方式设置主键生成策略 在实体类中使用@TableId注解可以设置主键生成方式。其属性type表示主键生成类型,取值范围为枚举类IdType中的枚举值,包括AUTO、NONE、INPUT、ID_WORKER、UUID、ID_WORKER_STR。其中,ID_WORK…

    Java 2023年5月19日
    00
  • Spring Boot两种全局配置和两种注解的操作方法

    Spring Boot是一个快速开发框架,它提供了许多便捷的功能,其中包括全局配置和注解。本文将详细讲解Spring Boot两种全局配置和两种注解的操作方法,包括以下内容: Spring Boot全局配置简介 application.properties配置文件 application.yml配置文件 @ConfigurationProperties注解 …

    Java 2023年5月15日
    00
  • javaweb分页原理详解

    对于“javaweb分页原理详解”,以下是我整理的完整攻略: 一、分页原理介绍 1.1 分页的定义 分页是指将大容量数据均匀的分成若干页面,每页包含固定数量的信息,以便于操作。在网站开发的过程中,分页技术经常被用来显示查询结果,以减少服务器的负载和提高用户体验。 1.2 分页的实现原理 在进行分页操作时,我们需要以下信息: 当前页码 每页显示的记录数 总记录…

    Java 2023年6月16日
    00
合作推广
合作推广
分享本页
返回顶部