首页 > 其他分享 >基于Spring Boot+Android的民宿预订系统

基于Spring Boot+Android的民宿预订系统

时间:2024-10-25 22:52:27浏览次数:3  
标签:return Spring Boot 民宿 user new import 客房

目录

前言

 一、技术栈

二、系统功能介绍

三、核心代码

1、登录模块

 2、文件上传模块

3、代码封装


前言

Android的民宿预订系统设计的目的是为用户提供民宿客房、公告信息等方面的平台。

与PC端应用程序相比,Android的民宿预订系统的设计主要面向于民宿,旨在为管理员和用户、商家提供一个Android的民宿预订系统。用户可以通过Android及时查看民宿客房等。

Android的民宿预订系统是在Android操作系统下的应用平台。为防止出现兼容性及稳定性问题,框架选择的是springboot,用户与后台之间的数据存储主要通过MySQL。用户在使用应用时产生的数据通过 java等语言传递给数据库。通过此方式促进Android的民宿预订系统信息流动和数据传输效率,提供一个内容丰富、功能多样、易于操作的Android的民宿预订系统。

 一、技术栈

末尾获取源码
Spring Boot+JS+ jQuery+Ajax...

二、系统功能介绍

第一次使用本Android的使用者,首先是要进行注册,点击“注册”,然后就会进入到注册的页面里面,将用户信息录入注册表,确认信息正确后,系统才会进入登录界面,用户登录成功后可使用本Android所提供的所有功能。用户注册界面如图5-1所示。

 

首先双击打开Android,连上网络之后会显示出本系统的登录界面,这是进入Android的第初始页面“登录”,能成功进入到该登录界面则代表Android开启是成功的,接下来就可以操作本系统所带有的其他所有的功能。用户登录界面如图5-2所示。 

 

 Android首页是用户注册登录后进入的第一个界面,用户可通过Android端首页的最下面的那一行导航栏中的“首页、民宿客房、公告信息、我的”进入到相应的网页进行操作;点击“我的”进入我的页面,在我的页面可以对民宿客房、预定信息、在线客服、我的收藏管理等进行详细操作。Android首页界面如图5-3所示。

 

 用户点击民宿客房,在民宿客房页面的输入栏填写民宿名称,进行搜索,然后可以查看民宿名称、客房编号、客房名称、客房类型、客房图片、客房价格、床位、客房状态、客房位置、发布时间、商家账号、商家名称、联系电话、点击次数等信息,如果有需要可以预订民宿客房或者收藏、评论等操作,如图5-4所示。

 

 用户点击预定信息,在预定信息页面的输入栏填写客房编号,进行搜索,然后可以查看预订编号、民宿名称、客房编号、客房类型、客房图片、客房价格、预订天数、总价格、预订时间、商家账号、商家名称、联系电话等信息,最后进行费用支付等操作,如图5-5所示。

 

 用户点击“我的”进入我的页面,在我的页面可以对民宿客房、预定信息、在线客服、我的收藏管理等进行详细操作。如图5-6所示。

 

 管理员登录,通过登录页面填写用户名和密码等信息,点击登录操作,如图5-7所示。

 管理员登录进入系统可以查看首页、个人中心、用户管理、商家管理、客房类型管理、民宿客房管理、预定信息管理、在线客服管理、系统管理等功能进行详细操作,如图5-8所示。

 管理员点击用户管理;在用户管理页面输入用户账号、用户姓名、性别、联系方式、头像等信息,进行查询,新增或删除用户信息等操作;如图5-9所示。

 管理员点击商家信息管理;在商家信息管理页面输入商家账号、商家名称、性别、联系电话、头像等信息,进行查询,新增或删除商家信息等操作;如图5-10所示。

 管理员点击民宿客房管理;在民宿客房管理页面对民宿名称、客房编号、客房名称、客房类型、客房图片、客房价格、床位、客房状态、客房位置、发布时间、商家账号、商家名称、联系电话等信息,进行查询或删除民宿客房等操作;如图5-11所示。

 管理员点击预定信息管理;在预定信息管理页面对预定编号、民宿名称、客房编号、客房类型、客房图片、客房价格、预定天数、总价格、预定时间、商家账号、商家名称、联系电话、是否支付等信息,进行查询或删除预定信息等操作;如图5-12所示。

 管理员点在线客服管理;在在线客服管理页面对编号、标题、封面、商家账号、商家名称、咨询时间、用户账号、用户姓名、回复等信息,进行查询或删除在线客服等操作;如图5-13所示。

 

