文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

Java实战房屋租赁网的实现流程

2024-04-02 19:55

关注

一、项目简述

功能包括: 前台:系统首页,酒店介绍,系统公告,客房信息,客房类型,用 户预等等。 用户:注册登陆修改我的信息客房预订等等。 管理员修改登录密码,添加客房,会员信息管理等等。

二、项目运行

环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)

项目技术: JSP +Spring + SpringMVC + MyBatis + html+ css + JavaScript + JQuery + Ajax + layui+ maven等等。

用户控制器:



@RestController
@CrossOrigin
@RequestMapping("/user")
public class UserController {
 
	@Autowired
	private UserService userService;
 
	@Autowired
	private RedisTemplate redisTemplate;
 
	@Autowired
	private HttpServletRequest request;
 
	@Autowired
    BCryptPasswordEncoder encoder;
 
 
 
    
    @RequestMapping(value = "userList",method = RequestMethod.GET)
    public Result findAll() {
		List<User> all = userService.findAll();
		return new Result(true, StatusCode.OK, "查询成功",all,all.size());
    }
 
    
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public Result findById(@PathVariable Long id) {
        return new Result(true, StatusCode.OK, "查询成功", userService.findById(id));
    }
 
 
	
	@RequestMapping(value="/search/{page}/{size}",method=RequestMethod.POST)
	public Result findSearch(@RequestBody Map searchMap , @PathVariable int page, @PathVariable int size){
		Page<User> pageList = userService.findSearch(searchMap, page, size);
		return  new Result(true,StatusCode.OK,"查询成功",  new PageResult<User>(pageList.getTotalElements(), pageList.getContent()) );
	}
 
	
    @RequestMapping(value="/search",method = RequestMethod.POST)
    public Result findSearch( @RequestBody Map searchMap){
        return new Result(true,StatusCode.OK,"查询成功",userService.findSearch(searchMap));
    }
	
	
	@RequestMapping(method=RequestMethod.POST)
	public Result add(@RequestBody User user  ){
		userService.add(user);
		return new Result(true,StatusCode.OK,"增加成功");
	}
	
	
	@ResponseBody
	@RequestMapping(value="/{id}",method= RequestMethod.PUT)
	public Result update(User user, @PathVariable Long id ){
		User oldUser=userService.findById(id);
		user.setId(id);
		user.setPassword(oldUser.getPassword());
		userService.update(user);
		return new Result(true,StatusCode.OK,"修改成功");
	}
 
	
	@RequestMapping(value="/change",method= RequestMethod.POST,consumes = "application/json")
	public Result update(@RequestBody User user, HttpSession session){
		User us= (User) session.getAttribute("user");
		user.setId(us.getId());
		user.setPassword(us.getPassword());
		userService.update(user);
		return new Result(true,StatusCode.OK,"修改成功");
	}
	
	@RequestMapping(value="/{id}",method= RequestMethod.DELETE)
	public Result delete(@PathVariable String id ){
		userService.deleteById(id);
		return new Result(true,StatusCode.OK,"删除成功");
	}
	
	@ResponseBody
	@RequestMapping(value = "/register/",method = RequestMethod.POST)
	public Result regist(@RequestParam(name = "code") String code,User user,HttpServletRequest request){
		String sCode = (String) request.getSession().getAttribute("user_register_email_code");
		if(!sCode.equalsIgnoreCase(code)){
			return new Result(false,StatusCode.ERROR,"验证码错误!");
		}
			userService.add(user);
			return new Result(true,StatusCode.OK,"注册成功");
	}
 
	
    @RequestMapping(value = "/checkPhone",method = RequestMethod.POST)
	@ResponseBody
    public Result checkPhone(User user){
		String phone = user.getMobile();
		if(!StringUtil.isMobile(phone)){
			return new Result(false,StatusCode.ERROR,"请填写正确的手机号!");
		}
		User userphone= userService.findByMobile(phone);
		if (userphone == null){
			return new Result(true,StatusCode.OK,"该手机号可以注册");
		}
		return new Result(false,StatusCode.ERROR,"该手机号已经被注册");
	}
 
 
	
	@RequestMapping(value = "/email",method = RequestMethod.POST)
	@ResponseBody
	public Result findemail(User user){
		String email = user.getEmail();
		if(!StringUtil.emailFormat(email)){
			return new Result(true,StatusCode.ERROR,"请填写正确的邮箱格式");
		}
		User useremail= userService.findByEmail(email);
		if (useremail == null){
			return new Result(true,StatusCode.OK,"该邮箱可以注册");
		}
		return new Result(false,StatusCode.ERROR,"该邮箱已经被注册");
	}
 
 
 
 
 
	
	@ResponseBody
	@RequestMapping(value="/login",method=RequestMethod.POST)
	public Result login(@RequestParam Map<String,String> loginMap,HttpServletRequest request){
		  String mobile = loginMap.get("login");
		if (StringUtil.isMobile(mobile)){
			User user = userService.findByMobileAndPassword(loginMap.get("login"),loginMap.get("password"));
			if(user!=null){
				request.getSession().setAttribute("user",user);
				Map map=new HashMap();
				return new Result(true,StatusCode.OK,"登陆成功");
			}else{
				return new Result(false,StatusCode.LOGINERROR,"用户名或密码错误");
			}
		}else {
			User user =  userService.findByNameAndPassword(loginMap.get("login"),loginMap.get("password"));
			if(user!=null){
				request.getSession().setAttribute("user",user);
				Map map=new HashMap();
				map.put("name",user.getName());//姓名
				return new Result(true,StatusCode.OK,"登陆成功",map);
 
			}else{
				return new Result(false,StatusCode.LOGINERROR,"用户名或密码错误");
			}
		}
	}
 
 
	
