基于javaweb+mysql的springboot房屋租赁管理系统(java+springboot+vue+maven+mysql)
运行环境
Java≥8、MySQL≥5.7、Node.js≥10
开发工具
后端:eclipse/idea/myeclipse/sts等均可配置运行
前端:WebStorm/VSCode/HBuilderX等均可
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SpringBoot房屋租赁管理系统(java+springboot+vue+maven+mysql)
用户类型:管理员、房主、用户
一、项目运行 环境配置:
Jdk1.8 + Tomcat8.5 + Mysql + HBuilderX(Webstorm也行)+ Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)。
项目技术:
Spring + SpringBoot+ mybatis + Maven + Vue 等等组成,B/S模式 + Maven管理等等。
User user = userService.getAccountByName(username);
if (user == null) {
// 注册账号
// 使用MD5+Salt(盐--用户名)+2次散列
String newPassword = new SimpleHash("MD5", password, username, 2).toHex();
newPassword=password;
int state = userService.addAccount(username, newPassword);
if (state == 1) {
return Result.success();
}
else {
return Result.error("-1", "注册失败,未知错误");
}
}
return Result.error("-1", "用户名已被占用,换一个试试");
}
@GetMapping("/notRole")
@ApiOperation("无权限跳转的接口")
public Result<?> notRole() {
System.out.println("来到notRole");
return Result.error("403", "没有权限访问...");
}
@GetMapping("/logout")
@ApiOperation("执行登出后,返回登出成功json信息")
public Result<?> logout() {
// 从SecurityUtils里边创建一个 subject
Subject subject = SecurityUtils.getSubject();
subject.logout();
System.out.println("==========logout登出系统============");
return Result.success("登出系统");
}
/**
* 登录接口
* */
/**
* 登录和权限相关的接口
* */
@RestController
@Api(tags = {"登录和注册"})
public class LoginRegisterController {
@Autowired
UserService userService;
/*登录
* 自己设置默认rememberMe登录状态true
* 自定义有效期7天 --cookie在ShiroLoginFilter中有设置了
* --Session在ShiroLoginFilter中有设置了
* */
@RequestMapping(value = "/login", method = RequestMethod.POST)
@ResponseBody
public Result<?> login(@RequestParam("username") String username,
@RequestParam("password") String password,
@RequestParam(defaultValue = "true") Boolean rememberMe) {
Subject subject = SecurityUtils.getSubject();
// 在认证提交前准备 token(令牌)
System.out.println(rememberMe + "======================");
UsernamePasswordToken token = new UsernamePasswordToken(username, password, rememberMe);
// 执行认证登陆
try {
subject.login(token);
} catch (UnknownAccountException uae) {
return Result.error("-1", "未知账户");
} catch (IncorrectCredentialsException ice) {
return Result.error("-1", "密码不正确");
} catch (LockedAccountException lae) {
return Result.error("-1", "账户已锁定");
} catch (ExcessiveAttemptsException eae) {
return Result.error("-1", "用户名或密码错误次数过多");
} catch (AuthenticationException ae) {
return Result.error("-1", "用户名或密码不正确");
}
if (subject.isAuthenticated()) {
// 将用户名和角色返回给前端
User user = userService.getAccountByName(username);
UserNameAndRoleVo result = new UserNameAndRoleVo();
result.setRole(user.getuRole());
result.setUsername(user.getuNickname());
return Result.success(result);
} else {
token.clear();
return Result.error("-1", "登录失败");
}
}
}
@PostMapping("/inputBill")
@ApiOperation("录入账单")
public Result<?> inputBill(InputBillVo inputBillVo, HttpServletRequest request) {
Long uId = (Long) SecurityUtils.getSubject().getPrincipal();
int insert = payAndBillService.inputBill(inputBillVo, uId);
if (insert == 1){
return Result.success();
}
return Result.error("-1", "录入失败");
}
@PostMapping("/terminateContract")
@ApiOperation("终止合同")
@ApiImplicitParam(name = "rhcId", value = "合同的id")
public Result<?> terminateContract(@RequestParam("rhcId") Long rhcId, HttpServletRequest request) {
Long uId = (Long) SecurityUtils.getSubject().getPrincipal();
int insert = houseService.terminateContract(rhcId, uId);
if (insert == 1){
return Result.success();
}
return Result.error("-1", "终止失败");
}
@GetMapping("/getHistoryBill")
@ApiOperation("获取我的历史账单(商家)")
@ApiImplicitParams({
@ApiImplicitParam(name = "search", value = "搜索的关键字"),
@ApiImplicitParam(name = "type", value = "根据哪种类型搜索(价格,房间号,地址)"),
@ApiImplicitParam(name = "pageNum", value = "当前页数"),
@ApiImplicitParam(name = "pageSize", value = "每页的条数"),})
public Result<?> getHistoryBill(@RequestParam(value = "search", defaultValue = "") String search,
@RequestParam(value = "type", defaultValue = "") String type,
@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
HttpServletRequest request){
Long uId = (Long) SecurityUtils.getSubject().getPrincipal();
String price = "";
String address = "";
String roomNum = "";
if (type.equals("price")) {
@Autowired
RentHouseService rentHouseService;
@Autowired
PayAndBillService payAndBillService;
@GetMapping("/collectHouse")
@ApiOperation("收藏/取消收藏房源")
@ApiImplicitParam(name = "hId", value = "房源id")
public Result<?> collectHouse(Long hId, HttpServletRequest request) {
// 获得当前操作的用户id
Long uId = (Long) SecurityUtils.getSubject().getPrincipal();
String state = houseService.collectHouse(hId, uId);
if (state.equals("fail")) {
return Result.error("-1", "收藏失败");
}
return Result.success(state);
}
@GetMapping("/appointHouse")
@ApiOperation("预约看房")
@ApiImplicitParams({
@ApiImplicitParam(name = "hId", value = "房源id"),
@ApiImplicitParam(name = "dateTime", value = "预约的时间"),})
public Result<?> appointHouse(@RequestParam("hId") Long hId,
@RequestParam("dateTime") String dateTime,
HttpServletRequest request) {
System.out.println(dateTime + "预约时间");
// 从token中获取出用户id
Long uId = (Long) SecurityUtils.getSubject().getPrincipal();
if (dateTime == null || dateTime.equals("")){
return Result.error("-1", "必须请选择预约时间");
}
// 将日期时间字符串转为Date
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date date;
try {
date = sdf.parse(dateTime);
} catch (ParseException e) {
e.printStackTrace();
/**
* 在访问controller前判断是否登录,返回json,不进行重定向。
* @param request
* @param response
* @return true-继续往下执行,false-该filter过滤器已经处理,不继续执行其他过滤器
* @throws Exception
*/
@Override
protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws IOException {
HttpServletResponse httpServletResponse = (HttpServletResponse) response;
httpServletResponse.setCharacterEncoding("UTF-8");
httpServletResponse.setContentType("application/json");
httpServletResponse.getWriter().write(JSONObject.toJSON(Result.error("401","登录认证失效,请重新登录!")).toString());
return false;
}
@Override
protected boolean onLoginSuccess(AuthenticationToken token, Subject subject, ServletRequest request, ServletResponse response) throws Exception {
WebUtils.getAndClearSavedRequest(request);
// 登录成功之后 设置session时间为7天 单位为毫秒
SecurityUtils.getSubject().getSession().setTimeout(7 * 24 * 60 * 60 * 1000L);
return true;
}
}
public class LogAspect {
private Logger logger = LogManager.getLogger(LogAspect.class);
@Pointcut("execution(* com.like.*.controller.*.*(..))")
public void LogPointcut() {}
@Around("LogPointcut()")
public Object doAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
// 接收到请求,记录请求内容
ServletRequestAttributes attributes =
(ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
javax.servlet.http.HttpServletRequest request = attributes.getRequest();
// 记录下请求内容
logger.info("请求连接 : " + request.getRequestURL().toString());
logger.info("请求方法 : " + request.getMethod());
logger.info("传入参数 :{} ", proceedingJoinPoint.getArgs());
// 获取方法的返回结果
Object result = proceedingJoinPoint.proceed();
logger.info("返回数据:{}", JSON.toJSONString(result));
return result;
}
@AfterThrowing(value = "LogPointcut()", throwing = "e")
public void doThrow(JoinPoint joinPoint, Exception e) {
Signature signature = joinPoint.getSignature();
String name = signature.getName();
logger.info("异常信息:{}:{}", name, e.getMessage());
}
}
/**
* 描述:异常拦截类
*
*/
@ControllerAdvice
public class NoPermissionException {
@ResponseBody
@ExceptionHandler(UnauthorizedException.class)
public String handleShiroException(Exception ex) {
* 这个方法决定了是否能让用户登录
*/
@Override
protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) {
Subject subject = getSubject(request, response);
//如果 isAuthenticated 为 false 证明不是登录过的,同时 isRememberd 为true 证明是没登陆直接通过记住我功能进来的
if(!subject.isAuthenticated() && subject.isRemembered()){
//获取session看看是不是空的
Session session = subject.getSession(true);
//随便拿session的一个属性来看session当前是否是空的,我用userId,你们的项目可以自行发挥
/*if(session.getAttribute("userId") == null){
//如果是空的才初始化,否则每次都要初始化,项目得慢死
//这边根据前面的前提假设,拿到的是username
String username = subject.getPrincipal().toString();
//在这个方法里面做初始化用户上下文的事情,比如通过查询数据库来设置session值,你们自己发挥
globalUserService.initUserContext(username, subject);
}*/
}
//这个方法本来只返回 subject.isAuthenticated() 现在我们加上 subject.isRemembered() 让它同时也兼容remember这种情况
return subject.isAuthenticated() || subject.isRemembered();
}
/**
* 在访问controller前判断是否登录,返回json,不进行重定向。
* @param request
* @param response
* @return true-继续往下执行,false-该filter过滤器已经处理,不继续执行其他过滤器
* @throws Exception
*/
@Override
protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws IOException {
HttpServletResponse httpServletResponse = (HttpServletResponse) response;
httpServletResponse.setCharacterEncoding("UTF-8");
httpServletResponse.setContentType("application/json");
httpServletResponse.getWriter().write(JSONObject.toJSON(Result.error("401","登录认证失效,请重新登录!")).toString());
return false;
/**
* 登录和权限相关的接口
* */
@RestController
@Api(tags = {"登录和注册"})
public class LoginRegisterController {
@Autowired
UserService userService;
/*登录
* 自己设置默认rememberMe登录状态true
* 自定义有效期7天 --cookie在ShiroLoginFilter中有设置了
* --Session在ShiroLoginFilter中有设置了
* */
@RequestMapping(value = "/login", method = RequestMethod.POST)
@ResponseBody
public Result<?> login(@RequestParam("username") String username,
@RequestParam("password") String password,
@RequestParam(defaultValue = "true") Boolean rememberMe) {
if (updateResult == 1) {
return Result.success("");
} else {
return Result.error("-1", "更新失败");
}
}
return Result.error("-1", "必须输入规则");
}
@GetMapping("/deleteMateRule")
@ApiOperation("终止规则征集房源")
public Result<?> deleteMateRule(@RequestParam("mrId") Long mrId,
HttpServletRequest request) {
Long uId = (Long) SecurityUtils.getSubject().getPrincipal();
if (mrId != null) {
// 删除匹配规则
int deleteResult = mateRuleService.deleteMateRule(mrId, uId);
if (deleteResult == 1) {
return Result.success("");
} else {
return Result.error("-1", "删除失败--当前规则不属于该用户");
}
}
return Result.error("-1", "删除失败--没有传入id");
}
@GetMapping("/getCurrentRentHouse")
@ApiOperation("获取当前当前用户租的房源")
public Result<?> getCurrentRentHouse(HttpServletRequest request){
Long uId = (Long) SecurityUtils.getSubject().getPrincipal();
// 获取当前用户正在租的房源
List<RentHouseContract> rentHouseContractList = rentHouseService.getCurrentRentHouse(uId);
return Result.success(rentHouseContractList);
}
if (type.equals("price")) {
String regEx = "[^0-9]";
Pattern pattern = Pattern.compile(regEx);
Matcher matcher;
// 将价格的非数字字符去除
matcher = pattern.matcher(search);
price = matcher.replaceAll("").trim();
}
else if (type.equals("address")){
address = search;
}
else if (type.equals("roomNum")){
roomNum = search;
}
Page<HistoryBill> resultPage = payAndBillService.getHistoryBillByUId("merchant", new Page<HistoryBill>(pageNum, pageSize), uId, price, address, roomNum);
return Result.success(resultPage);
}
}
@RestController
@RequestMapping("/user")
@Api(tags = "用户对房源的相关操作")
}
else {
return Result.error("-1", "注册失败,未知错误");
}
}
return Result.error("-1", "用户名已被占用,换一个试试");
}
@GetMapping("/notRole")
@ApiOperation("无权限跳转的接口")
public Result<?> notRole() {
System.out.println("来到notRole");
return Result.error("403", "没有权限访问...");
}
@GetMapping("/logout")
@ApiOperation("执行登出后,返回登出成功json信息")
public Result<?> logout() {
// 从SecurityUtils里边创建一个 subject
Subject subject = SecurityUtils.getSubject();
subject.logout();
System.out.println("==========logout登出系统============");
return Result.success("登出系统");
}
/**
* 登录接口
* */
/*@PostMapping("/login")
@ApiOperation("登录接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "username", value = "账号"),
@ApiImplicitParam(name = "password", value = "密码")})
public Result<?> login(@RequestParam("username") String username,
@RequestParam("password") String password) {
User user = userService.getAccountByUserNamePassword(username, password);
if (user != null) {
//只展示前端需要的部分数据
UserVo userVo = new UserVo();
BeanUtils.copyProperties(user, userVo);
@ApiImplicitParam(name = "hId", value = "房源id")
public Result<?> deleteHouse(@RequestParam("hId") Long hId,
HttpServletRequest request){
Long uId = (Long) SecurityUtils.getSubject().getPrincipal();
String result = houseService.deleteHouse(hId, uId);
if (result.equals("删除成功")){
return Result.success();
}
return Result.error("-1", result);
}
@GetMapping("/getMyBasicHouseImfor")
//方法参数说明,name参数名;value参数说明,备注;dataType参数类型;required 是否必传;defaultValue 默认值
@ApiOperation("获取当前用户发布的房源(简要信息)")
@ApiImplicitParams({
@ApiImplicitParam(name = "pageNum", value = "显示的起始页"),
@ApiImplicitParam(name = "pageSize", value = "每页的条数"),
@ApiImplicitParam(name = "titleKeyword", value = "标题关键字"),})
public Result<?> getBasicHouseImfor(@RequestParam(defaultValue = "1") Integer pageNum,
@RequestParam(defaultValue = "10") Integer pageSize,
@RequestParam(name = "titleKeyword", defaultValue = "") String titleKeyword,
HttpServletRequest request){
Long uId = (Long) SecurityUtils.getSubject().getPrincipal();
Page<House> resultPage =
houseService.getMyBasicHouseImfor(new Page<House>(pageNum, pageSize), titleKeyword, uId);
return Result.success(resultPage);
}
@GetMapping("/getImageById")
@ApiOperation("根据图片id获取图片url")
@ApiImplicitParam(name = "hiId", value = "图片id")
public Result<?> getBasicHouseImfor(@RequestParam("hiId") Long hiId){
String url = houseService.getImageByHiId(hiId);
return Result.success(url);
}
@GetMapping("/getAppointRecord")
@ApiOperation("获取被预约的记录")
@ApiImplicitParams({
@ApiImplicitParam(name = "pageNum", value = "显示的起始页"),
@ApiImplicitParam(name = "pageSize", value = "每页的条数"),})
public Result<?> getAppointRecord(@RequestParam(defaultValue = "1") Integer pageNum,
@RequestParam(defaultValue = "10") Integer pageSize,
HttpServletRequest request) {
Long uId = (Long) SecurityUtils.getSubject().getPrincipal();
Page<AppointRecord> page = houseService.getAppointRecord(new Page<AppointRecord>(pageNum, pageSize), uId, "leaser");
return Result.success(page);
@RestController
@RequestMapping("/admin")
@Api(tags = "管理员对系统管理的相关操作")
public class AdminOperationController {
@Autowired
MateRuleAction mateRuleAction;
@Autowired
AdminService adminService;
@Autowired
UserService userService;
@Autowired
HouseService houseService;
@GetMapping("/getMerchantApply")
@ApiOperation("获取商家申请未处理的记录")
@ApiImplicitParams({
@ApiImplicitParam(name = "pageNum", value = "显示的起始页"),
@ApiImplicitParam(name = "pageSize", value = "每页的条数"),})
public Result<?> getMerchantApply(@RequestParam(defaultValue = "1") Integer pageNum,
@RequestParam(defaultValue = "10") Integer pageSize,
HttpServletRequest request){
Long uId = (Long) SecurityUtils.getSubject().getPrincipal();
Page<LeaserApply> page = adminService.getMerchantApply(new Page<LeaserApply>(pageNum, pageSize), uId);
@ApiImplicitParams({
@ApiImplicitParam(name = "pageNum", value = "显示的起始页"),
@ApiImplicitParam(name = "pageSize", value = "每页的条数"),
@ApiImplicitParam(name = "titleKeyword", value = "标题关键字"),})
public Result<?> getBasicHouseImfor(@RequestParam(defaultValue = "1") Integer pageNum,
@RequestParam(defaultValue = "10") Integer pageSize,
@RequestParam(name = "titleKeyword", defaultValue = "") String titleKeyword,
HttpServletRequest request){
Long uId = (Long) SecurityUtils.getSubject().getPrincipal();
Page<House> resultPage =
houseService.getMyBasicHouseImfor(new Page<House>(pageNum, pageSize), titleKeyword, uId);
return Result.success(resultPage);
}
@GetMapping("/getImageById")
@ApiOperation("根据图片id获取图片url")
@ApiImplicitParam(name = "hiId", value = "图片id")
public Result<?> getBasicHouseImfor(@RequestParam("hiId") Long hiId){
String url = houseService.getImageByHiId(hiId);
return Result.success(url);
}
@GetMapping("/getAppointRecord")
@ApiOperation("获取被预约的记录")
@ApiImplicitParams({
@ApiImplicitParam(name = "pageNum", value = "显示的起始页"),
@ApiImplicitParam(name = "pageSize", value = "每页的条数"),})
public Result<?> getAppointRecord(@RequestParam(defaultValue = "1") Integer pageNum,
@RequestParam(defaultValue = "10") Integer pageSize,
HttpServletRequest request) {
Long uId = (Long) SecurityUtils.getSubject().getPrincipal();
Page<AppointRecord> page = houseService.getAppointRecord(new Page<AppointRecord>(pageNum, pageSize), uId, "leaser");
return Result.success(page);
}
@PostMapping("/confirmAppoint")
//方法参数说明,name参数名;value参数说明,备注;dataType参数类型;required 是否必传;defaultValue 默认值
@ApiOperation("确认预约")
@ApiImplicitParam(name = "apId", value = "预约记录的id")
public Result<?> confirmAppoint(@RequestParam("apId") Long apId, HttpServletRequest request) {
Long uId = (Long) SecurityUtils.getSubject().getPrincipal();
boolean state = houseService.confirmAppoint(apId, uId);
if (state){
return Result.success();
}
return Result.error("-1", "确认失败");
}
@PostMapping("/cancelAppoint")
@ApiOperation("取消预约")
@GetMapping("/getCollectHouse")
@ApiOperation("获取收藏的房源")
public Result<?> getCollectHouse(HttpServletRequest request){
Long uId = (Long) SecurityUtils.getSubject().getPrincipal();
List<Collect> collectList = houseService.getCollectHouse(uId);
return Result.success(collectList);
}
@GetMapping("/getHistoryBill")
@ApiOperation("获取我的历史账单(普通用户)")
@ApiImplicitParams({
@ApiImplicitParam(name = "search", value = "搜索的关键字"),
@ApiImplicitParam(name = "type", value = "根据哪种类型搜索(价格,房间号,地址)"),
@ApiImplicitParam(name = "pageNum", value = "当前页数"),
@ApiImplicitParam(name = "pageSize", value = "每页的条数"),})
public Result<?> getHistoryBill(@RequestParam(value = "search", defaultValue = "") String search,
@RequestParam(value = "type", defaultValue = "") String type,
@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
HttpServletRequest request){
Long uId = (Long) SecurityUtils.getSubject().getPrincipal();
String price = "";
String address = "";
String roomNum = "";
if (type.equals("price")) {
String regEx = "[^0-9]";
Pattern pattern = Pattern.compile(regEx);
Matcher matcher;
// 将价格的非数字字符去除
matcher = pattern.matcher(search);
price = matcher.replaceAll("").trim();
}
else if (type.equals("address")){
address = search;
}
else if (type.equals("roomNum")){
roomNum = search;
BeanUtils.copyProperties(user, userVo);
return Result.success(userVo);
}
return Result.error("-1", "没有查到该用户");
}
@PostMapping("/updateUserState")
@ApiOperation("更新用户状态")
@ApiImplicitParams({
@ApiImplicitParam(name = "uId", value = "用户id"),
@ApiImplicitParam(name = "operation", value = "操作(banSay、frozen、close、removeBanSay、removeFrozen)")})
public Result<?> updateUserState(@RequestParam("uId") Long uId,
@RequestParam("operation") String operation){
int num = userService.updateUserState(uId, operation);
if (num == 1){
return Result.success();
}
return Result.error("-1", "操作失败");
}
/* ================end================ */
@GetMapping("/getComplaintUser")
@ApiOperation("获取未处理的投诉用户信息")
@ApiImplicitParams({@ApiImplicitParam(name = "pageNum", value = "显示的起始页"),
@ApiImplicitParam(name = "pageSize", value = "每页的条数"),})
public Result<?> getComplaintUser(@RequestParam(defaultValue = "1") Integer pageNum,
@RequestParam(defaultValue = "10") Integer pageSize){
Page<ComplaintUser> result =
adminService.getUntreatedComplaintUser(new Page<ComplaintUser>(pageNum, pageSize));
return Result.success(result);
}
@GetMapping("/getComplaintHouse")
@ApiOperation("获取未处理的投诉房源信息")
@ApiImplicitParams({@ApiImplicitParam(name = "pageNum", value = "显示的起始页"),
@ApiImplicitParam(name = "pageSize", value = "每页的条数"),})
public Result<?> getComplaintHouse(@RequestParam(defaultValue = "1") Integer pageNum,
@RequestParam(defaultValue = "10") Integer pageSize){
Page<ComplaintHouse> result =
adminService.getUntreatedComplaintHouse(new Page<ComplaintHouse>(pageNum, pageSize));
return Result.success(result);
}
return Result.success(rentHouseContractList);
}
@GetMapping("/getCollectHouse")
@ApiOperation("获取收藏的房源")
public Result<?> getCollectHouse(HttpServletRequest request){
Long uId = (Long) SecurityUtils.getSubject().getPrincipal();
List<Collect> collectList = houseService.getCollectHouse(uId);
return Result.success(collectList);
}
@GetMapping("/getHistoryBill")
@ApiOperation("获取我的历史账单(普通用户)")
@ApiImplicitParams({
@ApiImplicitParam(name = "search", value = "搜索的关键字"),
@ApiImplicitParam(name = "type", value = "根据哪种类型搜索(价格,房间号,地址)"),
@ApiImplicitParam(name = "pageNum", value = "当前页数"),
@ApiImplicitParam(name = "pageSize", value = "每页的条数"),})
public Result<?> getHistoryBill(@RequestParam(value = "search", defaultValue = "") String search,
@RequestParam(value = "type", defaultValue = "") String type,
@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
HttpServletRequest request){
Long uId = (Long) SecurityUtils.getSubject().getPrincipal();
String price = "";
String address = "";
String roomNum = "";
if (type.equals("price")) {
String regEx = "[^0-9]";
Pattern pattern = Pattern.compile(regEx);
Matcher matcher;
// 将价格的非数字字符去除
matcher = pattern.matcher(search);
price = matcher.replaceAll("").trim();
}
else if (type.equals("address")){
address = search;
}
HouseService houseService;
/*
* 获取主页的初始化房源简要信息
* */
@PostMapping("/getBasicHouseImfor")
//方法参数说明,name参数名;value参数说明,备注;dataType参数类型;required 是否必传;defaultValue 默认值
@ApiOperation("获取房源简要信息")
@ApiImplicitParams({@ApiImplicitParam(name = "houseBasicVo", value = "筛选房源的条件"),})
public Result<?> getBasicHouseImfor(@RequestBody HouseBasicVo houseBasicVo){
// 将选定的价格区间分割(按~符号), 转为对象PriceScope存储
if (houseBasicVo != null){
houseBasicVo.transitionPriceScopeObjectList();
}else {
houseBasicVo = new HouseBasicVo();
}
Page<HouseBasicResultVo> page = houseService.getHouseList(new Page<>(houseBasicVo.getPageNum(), houseBasicVo.getPageSize()), houseBasicVo.getSearch(), houseBasicVo);
return Result.success(page);
}
/*
* 获取房源详细信息(查看房源详细信息)
* */
@GetMapping("/getHouseImfor")
//方法参数说明,name参数名;value参数说明,备注;dataType参数类型;required 是否必传;defaultValue 默认值
@ApiOperation("获取房源详细信息")
@ApiImplicitParam(name = "hId", value = "房源id")
public Result<?> getHouseImfor(Long hId){
// 获取房源详细信息
House house = houseService.getHouseDetailByHId(hId);
return Result.success(house);
}
}