三、核心代码

1、登录模块

 
package com.controller;
 
 
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.Map;
 
import javax.servlet.http.HttpServletRequest;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
 
import com.annotation.IgnoreAuth;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.entity.TokenEntity;
import com.entity.UserEntity;
import com.service.TokenService;
import com.service.UserService;
import com.utils.CommonUtil;
import com.utils.MD5Util;
import com.utils.MPUtil;
import com.utils.PageUtils;
import com.utils.R;
import com.utils.ValidatorUtils;
 
/**
 * 登录相关
 */
@RequestMapping("users")
@RestController
public class UserController{
	
	@Autowired
	private UserService userService;
	
	@Autowired
	private TokenService tokenService;
 
	/**
	 * 登录
	 */
	@IgnoreAuth
	@PostMapping(value = "/login")
	public R login(String username, String password, String captcha, HttpServletRequest request) {
		UserEntity user = userService.selectOne(new EntityWrapper<UserEntity>().eq("username", username));
		if(user==null || !user.getPassword().equals(password)) {
			return R.error("账号或密码不正确");
		}
		String token = tokenService.generateToken(user.getId(),username, "users", user.getRole());
		return R.ok().put("token", token);
	}
	
	/**
	 * 注册
	 */
	@IgnoreAuth
	@PostMapping(value = "/register")
	public R register(@RequestBody UserEntity user){
//    	ValidatorUtils.validateEntity(user);
    	if(userService.selectOne(new EntityWrapper<UserEntity>().eq("username", user.getUsername())) !=null) {
    		return R.error("用户已存在");
    	}
        userService.insert(user);
        return R.ok();
    }
 
	/**
	 * 退出
	 */
	@GetMapping(value = "logout")
	public R logout(HttpServletRequest request) {
		request.getSession().invalidate();
		return R.ok("退出成功");
	}
	
	/**
     * 密码重置
     */
    @IgnoreAuth
	@RequestMapping(value = "/resetPass")
    public R resetPass(String username, HttpServletRequest request){
    	UserEntity user = userService.selectOne(new EntityWrapper<UserEntity>().eq("username", username));
    	if(user==null) {
    		return R.error("账号不存在");
    	}
    	user.setPassword("123456");
        userService.update(user,null);
        return R.ok("密码已重置为:123456");
    }
	
	/**
     * 列表
     */
    @RequestMapping("/page")
    public R page(@RequestParam Map<String, Object> params,UserEntity user){
        EntityWrapper<UserEntity> ew = new EntityWrapper<UserEntity>();
    	PageUtils page = userService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.allLike(ew, user), params), params));
        return R.ok().put("data", page);
    }
 
	/**
     * 列表
     */
    @RequestMapping("/list")
    public R list( UserEntity user){
       	EntityWrapper<UserEntity> ew = new EntityWrapper<UserEntity>();
      	ew.allEq(MPUtil.allEQMapPre( user, "user")); 
        return R.ok().put("data", userService.selectListView(ew));
    }
 
    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") String id){
        UserEntity user = userService.selectById(id);
        return R.ok().put("data", user);
    }
    
    /**
     * 获取用户的session用户信息
     */
    @RequestMapping("/session")
    public R getCurrUser(HttpServletRequest request){
    	Long id = (Long)request.getSession().getAttribute("userId");
        UserEntity user = userService.selectById(id);
        return R.ok().put("data", user);
    }
 
    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody UserEntity user){
//    	ValidatorUtils.validateEntity(user);
    	if(userService.selectOne(new EntityWrapper<UserEntity>().eq("username", user.getUsername())) !=null) {
    		return R.error("用户已存在");
    	}
        userService.insert(user);
        return R.ok();
    }
 
    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody UserEntity user){
//        ValidatorUtils.validateEntity(user);
        userService.updateById(user);//全部更新
        return R.ok();
    }
 
    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
        userService.deleteBatchIds(Arrays.asList(ids));
        return R.ok();
    }
}

 2、文件上传模块

