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

打印 上一主题 下一主题

主题 555|帖子 555|积分 1665

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

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

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


  • HotelController 定义了对酒店信息的CRUD的接口:
  1. @RestController
  2. @RequestMapping("hotel")
  3. public class HotelController {
  4.     @Autowired
  5.     private IHotelService hotelService;
  6.     /**
  7.      * 通过id来查询酒店数据
  8.      * @param id 酒店id号
  9.      * @return
  10.      */
  11.     @GetMapping("/{id}")
  12.     public Hotel queryById(@PathVariable("id") Long id){
  13.         return hotelService.getById(id);
  14.     }
  15.     /**
  16.      * 分页查询数据列表出来
  17.      * @param page 页码
  18.      * @param size 每页的大小
  19.      * @return
  20.      */
  21.     @GetMapping("/list")
  22.     public PageResult hotelList(
  23.             @RequestParam(value = "page", defaultValue = "1") Integer page,
  24.             @RequestParam(value = "size", defaultValue = "1") Integer size
  25.     ){
  26.         Page<Hotel> result = hotelService.page(new Page<>(page, size));
  27.         return new PageResult(result.getTotal(), result.getRecords());
  28.     }
  29.     /**
  30.      * 保存酒店信息
  31.      * @param hotel 酒店信息实体类
  32.      */
  33.     @PostMapping
  34.     public void saveHotel(@RequestBody Hotel hotel){
  35.         hotelService.save(hotel);
  36.     }
  37.     /**
  38.      * 更新酒店信息
  39.      * @param hotel 酒店信息实体类
  40.      */
  41.     @PutMapping()
  42.     public void updateById(@RequestBody Hotel hotel){
  43.         if (hotel.getId() == null) {
  44.             throw new InvalidParameterException("id不能为空");
  45.         }
  46.         hotelService.updateById(hotel);
  47.     }
  48.     /**
  49.      * 通过酒店id删除酒店信息
  50.      * @param id 酒店id号
  51.      */
  52.     @DeleteMapping("/{id}")
  53.     public void deleteById(@PathVariable("id") Long id) {
  54.         hotelService.removeById(id);
  55.     }
  56. }
