Java实战房屋租赁网的实现流程
程序员文章站
2022-03-15 19:30:49
一、项目简述功能包括: 前台:系统首页,酒店介绍,系统公告,客房信息,客房类型,用 户预等等。 用户:注册登陆修改我的信息客房预订等等。 管理员修改登录密码,添加客房,会员信息管理等等。二、项目运行环...
一、项目简述
功能包括: 前台:系统首页,酒店介绍,系统公告,客房信息,客房类型,用 户预等等。 用户:注册登陆修改我的信息客房预订等等。 管理员修改登录密码,添加客房,会员信息管理等等。
二、项目运行
环境配置: 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; /** * 查询全部数据 * * @return */ @requestmapping(value = "userlist",method = requestmethod.get) public result findall() { list<user> all = userservice.findall(); return new result(true, statuscode.ok, "查询成功",all,all.size()); } /** * 根据id查询 * * @param id id * @return */ @requestmapping(value = "/{id}", method = requestmethod.get) public result findbyid(@pathvariable long id) { return new result(true, statuscode.ok, "查询成功", userservice.findbyid(id)); } /** * 分页+多条件查询 * @param searchmap 查询条件封装 * @param page 页码 * @param size 页大小 * @return 分页结果 */ @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()) ); } /** * 根据条件查询 * @param searchmap * @return */ @requestmapping(value="/search",method = requestmethod.post) public result findsearch( @requestbody map searchmap){ return new result(true,statuscode.ok,"查询成功",userservice.findsearch(searchmap)); } /** * 增加 * @param user */ @requestmapping(method=requestmethod.post) public result add(@requestbody user user ){ userservice.add(user); return new result(true,statuscode.ok,"增加成功"); } /** * 修改 * @param user */ @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,"修改成功"); } /** * 修改 * @param user */ @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,"修改成功"); } /** * 删除 * @param id */ @requestmapping(value="/{id}",method= requestmethod.delete) public result delete(@pathvariable string id ){ userservice.deletebyid(id); return new result(true,statuscode.ok,"删除成功"); } /** * 用户注册 * @param code * @param user * @return */ @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,"注册成功"); } /** *判断账号是否存在 * @param user * @return */ @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,"该手机号已经被注册"); } /** * 邮箱验证 * @param user * @return */ @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,"该邮箱已经被注册"); } /** * 用户登录 * @param loginmap * @return */ @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,"用户名或密码错误"); } } } /** * 用户注销 * @param request * @param response * @throws ioexception */ @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; /** * 查询全部酒店信息 * @return */ @responsebody @requestmapping(value = "/list",method= requestmethod.get) public result findall(){ list<hotel> all = hotelservice.findall(); return new result(true, statuscode.ok,"查询成功",all,all.size()); } /** * 根据id查询 * @param id id * @return */ @responsebody @requestmapping(value="/{id}",method= requestmethod.get) public result findbyid(@pathvariable long id){ return new result(true,statuscode.ok,"查询成功",hotelservice.findbyid(id)); } /** * 酒店添加操作 * @param hotel */ @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,"添加成功"); } /** * 分页+多条件查询 * @param searchmap 查询条件封装 * @param page 页码 * @param size 页大小 * @return 分页结果 */ @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()) ); } /** * 根据条件查询 * @param searchmap * @return */ @responsebody @requestmapping(value="/search",method = requestmethod.post) public result findsearch( @requestbody map searchmap){ return new result(true,statuscode.ok,"查询成功",hotelservice.findsearch(searchmap)); } /** * 修改 * @param hotel */ @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,"修改成功"); } /** * 删除 * @param id */ @responsebody @requestmapping(value="/{id}",method= requestmethod.delete) public result delete(@pathvariable string id ){ hotelservice.deletebyid(id); return new result(true,statuscode.ok,"删除成功"); } /** * 酒店列表跳转路径 * @return */ @requestmapping(value = "/hotellist") public string hotellist(){ return "admin/hotelmanage/hotellist"; } @requestmapping(value = "/hoteladd") public string hoteladd(){ return "admin/hotelmanage/hoteladd"; } /** * 查询单个酒店 * @param model * @param id * @return */ @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"; } }
后台管理员控制器:
/** * 控制器层 * @author yy * */ @controller @crossorigin @requestmapping("/admin") public class admincontroller { @autowired private adminservice adminservice; @autowired bcryptpasswordencoder encoder; /** * 查询全部数据 * @return */ @responsebody @requestmapping(method= requestmethod.get) public result findall(){ return new result(true, statuscode.ok,"查询成功",adminservice.findall()); } /** * 根据id查询 * @param id id * @return */ @responsebody @requestmapping(value="/{id}",method= requestmethod.get) public result findbyid(@pathvariable long id){ return new result(true,statuscode.ok,"查询成功",adminservice.findbyid(id)); } /** * 分页+多条件查询 * @param searchmap 查询条件封装 * @param page 页码 * @param size 页大小 * @return 分页结果 */ @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()) ); } /** * 根据条件查询 * @param searchmap * @return */ @responsebody @requestmapping(value="/search",method = requestmethod.post) public result findsearch( @requestbody map searchmap){ return new result(true,statuscode.ok,"查询成功",adminservice.findsearch(searchmap)); } /** * 增加 * @param admin */ @responsebody @requestmapping(method=requestmethod.post) public result add(@requestbody admin admin ){ adminservice.add(admin); return new result(true,statuscode.ok,"增加成功"); } /** * 修改 * @param admin */ @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,"修改成功"); } /** * 删除 * @param id */ @responsebody @requestmapping(value="/{id}",method= requestmethod.delete) public result delete(@pathvariable string id ){ adminservice.deletebyid(id); return new result(true,statuscode.ok,"删除成功"); } /** * 管理员跳转 * @return */ @requestmapping(value = "/adminlogin") public string adminlogin() { return "admin/login/login"; } /** * admin登录 * @param loginmap * @param request * @return */ @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,"账号密码错误"); } } /** * 管理员登录成功 * @return */ @requestmapping(value = "/index") public string success(){ return "admin/index"; } /** * 用户列表 * @return */ @requestmapping(value = "/userlist") public string user(){ return "admin/usermanage/userlist"; } @requestmapping(value = "/echars") public string analysis(){ return "admin/echars/console"; } /** * 管理员退出登录 * @return */ @requestmapping(value = "/logout") public string logout(httpsession session){ session.removeattribute("admin"); return "admin/login/login"; } /** * 管理员修改密码 * @return */ @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 房屋租赁网的资料请关注其它相关文章!