基于javaweb+mysql的ssm公寓房屋出租系统(java+ssm+jsp+easyui+echarts+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SSM公寓房屋出租系统(java+ssm+jsp+easyui+echarts+mysql)
项目介绍
该项目分为前后台,分为普通用户与管理员两种角色。 前台主要功能包括: 普通用户的注册、登录,房屋列表展示,租房,我的订单、用户中心等功能模块;
后台主要功能包括: 系统设置:菜单管理、角色管理、修改密码; 用户管理:用户列表; 系统日志:日志列表; 房屋管理:房屋列表; 租赁管理:租赁列表;
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。 2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA; 3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可 4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 5.数据库:MySql 5.7版本; 6.是否Maven项目:否;
技术栈
- 后端:Spring+SpringMVC+Mybatis 2. 前端:JSP+EasyUI+Echarts+jQuery
使用说明
- 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven; 若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中db.properties配置文件中的数据库配置改为自己的配置; 4. 运行项目,输入localhost:8080即可
authorityService.add(authority);
}
ret.put("type", "success");
ret.put("msg", "权限编辑成功!");
return ret;
}
/**
* 获取某个角色的所有权限
* @param roleId
* @return
*/
@RequestMapping(value="/get_role_authority",method=RequestMethod.POST)
@ResponseBody
public List<Authority> getRoleAuthority(
@RequestParam(name="roleId",required=true) Long roleId
){
return authorityService.findListByRoleId(roleId);
}
}
/**
* 菜单管理控制器
if(StringUtils.isEmpty(oldPassword)){
retMap.put("type", "error");
retMap.put("msg", "请填写原来的密码!");
return retMap;
}
if(StringUtils.isEmpty(newPassword)){
retMap.put("type", "error");
retMap.put("msg", "请填写新密码!");
return retMap;
}
Account loginedAccount = (Account)request.getSession().getAttribute("account");
if(!oldPassword.equals(loginedAccount.getPassword())){
retMap.put("type", "error");
retMap.put("msg", "原密码错误!");
return retMap;
}
loginedAccount.setPassword(newPassword);
if(accountService.edit(loginedAccount) <= 0){
retMap.put("type", "error");
retMap.put("msg", "修改失败,请联系管理员!");
return retMap;
}
retMap.put("type", "success");
retMap.put("msg", "修改密码成功!");
return retMap;
}
/**
* 判断用户是否存在
* @param name
* @param id
* @return
*/
private boolean isExist(String name,Long id){
Account account = accountService.findByName(name);
if(account == null)return false;
if(account != null && account.getId().longValue() == id)return false;
return true;
}
}
/**
* 角色role控制器
*
*/
@RequestMapping("/admin/role")
@Controller
public class RoleController {
@Autowired
private RoleService roleService;
@Autowired
private AuthorityService authorityService;
@Autowired
private MenuService menuService;
/**
* 角色列表页面
* @param model
* @return
*/
@RequestMapping(value="/list",method=RequestMethod.GET)
public ModelAndView list(ModelAndView model){
model.setViewName("/role/list");
return model;
}
/**
* 获取角色列表
* @param page
* @param name
if(!oldPassword.equals(loginedAccount.getPassword())){
retMap.put("type", "error");
retMap.put("msg", "原密码错误!");
return retMap;
}
loginedAccount.setPassword(newPassword);
if(accountService.edit(loginedAccount) <= 0){
retMap.put("type", "error");
retMap.put("msg", "修改失败,请联系管理员!");
return retMap;
}
retMap.put("type", "success");
retMap.put("msg", "修改密码成功!");
return retMap;
}
/**
* 判断用户是否存在
* @param name
* @param id
* @return
*/
private boolean isExist(String name,Long id){
Account account = accountService.findByName(name);
if(account == null)return false;
if(account != null && account.getId().longValue() == id)return false;
return true;
}
}
bookOrder.setStatus(0);
if(bookOrderService.add(bookOrder) <= 0){
ret.put("type", "error");
ret.put("msg", "添加失败,请联系管理员!");
return ret;
}
RoomType roomType = roomTypeService.find(bookOrder.getRoomTypeId());
//出租成功后去修改该房型的出租数
if(roomType != null){
roomType.setBookNum(roomType.getBookNum() + 1);
roomType.setAvilableNum(roomType.getAvilableNum() - 1);
roomTypeService.updateNum(roomType);
//如果可用的房间数为0,则设置该房型状态已满
if(roomType.getAvilableNum() == 0){
roomType.setStatus(0);
roomTypeService.edit(roomType);
}
}
ret.put("type", "success");
ret.put("msg", "出租成功!");
return ret;
}
/**
* 修改个人信息提交
* @param account
* @return
*/
@RequestMapping(value="/update_info",method=RequestMethod.POST)
@ResponseBody
public Map<String,String> updateInfoAct(Account account,HttpServletRequest request){
Map<String,String> retMap = new HashMap<String, String>();
if(account == null){
retMap.put("type", "error");
retMap.put("msg", "请填写正确的用户信息!");
return retMap;
}
if(StringUtils.isEmpty(account.getName())){
retMap.put("type", "error");
retMap.put("msg", "用户名不能为空!");
return retMap;
}
Account loginedAccount = (Account)request.getSession().getAttribute("account");
if(isExist(account.getName(),loginedAccount.getId())){
retMap.put("type", "error");
retMap.put("msg", "该用户名已经存在!");
return retMap;
}
loginedAccount.setAddress(account.getAddress());
loginedAccount.setIdCard(account.getIdCard());
loginedAccount.setMobile(account.getMobile());
loginedAccount.setName(account.getName());
return ret;
}
if(accountService.add(account) <= 0){
ret.put("type", "error");
ret.put("msg", "添加失败,请联系管理员!");
return ret;
}
ret.put("type", "success");
ret.put("msg", "添加成功!");
return ret;
}
/**
* 用户信息编辑操作
* @param account
* @return
*/
@RequestMapping(value="/edit",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> edit(Account account){
Map<String, String> ret = new HashMap<String, String>();
if(account == null){
ret.put("type", "error");
ret.put("msg", "请填写正确的用户信息!");
return ret;
}
if(StringUtils.isEmpty(account.getName())){
ret.put("type", "error");
ret.put("msg", "用户名称不能为空!");
return ret;
}
if(StringUtils.isEmpty(account.getPassword())){
ret.put("type", "error");
ret.put("msg", "用户密码不能为空!");
return ret;
}
if(isExist(account.getName(), account.getId())){
ret.put("type", "error");
ret.put("msg", "该用户名已经存在!");
return ret;
}
if(accountService.edit(account) <= 0){
ret.put("type", "error");
ret.put("msg", "添加失败,请联系管理员!");
return ret;
* 添加权限
* @param ids
*/
@RequestMapping(value="/add_authority",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> addAuthority(
@RequestParam(name="ids",required=true) String ids,
@RequestParam(name="roleId",required=true) Long roleId
){
Map<String,String> ret = new HashMap<String, String>();
if(StringUtils.isEmpty(ids)){
ret.put("type", "error");
ret.put("msg", "请选择相应的权限!");
return ret;
}
if(roleId == null){
ret.put("type", "error");
ret.put("msg", "请选择相应的角色!");
return ret;
}
if(ids.contains(",")){
ids = ids.substring(0,ids.length()-1);
}
String[] idArr = ids.split(",");
if(idArr.length > 0){
authorityService.deleteByRoleId(roleId);
}
for(String id:idArr){
Authority authority = new Authority();
authority.setMenuId(Long.valueOf(id));
authority.setRoleId(roleId);
authorityService.add(authority);
}
ret.put("type", "success");
ret.put("msg", "权限编辑成功!");
return ret;
}
/**
* 获取某个角色的所有权限
* @param roleId
* @return
*/
@RequestMapping(value="/get_role_authority",method=RequestMethod.POST)
@ResponseBody
public List<Authority> getRoleAuthority(
/**
* 用户管理控制器
*
*/
@RequestMapping("/admin/user")
@Controller
public class UserController {
@Autowired
private UserService userService;
@Autowired
private RoleService roleService;
/**
* 用户列表页面
* @param model
* @return
*/
@RequestMapping(value="/list",method=RequestMethod.GET)
public ModelAndView list(ModelAndView model){
Map<String, Object> queryMap = new HashMap<String, Object>();
model.addObject("roleList", roleService.findList(queryMap));
model.setViewName("user/list");
return model;
}
/**
return ret;
}
if(StringUtils.isEmpty(roomType.getName())){
ret.put("type", "error");
ret.put("msg", "房屋类型名称不能为空!");
return ret;
}
RoomType existRoomType = roomTypeService.find(roomType.getId());
if(existRoomType == null){
ret.put("type", "error");
ret.put("msg", "未找到该数据!");
return ret;
}
int offset = roomType.getRoomNum() - existRoomType.getRoomNum();
roomType.setAvilableNum(existRoomType.getAvilableNum() + offset);
if(roomType.getAvilableNum() <= 0){
roomType.setAvilableNum(0);//没有可用房屋
roomType.setStatus(0);//房型已满
if(roomType.getAvilableNum() + existRoomType.getLivedNum() + existRoomType.getBookNum() > roomType.getRoomNum()){
ret.put("type", "error");
ret.put("msg", "房屋数设置不合理!");
return ret;
}
}
if(roomTypeService.edit(roomType) <= 0){
ret.put("type", "error");
ret.put("msg", "修改失败,请联系管理员!");
return ret;
}
ret.put("type", "success");
ret.put("msg", "修改成功!");
return ret;
}
/**
* 分页查询房屋类型信息
* @param name
* @param page
* @return
*/
//设置成状态可用
oldRoomType.setStatus(1);
roomTypeService.edit(oldRoomType);
}
}
//修改新的房型的可用数和出租数
RoomType newRoomType = roomTypeService.find(bookOrder.getRoomTypeId());
newRoomType.setAvilableNum(newRoomType.getAvilableNum() - 1);
newRoomType.setBookNum(newRoomType.getBookNum() + 1);
roomTypeService.updateNum(newRoomType);
if(newRoomType.getAvilableNum() <= 0){
//没有可以出租的房屋
newRoomType.setStatus(0);//设置成已出租
roomTypeService.edit(newRoomType);
}
}
ret.put("type", "success");
ret.put("msg", "修改成功!");
return ret;
}
/**
* 分页查询出租订单信息
* @param name
* @param page
* @return
*/
@RequestMapping(value="/list",method=RequestMethod.POST)
@ResponseBody
public Map<String,Object> list(
@RequestParam(name="name",defaultValue="") String name,
@RequestParam(name="accountId",defaultValue="") Long accountId,
@RequestParam(name="roomTypeId",defaultValue="") Long roomTypeId,
@RequestParam(name="idCard",defaultValue="") String idCard,
@RequestParam(name="mobile",defaultValue="") String mobile,
@RequestParam(name="status",required=false) Integer status,
Page page
){
Map<String,Object> ret = new HashMap<String, Object>();
Map<String,Object> queryMap = new HashMap<String, Object>();
ids = ids.substring(0,ids.length()-1);
}
String[] idArr = ids.split(",");
if(idArr.length > 0){
authorityService.deleteByRoleId(roleId);
}
for(String id:idArr){
Authority authority = new Authority();
authority.setMenuId(Long.valueOf(id));
authority.setRoleId(roleId);
authorityService.add(authority);
}
ret.put("type", "success");
ret.put("msg", "权限编辑成功!");
return ret;
}
/**
* 获取某个角色的所有权限
* @param roleId
* @return
*/
@RequestMapping(value="/get_role_authority",method=RequestMethod.POST)
@ResponseBody
public List<Authority> getRoleAuthority(
@RequestParam(name="roleId",required=true) Long roleId
){
return authorityService.findListByRoleId(roleId);
}
}
@ResponseBody
public Map<String, String> add(BookOrder bookOrder){
Map<String, String> ret = new HashMap<String, String>();
if(bookOrder == null){
ret.put("type", "error");
ret.put("msg", "请填写正确的出租订单信息!");
return ret;
}
if(bookOrder.getAccountId() == null){
ret.put("type", "error");
ret.put("msg", "客户不能为空!");
return ret;
}
if(bookOrder.getRoomTypeId() == null){
ret.put("type", "error");
ret.put("msg", "房型不能为空!");
return ret;
}
if(StringUtils.isEmpty(bookOrder.getName())){
ret.put("type", "error");
ret.put("msg", "出租订单联系人名称不能为空!");
return ret;
}
if(StringUtils.isEmpty(bookOrder.getMobile())){
ret.put("type", "error");
ret.put("msg", "出租订单联系人手机号不能为空!");
return ret;
}
if(StringUtils.isEmpty(bookOrder.getIdCard())){
ret.put("type", "error");
ret.put("msg", "联系人身份证号不能为空!");
return ret;
}
if(StringUtils.isEmpty(bookOrder.getArriveDate())){
ret.put("type", "error");
ret.put("msg", "到达时间不能为空!");
return ret;
}
if(StringUtils.isEmpty(bookOrder.getLeaveDate())){
ret.put("type", "error");
ret.put("msg", "离店时间不能为空!");
return ret;
}
/**
* 角色role控制器
*
*/
@RequestMapping("/admin/role")
@Controller
public class RoleController {
@Autowired
private RoleService roleService;
@Autowired
private AuthorityService authorityService;
@Autowired
private MenuService menuService;
/**
* 角色列表页面
* @param model
* @return
*/
@RequestMapping(value="/list",method=RequestMethod.GET)
public ModelAndView list(ModelAndView model){
model.setViewName("/role/list");
return model;
}
/**
* 获取角色列表
* @param page
* @param name
* @return
*/
@RequestMapping(value="/list",method=RequestMethod.POST)
@ResponseBody
public Map<String, Object> getList(Page page,
@RequestParam(name="name",required=false,defaultValue="") String name
){
/**
* 房屋类型管理后台控制器
*
*/
@RequestMapping("/admin/room_type")
@Controller
public class RoomTypeController {
@Autowired
private RoomTypeService roomTypeService;
/**
* 房屋类型管理列表页面
* @param model
* @return
*/
@RequestMapping(value="/list",method=RequestMethod.GET)
public ModelAndView list(ModelAndView model){
model.setViewName("room_type/list");
return model;
}
/**
* 房屋类型信息添加操作
* @param roomType
* @return
*/
@RequestMapping(value="/add",method=RequestMethod.POST)
@ResponseBody
public Map<String, Object> getList(Page page,
@RequestParam(name="content",required=false,defaultValue="") String content
){
Map<String, Object> ret = new HashMap<String, Object>();
Map<String, Object> queryMap = new HashMap<String, Object>();
queryMap.put("content", content);
queryMap.put("offset", page.getOffset());
queryMap.put("pageSize", page.getRows());
ret.put("rows", logService.findList(queryMap));
ret.put("total", logService.getTotal(queryMap));
return ret;
}
/**
* 添加日志
* @param user
* @return
*/
@RequestMapping(value="/add",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> add(Log log){
Map<String, String> ret = new HashMap<String, String>();
if(log == null){
ret.put("type", "error");
ret.put("msg", "请填写正确的日志信息!");
return ret;
}
if(StringUtils.isEmpty(log.getContent())){
ret.put("type", "error");
ret.put("msg", "请填写日志内容!");
return ret;
}
log.setCreateTime(new Date());
if(logService.add(log) <= 0){
ret.put("type", "error");
ret.put("msg", "日志添加失败,请联系管理员!");
return ret;
}
ret.put("type", "success");
ret.put("msg", "日志添加成功!");
return ret;
}
/**
* 批量删除日志
* @param ids
* @return
*/
@RequestMapping(value="/delete",method=RequestMethod.POST)
// ret.put("type", "error");
// ret.put("msg", "请填写密码!");
// return ret;
// }
if(user.getRoleId() == null){
ret.put("type", "error");
ret.put("msg", "请选择所属角色!");
return ret;
}
if(isExist(user.getUsername(), user.getId())){
ret.put("type", "error");
ret.put("msg", "该用户名已经存在,请重新输入!");
return ret;
}
if(userService.edit(user) <= 0){
ret.put("type", "error");
ret.put("msg", "用户添加失败,请联系管理员!");
return ret;
}
ret.put("type", "success");
ret.put("msg", "角色添加成功!");
return ret;
}
/**
* 批量删除用户
* @param ids
* @return
*/
@RequestMapping(value="/delete",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> delete(String ids){
Map<String, String> ret = new HashMap<String, String>();
if(StringUtils.isEmpty(ids)){
ret.put("type", "error");
ret.put("msg", "选择要删除的数据!");
return ret;
}
if(ids.contains(",")){
ids = ids.substring(0,ids.length()-1);
}
if(userService.delete(ids) <= 0){
ret.put("type", "error");
ret.put("msg", "用户删除失败,请联系管理员!");
queryMap.put("offset", page.getOffset());
queryMap.put("pageSize", page.getRows());
ret.put("rows", logService.findList(queryMap));
ret.put("total", logService.getTotal(queryMap));
return ret;
}
/**
* 添加日志
* @param user
* @return
*/
@RequestMapping(value="/add",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> add(Log log){
Map<String, String> ret = new HashMap<String, String>();
if(log == null){
ret.put("type", "error");
ret.put("msg", "请填写正确的日志信息!");
return ret;
}
if(StringUtils.isEmpty(log.getContent())){
ret.put("type", "error");
ret.put("msg", "请填写日志内容!");
return ret;
}
log.setCreateTime(new Date());
if(logService.add(log) <= 0){
ret.put("type", "error");
ret.put("msg", "日志添加失败,请联系管理员!");
return ret;
}
ret.put("type", "success");
ret.put("msg", "日志添加成功!");
return ret;
}
/**
* 批量删除日志
* @param ids
* @return
*/
@RequestMapping(value="/delete",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> delete(String ids){
Map<String, String> ret = new HashMap<String, String>();
}
/**
* 出租订单信息编辑操作
* @param account
* @return
*/
@RequestMapping(value="/edit",method=RequestMethod.POST)
@ResponseBody
public Map<String, String> edit(BookOrder bookOrder){
Map<String, String> ret = new HashMap<String, String>();
if(bookOrder == null){
ret.put("type", "error");
ret.put("msg", "请填写正确的出租订单信息!");
return ret;
}
if(bookOrder.getAccountId() == null){
ret.put("type", "error");
ret.put("msg", "客户不能为空!");
return ret;
}
if(bookOrder.getRoomTypeId() == null){
ret.put("type", "error");
ret.put("msg", "房型不能为空!");
return ret;
}
if(StringUtils.isEmpty(bookOrder.getName())){
ret.put("type", "error");
ret.put("msg", "出租订单联系人名称不能为空!");
return ret;
}
if(StringUtils.isEmpty(bookOrder.getMobile())){
ret.put("type", "error");
ret.put("msg", "出租订单联系人手机号不能为空!");
return ret;
}
if(StringUtils.isEmpty(bookOrder.getIdCard())){
ret.put("type", "error");
ret.put("msg", "联系人身份证号不能为空!");
return ret;
}
if(StringUtils.isEmpty(bookOrder.getArriveDate())){
ret.put("type", "error");
ret.put("msg", "到达时间不能为空!");
return ret;