复制代码

  • 前端使用的vue
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.   <meta charset="UTF-8">
  5.   <title>简单酒店管理</title>
  6.   <link href="./css/main.css" rel="stylesheet">
  7. </head>
  8. <body>
  9.   <h1>简单酒店增删改查项目</h1>
  10.   
  11.     <el-button type="primary" size="small" @click="beginAdd">新增酒店</el-button>
  12.   
  13.   <el-table :data="hotels" border height="500" >
  14.     <el-table-column align="center" fixed prop="id" label="酒店房间号" width="120"></el-table-column>
  15.     <el-table-column align="center" prop="name" label="酒店名称" width="120"></el-table-column>
  16.     <el-table-column align="center" prop="address" label="酒店地址" width="120"></el-table-column>
  17.     <el-table-column align="center" prop="name" label="酒店名称" width="120"></el-table-column>
  18.     <el-table-column align="center" label="酒店图片" width="200">
  19.       <template slot-scope="scope">
  20.         <img :src="scope.row.pic" height="200" width="200" />
  21.       </template>
  22.     </el-table-column>
  23.     <el-table-column align="center" prop="price" label="酒店价格" width="100"></el-table-column>
  24.     <el-table-column align="center" label="酒店评分" width="200">
  25.       <template slot-scope="scope">
  26.         <el-rate
  27.           v-model="scope.row.score / 10" disabled show-score text-color="#ff9900" score-template="{value}">
  28.         </el-rate>
  29.       </template>
  30.     </el-table-column>
  31.     <el-table-column align="center" prop="brand" label="酒店品牌" width="120"></el-table-column>
  32.     <el-table-column align="center" prop="city" label="所在城市" width="120"></el-table-column>
  33.     <el-table-column align="center" prop="starName" label="酒店星级" width="60"></el-table-column>
  34.     <el-table-column align="center" prop="business" label="所在商圈" width="120"></el-table-column>
  35.     <el-table-column align="center" label="操作" fixed="right" :width="150">
  36.       <template slot-scope="scope">
  37.         <el-button type="primary" plain icon="el-icon-edit" circle
  38.                    @click="handleEdit(scope.$index, scope.row)"></el-button>
  39.         <el-button type="danger" plain icon="el-icon-delete" circle
  40.                    @click="handleDelete(scope.$index, scope.row)"></el-button>
  41.       </template>
  42.     </el-table-column>
  43.   </el-table>
  44.   <el-pagination
  45.       @current-change="query"
  46.       
  47.       background
  48.       :page-size="5"
  49.       layout="prev, pager, next"
  50.       :total="total">
  51.   </el-pagination>
  52.   <el-dialog title="酒店信息" :visible.sync="formVisible" width="50%" >
  53.     <el-form :model="hotel" size="small" label-position="left" :label-width="formLabelWidth">
  54.       <el-form-item label="酒店名称" >
  55.         <el-input v-model="hotel.name" autocomplete="off"></el-input>
  56.       </el-form-item>
  57.       <el-form-item label="酒店地址" >
  58.         <el-input v-model="hotel.address" autocomplete="off"></el-input>
  59.       </el-form-item>
  60.       <el-form-item label="酒店价格" >
  61.         <el-input v-model="hotel.price" autocomplete="off"></el-input>
  62.       </el-form-item>
  63.       <el-form-item label="酒店评分">
  64.         <el-input v-model="hotel.score" autocomplete="off"></el-input>
  65.       </el-form-item>
  66.       <el-form-item label="酒店品牌">
  67.         <el-input v-model="hotel.brand" autocomplete="off"></el-input>
  68.       </el-form-item>
  69.       <el-form-item label="所在城市">
  70.         <el-input v-model="hotel.city" autocomplete="off"></el-input>
  71.       </el-form-item>
  72.       <el-form-item label="所在商圈">
  73.         <el-input v-model="hotel.business" autocomplete="off"></el-input>
  74.       </el-form-item>
  75.       <el-form-item label="酒店图片" >
  76.         <el-input v-model="hotel.pic" autocomplete="off"></el-input>
  77.       </el-form-item>
  78.       <el-form-item label="酒店纬度" >
  79.         <el-input v-model="hotel.latitude" autocomplete="off"></el-input>
  80.       </el-form-item>
  81.       <el-form-item label="酒店经度" >
  82.         <el-input v-model="hotel.longitude" autocomplete="off"></el-input>
  83.       </el-form-item>
  84.       <el-form-item label="星级" >
  85.         <el-select  v-model="hotel.starName" placeholder="请选择酒店星级">
  86.           <el-option label="一星级" value="一星级"></el-option>
  87.           <el-option label="二星级" value="二星级"></el-option>
  88.           <el-option label="三星级" value="三星级"></el-option>
  89.           <el-option label="四星级" value="四星级"></el-option>
  90.           <el-option label="五星级" value="五星级"></el-option>
  91.           <el-option label="一钻" value="一钻"></el-option>
  92.           <el-option label="两钻" value="两钻"></el-option>
  93.           <el-option label="三钻" value="三钻"></el-option>
  94.           <el-option label="四钻" value="四钻"></el-option>
  95.           <el-option label="五钻" value="五钻"></el-option>
  96.         </el-select>
  97.       </el-form-item>
  98.     </el-form>
  99.    
  100.       <el-button @click="formVisible = false">取 消</el-button>
  101.       <el-button type="primary" @click="confirmEdit">确 定</el-button>
  102.    
  103.   </el-dialog>
  104. </body>
  105. </html>
复制代码
项目实现的效果


  • 首页

  • 增加酒店信息页面


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

尚未崩坏

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表