	@RequestMapping(value="/logout",method=RequestMethod.GET)
	public void logout(HttpServletRequest request,HttpServletResponse response) throws IOException {
        request.getSession().setAttribute("user", null);
        response.sendRedirect(request.getContextPath() + "/dist/view");
 
    }
 
}

酒店房屋控制器:



@Controller
@CrossOrigin
@RequestMapping("/hotel")
public class HotelController {
 
	@Autowired
	private HotelService hotelService;
 
	@Autowired
	private ScenicService scenicService;
 
 
 
	
	@ResponseBody
	@RequestMapping(value = "/list",method= RequestMethod.GET)
	public Result findAll(){
		List<Hotel> all = hotelService.findAll();
		return new Result(true, StatusCode.OK,"查询成功",all,all.size());
	}
	
	
	@ResponseBody
	@RequestMapping(value="/{id}",method= RequestMethod.GET)
	public Result findById(@PathVariable Long id){
		return new Result(true,StatusCode.OK,"查询成功",hotelService.findById(id));
	}
 
 
	
	@ResponseBody
	@RequestMapping(value = "/add",method=RequestMethod.POST)
	public Result add(Hotel hotel){
		if(StringUtils.isEmpty(hotel.getName())){
			return new Result(false,StatusCode.ERROR,"请填写酒店名称");
		}
		if(StringUtils.isEmpty(hotel.getImg())){
			return new Result(false,StatusCode.ERROR,"请上传酒店封面图片");
		}
		if(StringUtils.isEmpty(hotel.getAddr())){
			return new Result(false,StatusCode.ERROR,"请填写酒店地址");
		}
		if(StringUtils.isEmpty(hotel.getMiaoshu())){
			return new Result(false,StatusCode.ERROR,"请填写酒店描述");
		}
		hotel.setCommentCount(0);
		hotel.setStar(0);
		if(hotelService.add(hotel)==null){
			return new Result(false,StatusCode.ERROR,"酒店添加失败");
		}
		return new Result(true,StatusCode.OK,"添加成功");
	}
 
 
	
	@ResponseBody
	@RequestMapping(value="/search/{page}/{size}",method=RequestMethod.POST)
	public Result findSearch(@RequestBody Map searchMap , @PathVariable int page, @PathVariable int size){
		Page<Hotel> pageList = hotelService.findSearch(searchMap, page, size);
		return  new Result(true,StatusCode.OK,"查询成功",  new PageResult<Hotel>(pageList.getTotalElements(), pageList.getContent()) );
	}
 
	
	@ResponseBody
    @RequestMapping(value="/search",method = RequestMethod.POST)
    public Result findSearch( @RequestBody Map searchMap){
        return new Result(true,StatusCode.OK,"查询成功",hotelService.findSearch(searchMap));
    }
 
 
	
	@ResponseBody
	@RequestMapping(value="/edit",method= RequestMethod.PUT)
	public Result update(Hotel hotel){
		Hotel hotelById = hotelService.findById(hotel.getId());
		if(hotelById==null){
			return new Result(false,StatusCode.ERROR,"该酒店信息不存在");
		}
		if(StringUtils.isEmpty(hotel.getName())){
			return new Result(false,StatusCode.ERROR,"请填写酒店名称");
		}
		BeanUtils.copyProperties(hotel,hotelById,"id","img","miaoshu","day","startdate","addr","commentCount");
		if(hotelService.update(hotelById)==null){
			return new Result(false,StatusCode.ERROR,"酒店编辑失败");
		}
		return new Result(true,StatusCode.OK,"修改成功");
	}
	
	
	@ResponseBody
	@RequestMapping(value="/{id}",method= RequestMethod.DELETE)
	public Result delete(@PathVariable String id ){
		hotelService.deleteById(id);
		return new Result(true,StatusCode.OK,"删除成功");
	}
 
	
	@RequestMapping(value = "/hotelList")
	public String hotelList(){
		return "admin/hotelmanage/hotelList";
	}
 
	@RequestMapping(value = "/hotelAdd")
	public String hotelAdd(){
		return "admin/hotelmanage/hotelAdd";
	}
 
 
	
	@RequestMapping("/oneAttr")
	public String One_attr(Model model, Long id){
		Hotel scenic=hotelService.findById(id);
		model.addAttribute("oneAttr",scenic);
		return "page/hotelDetail";
	}
 