package com.controller;
 
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.UUID;
 
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
 
import com.annotation.IgnoreAuth;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.entity.ConfigEntity;
import com.entity.EIException;
import com.service.ConfigService;
import com.utils.R;
 
/**
 * 上传文件映射表
 */
@RestController
@RequestMapping("file")
@SuppressWarnings({"unchecked","rawtypes"})
public class FileController{
	@Autowired
    private ConfigService configService;
	/**
	 * 上传文件
	 */
	@RequestMapping("/upload")
	public R upload(@RequestParam("file") MultipartFile file,String type) throws Exception {
		if (file.isEmpty()) {
			throw new EIException("上传文件不能为空");
		}
		String fileExt = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")+1);
		File path = new File(ResourceUtils.getURL("classpath:static").getPath());
		if(!path.exists()) {
		    path = new File("");
		}
		File upload = new File(path.getAbsolutePath(),"/upload/");
		if(!upload.exists()) {
		    upload.mkdirs();
		}
		String fileName = new Date().getTime()+"."+fileExt;
		File dest = new File(upload.getAbsolutePath()+"/"+fileName);
		file.transferTo(dest);
		FileUtils.copyFile(dest, new File("C:\\Users\\Desktop\\jiadian\\springbootl7own\\src\\main\\resources\\static\\upload"+"/"+fileName));
		if(StringUtils.isNotBlank(type) && type.equals("1")) {
			ConfigEntity configEntity = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "faceFile"));
			if(configEntity==null) {
				configEntity = new ConfigEntity();
				configEntity.setName("faceFile");
				configEntity.setValue(fileName);
			} else {
				configEntity.setValue(fileName);
			}
			configService.insertOrUpdate(configEntity);
		}
		return R.ok().put("file", fileName);
	}
	
	/**
	 * 下载文件
	 */
	@IgnoreAuth
	@RequestMapping("/download")
	public ResponseEntity<byte[]> download(@RequestParam String fileName) {
		try {
			File path = new File(ResourceUtils.getURL("classpath:static").getPath());
			if(!path.exists()) {
			    path = new File("");
			}
			File upload = new File(path.getAbsolutePath(),"/upload/");
			if(!upload.exists()) {
			    upload.mkdirs();
			}
			File file = new File(upload.getAbsolutePath()+"/"+fileName);
			if(file.exists()){
				/*if(!fileService.canRead(file, SessionManager.getSessionUser())){
					getResponse().sendError(403);
				}*/
				HttpHeaders headers = new HttpHeaders();
			    headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);    
			    headers.setContentDispositionFormData("attachment", fileName);    
			    return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file),headers, HttpStatus.CREATED);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		return new ResponseEntity<byte[]>(HttpStatus.INTERNAL_SERVER_ERROR);
	}
	
}

3、代码封装

package com.utils;
 
import java.util.HashMap;
import java.util.Map;
 
/**
 * 返回数据
 */
public class R extends HashMap<String, Object> {
	private static final long serialVersionUID = 1L;
	
	public R() {
		put("code", 0);
	}
	
	public static R error() {
		return error(500, "未知异常,请联系管理员");
	}
	
	public static R error(String msg) {
		return error(500, msg);
	}
	
	public static R error(int code, String msg) {
		R r = new R();
		r.put("code", code);
		r.put("msg", msg);
		return r;
	}
 
	public static R ok(String msg) {
		R r = new R();
		r.put("msg", msg);
		return r;
	}
	
