11.19
完成经纪人页面的语法优化后,下一步可聚焦于完善系统的安全性与用户体验,并进行全流程测试与功能补全。以下是具体步骤:
第一步:添加密码加密(提升安全性)
使用Spring Security的BCrypt对用户密码进行加密,避免明文存储。
1. 引入Spring Security依赖(pom.xml补充)
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
2. 改造用户实体与服务层
以顾客为例,修改CustomerService的注册逻辑,对密码加密:
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
@Service
public class CustomerService {
@Autowired
private CustomerRepository customerRepository;
@Autowired
private BCryptPasswordEncoder passwordEncoder;
// 顾客注册(密码加密)
public void register(Customer customer) {
customer.setPassword(passwordEncoder.encode(customer.getPassword())); // 加密密码
customer.setIsApproved(0);
customerRepository.save(customer);
}
// 顾客登录验证(密码匹配)
public boolean login(String phone, String password) {
Customer customer = customerRepository.findByPhone(phone);
if (customer != null && customer.getIsApproved() == 1) {
return passwordEncoder.matches(password, customer.getPassword());
}
return false;
}
}
3. 改造经纪人、管理员的密码加密逻辑(同理)
在AgentService、AdminService中加入BCrypt加密,确保所有用户密码均为密文存储。
第二步:完善异常处理与用户提示
为关键操作添加异常捕获与前端提示,提升用户体验。
1. 房产购买异常处理(CustomerController补充)
@GetMapping("/house/buy")
public String buyHouse(@RequestParam String houseId, Model model) {
House house = houseRepository.findById(houseId).orElse(null);
if (house == null) {
model.addAttribute("error", "房产不存在!");
return "customer/house-detail";
}
if ("售出".equals(house.getStatus()) || "停售".equals(house.getStatus())) {
model.addAttribute("error", "该房产已售罄或停售,无法购买!");
return "customer/house-detail";
}
houseService.updateStatus(houseId, "意向");
return "redirect:/customer/index";
}
2. 前端错误提示(以house-detail.html为例)
<div th:if="${error}" style="color: red;">[[${error}]]</div>
第三步:优化前端样式(提升美观度)
引入Bootstrap框架,使页面布局更专业。
1. 引入Bootstrap(templates/layout.html公共模板)
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>房产信息管理系统</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
</head>
<body>
<div class="container mt-5">
<th:block th:insert="${content}"></th:block>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
2. 改造页面为Bootstrap风格(以customer/index.html为例)
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>顾客中心-在售房产</title>
</head>
<body th:replace="layout :: layout(content='customer/index-content')">
<div th:fragment="customer/index-content">
<h2>在售房产列表</h2>
<table class="table table-bordered">
<thead>
<tr>
<th>地址</th>
<th>户型</th>
<th>面积</th>
<th>售价</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr th:each="house : ${houses}">
<td th:text="${house.address}"></td>
<td th:text="${house.roomType}"></td>
<td th:text="${house.area}"></td>
<td th:text="${house.price}"></td>
<td>
<a th:href="@{/customer/house/detail(houseId=${house.houseId})}" class="btn btn-primary btn-sm">查看详情</a>
<a th:href="@{/customer/house/buy(houseId=${house.houseId})}" class="btn btn-success btn-sm">购买</a>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
第四步:全流程测试与验收
- 功能测试:
- 顾客:注册→审核→登录→浏览→购买→查看状态流转。
- 经纪人:登录→确认交易→查看售出房产。
- 管理员:登录→新增房产→授权经纪人→停售房产。
- 边界测试:
- 测试“已售房产购买”“未审核顾客登录”等异常场景,确保提示准确。
最终交付与提交
- 打包项目:通过Maven执行
clean package,生成可执行JAR包。 - 备份数据库:导出
house_db的SQL脚本。 - 按要求命名:将JAR包、源代码、数据库备份放入“班级学号姓名”文件夹,压缩后提交。
至此,“房产信息管理系统”的核心功能、安全性、用户体验均已完善,可满足项目需求。

浙公网安备 33010602011771号