博主主页:Java旅途
简介:分享计算机知识、学习路线、系统源码及教程
文末获取源码
一、项目介绍
房屋租赁网站基于SpringBoot+Mybatis开发,系统分为管理员和普通用户两种角色。
管理员功能如下:
- 登录
- 修改密码
- 查看用户
- 房屋管理
- 图片上传
普通用户功能如下:
- 网站首页
- 房屋浏览
- 房屋查询
- 注册登录
- 房屋预定
- 我的租房信息
- 发布房源
二、技术框架
- 后端:SpringBoot,Mybatis
- 前端:layui
三、安装教程
- 用idea打开项目
- 在idea中配置jdk环境
- 配置maven环境并下载依赖
- 新建数据库,导入数据库文件
- 在application.properties文件中将数据库账号密码改成自己本地的
- 系统的静态资源存储在D盘,如果你的电脑没有D盘,则需要改成其他盘,具体位置在WebConfig.java和AddHouseController.java两个文件,将文件里面的D:改成你本地有的盘符即可。
- 启动运行, 管理员账号密码 admin/123456,普通用户直接注册或者使用默认账户 zhang/123456
四、项目截图
五、相关代码
OrderController
package com.house.wym.controller;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import com.house.wym.entity.*;
import com.house.wym.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class OrderController {
@Autowired
private IOrderService sevice;
@RequestMapping("/myorder")
public String toOrderPage() {
return "myorder";
}
@RequestMapping("/updatepwd")
public String toUpdatepwdPage() {
return "updatepwd";
}
@RequestMapping("/addOrder")
@ResponseBody
public String addOrder(String id,HttpServletRequest request) {
Users u = (Users) request.getSession().getAttribute("loginUser");
try {
Order order = new Order();
order.sethID(Integer.parseInt(id));
order.setOrderUser(u.getuNickName());
order.setuID(u.getuID());
int n = sevice.addOrder(order);
if(n>0) {
return "OK";
}
} catch (NumberFormatException e) {
e.printStackTrace();
}
return "FAIL";
}
@RequestMapping("/myOrderInfo")
@ResponseBody
public UserOrderData findAllOrder(int page, int limit, HttpServletRequest request){
Page p = new Page();
p.setPage((page - 1) * limit);
p.setLimit(limit);
Users u = (Users) request.getSession().getAttribute("loginUser");
p.setuID(u.getuID());
UserOrderData uod = new UserOrderData();
List<UserOrder> order = sevice.findAllOrder(p);
uod.setCode(0);
uod.setCount(sevice.getOrderCount(u.getuID()));
uod.setData(order);
uod.setMsg("200");
return uod;
}
@RequestMapping("/deleteOrder")
@ResponseBody
public String deleteOrder(int oID) {
int n = sevice.deleteOrder(oID);
if(n>0)
return "OK";
return "FAIL";
}
}
LoginController
package com.house.wym.controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.house.wym.config.MD5;
import com.house.wym.entity.Users;
import com.house.wym.service.IUserService;
import com.wf.captcha.utils.CaptchaUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class LoginController {
@Autowired
private IUserService mapper;
@RequestMapping("/captcha")
public void captcha(HttpServletRequest request, HttpServletResponse response) throws Exception {
CaptchaUtil.out(request, response);
}
@RequestMapping("/login")
@ResponseBody
public String toCustomerPage(String username,String password,String verCode,HttpServletRequest req ) {
if (!CaptchaUtil.ver(verCode, req)) {
CaptchaUtil.clear(req); // 清除session中的验证码
return "FAIL1";
}
Users user = new Users();
user.setuName(username);
user.setuPassword(MD5.getMD5ofStr(password));
Users loginUser = mapper.login(user);
if(loginUser!=null) {
req.getSession().setAttribute("loginUser", loginUser);
return "OK";
}
return "FAIL";
}
@RequestMapping("/signout")
public String signout(HttpSession session) {
session.invalidate();
return "redirect:toIndexPage";
}
@RequestMapping("/regist")
@ResponseBody
public String regist(Users user,String verCode,HttpServletRequest req) {
if (!CaptchaUtil.ver(verCode, req)) {
CaptchaUtil.clear(req); // 清除session中的验证码
return "FAIL1";
}
int regist;
try {
regist = mapper.regist(user);
if(regist>0) {
return "OK";
}
} catch (Exception e) {
e.printStackTrace();
}
return "FAIL";
}
}
大家点赞、收藏、关注、评论啦 、👇🏻点开下方卡片👇🏻关注后回复 101