	public static R ok(Map<String, Object> map) {
		R r = new R();
		r.putAll(map);
		return r;
	}
	
	public static R ok() {
		return new R();
	}
 
	public R put(String key, Object value) {
		super.put(key, value);
		return this;
	}
}

标签:return,Spring,Boot,民宿,user,new,import,客房
From: https://blog.csdn.net/2301_77541824/article/details/143127589

相关文章

  • 基于Spring Boot+Android的武汉市公交路线查询系统
    目录前言 一、技术栈二、系统功能介绍三、核心代码1、登录模块 2、文件上传模块3、代码封装前言武汉市公交路线查询系统APP设计的目的是为用户提供公交路线等方面的平台。与PC端应用程序相比,武汉市公交路线查询管理的设计主要面向于公交公司,旨在为管理员和用户......
  • 基于SpringBoot的学生社团管理系统【附源码】
    ​基于SpringBoot的学生社团管理系统(源码+L文+说明文档)     目录4系统设计  4.1界面设计原则  4.2功能模块设计  4.3数据库设计  4.3.1数据库E-R图  4.3.2数据库表结构  5 系统实现   5.1 管理员功能实现  5.1.1 团长管理  5.1.2......
  • Springboot+vue图书商城购物系统【附源码】
    Springboot+vue图书商城购物系统(源码+L文+说明文档)  目录 四系统设计  4.1系统概述 4.2系统层次架构  4.3系统功能详情设计  4.4主流程描述  五、系统实现  5.1用户登录:  5.2用户注册  5.3前端首页   5.4管理员首页  5.5书籍分类管理......
  • Springboot 整合 Java DL4J 实现时尚穿搭推荐系统
    ......
  • Spring Boot 3.2.3 中文参考指南:全面解析与最佳实践
    一、SpringBoot3.2.3的主要特性和亮点1.自动配置自动配置是SpringBoot的核心特性之一,它能够根据项目的依赖自动配置应用。减少了配置时间:项目依赖中包含特定的组件时,SpringBoot会自动进行配置。示例:在classpath中看到spring-boot-starter-web时,会自动配置一个To......
  • 基于java+springboot的高校毕业生就业推介系统
    基于java+springboot的高校毕业生就业推介系统是一款助力高校毕业生就业的平台。它全面记录毕业生个人信息,如基本信息、学习成绩、获奖实习等履历,且支持实时更新。对企业则有入驻审核机制,确保合法性,企业可发布岗位信息并管理。系统运用智能匹配算法,依据毕业生专业、技能......
  • 基于springboot的高校班级管理系统微信小程序
    基于java+springboot的高校班级管理系统微信小程序是一款专为高校班级管理打造的便捷工具。它充分利用了java的稳定性和强大功能,以及springboot的高效开发优势,结合微信小程序的便捷性,为高校班级管理带来了全新的体验。对于教师而言,该小程序提供了全面的班级管理功能......
  • SpringMVC7-RESTful
    目录RESTful简介资源资源的表述状态转移RESTful的实现案例RESTful简介REST:RepresentationalStateTransfer,表现层资源状态转移资源资源是一种看待服务器的方式,即,将服务器看作是由很多离散的资源组成。每个资源是服务器上一个可命名的抽象概念。因为资源是一个抽象......
  • springboot监听器的使用(ApplicationListener、SmartApplicationListener、@EventListe
    Springboot监听器的使用(ApplicationListener、SmartApplicationListener、@EventListener)https://blog.csdn.net/m0_54355172/article/details/128592476    目录前言1.ApplicationListener1.简单的全局监听2.定时任务3.监听自定义事件2.SmartApplicatio......
  • Spring学习笔记_10-@Component
    @Component1.介绍在项目开发过程中,我们自己编写的类如果想注入到Spring中,由Spring来管理Bean的生命周期,就可以使用@Component注解将其注入到IOC容器中。@Component注解还有三个衍生注解,那就是@Repository、@Service和@Controller注解,并且衍生出的注解通常会在使用MVC架构开......