	@RequestMapping("/local")
	public String localRefresh(Model model,Long id) {
		Hotel hotel=hotelService.findById(id);
			//	Sort sort=new Sort(Sort.Direction.DESC,"star");
			System.out.println("1111"+hotel.toString());
			List<Scenic> scenics=scenicService.findByCountryLike(hotel.getAddr());
			System.out.println("2222"+scenics.toString());
			Collections.sort(scenics, new Comparator<Scenic>() {
				@Override
				public int compare(Scenic o1, Scenic o2) {
					if (o1.getStart()<o2.getStart()){
						return 2;
					}
					if (o1.getStart().equals(o2.getStart()) ){
						return 1;
					}
					return -1;
				}
			});
			if (scenics.size()>=4){
				List newList=scenics.subList(0,3);
				model.addAttribute("scenics",newList);
			}else {
				model.addAttribute("scenics",scenics);
			}
 
		return "page/hotelDetail::table_refresh";
	}
}

后台管理员控制器:



@Controller
@CrossOrigin
@RequestMapping("/admin")
public class AdminController {
 
	@Autowired
	private AdminService adminService;
	
	@Autowired
	BCryptPasswordEncoder encoder;
 
	
	@ResponseBody
	@RequestMapping(method= RequestMethod.GET)
	public Result findAll(){
		return new Result(true, StatusCode.OK,"查询成功",adminService.findAll());
	}
	
	
	@ResponseBody
	@RequestMapping(value="/{id}",method= RequestMethod.GET)
	public Result findById(@PathVariable Long id){
		return new Result(true,StatusCode.OK,"查询成功",adminService.findById(id));
	}
 
 
	
	@ResponseBody
	@RequestMapping(value="/search/{page}/{size}",method=RequestMethod.POST)
	public Result findSearch(@RequestBody Map searchMap , @PathVariable int page, @PathVariable int size){
		Page<Admin> pageList = adminService.findSearch(searchMap, page, size);
		return  new Result(true,StatusCode.OK,"查询成功",  new PageResult<Admin>(pageList.getTotalElements(), pageList.getContent()) );
	}
 
	
	@ResponseBody
    @RequestMapping(value="/search",method = RequestMethod.POST)
    public Result findSearch( @RequestBody Map searchMap){
        return new Result(true,StatusCode.OK,"查询成功",adminService.findSearch(searchMap));
    }
	
	
	@ResponseBody
	@RequestMapping(method=RequestMethod.POST)
	public Result add(@RequestBody Admin admin  ){
		adminService.add(admin);
		return new Result(true,StatusCode.OK,"增加成功");
	}
	
	
	@ResponseBody
	@RequestMapping(value="/{id}",method= RequestMethod.PUT)
	public Result update(@RequestBody Admin admin, @PathVariable Long id ){
		admin.setId(id);
		adminService.update(admin);		
		return new Result(true,StatusCode.OK,"修改成功");
	}
	
	
	@ResponseBody
	@RequestMapping(value="/{id}",method= RequestMethod.DELETE)
	public Result delete(@PathVariable String id ){
		adminService.deleteById(id);
		return new Result(true,StatusCode.OK,"删除成功");
	}
 
	
	@RequestMapping(value = "/adminlogin")
	public String adminlogin()
	{
		return "admin/login/login";
	}
 
 
	
	@ResponseBody
	@RequestMapping(value="/login",method= RequestMethod.POST)
	public Result login(@RequestParam Map<String,String> loginMap,HttpServletRequest request){
		Admin admin = adminService.finbyNameAndPassword(loginMap.get("name"),loginMap.get("password"));
		if (admin!=null){
 
			request.getSession().setAttribute("admin",admin);
			Map map=new HashMap();
			map.put("name",admin.getName());
			return new Result(true,StatusCode.OK,"登录成功");
		}else {
			return new Result(false,StatusCode.ERROR,"账号密码错误");
		}
	}
 
	
	@RequestMapping(value = "/index")
	public String success(){
		return "admin/index";
	}
 
 
	
	@RequestMapping(value = "/userList")
	public String user(){
		return "admin/usermanage/userList";
	}
 
	@RequestMapping(value = "/echars")
	public String analysis(){
		return "admin/echars/console";
	}
 
 
	
	@RequestMapping(value = "/logout")
	public String logout(HttpSession session){
		session.removeAttribute("admin");
		return "admin/login/login";
	}
 
 
	
	@ResponseBody
	@RequestMapping(value = "/passwd")
	public Result passwd(HttpSession session,String passwd,String oldpad){
 
		Admin admindmin= (Admin) session.getAttribute("admin");
		Admin admins=adminService.findById(admindmin.getId());
		boolean old=encoder.matches(oldpad,admins.getPassword());
		if (old){
			String newPassd=encoder.encode(passwd);
			admins.setPassword(newPassd);
			adminService.update(admins);
			return new Result(true,StatusCode.OK,"成功");
		}else {
			return new Result(false,StatusCode.ERROR,"更新失败");
		}
	}
 
}

以上就是Java实战房屋租赁网的实现流程的详细内容,更多关于Java 房屋租赁网的资料请关注编程网其它相关文章!

阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     813人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     354人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     318人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     435人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     224人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-后端开发
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