管家预约字段修复说明
🐛 问题描述
在管家预约功能中,前端发送的JSON数据包含了后端 Appointment
实体类中不存在的字段,导致反序列化失败:
Unrecognized field "ownerCommunity" (class com.parkingmanage.entity.Appointment), not marked as ignorable
🔍 问题分析
错误的字段映射
前端代码中添加了以下不存在的字段:
ownerCommunity
ownerBuilding
ownerUnits
ownerFloor
ownerRoom
isManagerBooking
后端实体类现有字段
根据 Appointment.java
,实际存在的字段是:
community
- 社区信息
building
- 楼栋信息
units
- 单元信息
floor
- 楼层信息
room
- 房间信息
ownername
- 业主姓名
ownerphone
- 业主电话
🔧 修复方案
修复前的代码:
// 错误:使用了不存在的字段
appointmentData.ownerCommunity = this.selectedOwnerInfo.community;
appointmentData.ownerBuilding = this.selectedOwnerInfo.building;
appointmentData.ownerUnits = this.selectedOwnerInfo.units;
appointmentData.ownerFloor = this.selectedOwnerInfo.floor;
appointmentData.ownerRoom = this.selectedOwnerInfo.roomnumber;
appointmentData.isManagerBooking = true;
修复后的代码:
// 正确:使用现有的字段
if (this.selectedOwnerInfo.community) {appointmentData.community = this.selectedOwnerInfo.community;
}
if (this.selectedOwnerInfo.building) {appointmentData.building = this.selectedOwnerInfo.building;
}
if (this.selectedOwnerInfo.units) {appointmentData.units = this.selectedOwnerInfo.units;
}
if (this.selectedOwnerInfo.floor) {appointmentData.floor = this.selectedOwnerInfo.floor;
}
if (this.selectedOwnerInfo.roomnumber) {appointmentData.room = this.selectedOwnerInfo.roomnumber;
}
📋 字段映射关系
业主信息字段 | Appointment字段 | 说明 |
|
| 业主姓名 |
|
| 业主电话 |
|
| 社区名称 |
|
| 楼栋号 |
|
| 单元号 |
|
| 楼层 |
|
| 房间号 |
🎯 修复效果
1. 解决序列化错误
- ✅ 移除了不存在的字段
- ✅ 使用正确的字段映射
- ✅ 保持数据完整性
2. 保持功能完整
- ✅ 管家代为预约功能正常
- ✅ 业主信息正确保存
- ✅ 地址信息完整传递
3. 数据一致性
- ✅ 前后端字段名称一致
- ✅ 数据类型匹配
- ✅ 避免冗余字段
🧪 测试验证
测试场景1:管家选择业主预约
// 预期数据结构
{"ownername": "张三","ownerphone": "13800138000", "community": "四季上东","building": "1号楼","units": "1单元", "floor": "5","room": "501","appointtype": "代人"
}
测试场景2:管家未选择业主
// 预期数据结构
{"ownername": "","ownerphone": "","appointtype": "代人"// 其他地址信息从表单获取
}
📝 注意事项
- 字段命名规范:确保前端字段名与后端实体类字段名完全一致
- 数据验证:添加了条件判断,避免空值覆盖现有数据
- 日志记录:保留详细的调试日志,便于问题排查
- 向后兼容:修改不影响其他预约类型的功能
✅ 验证清单
- 移除不存在的字段:
ownerCommunity
,ownerBuilding
,ownerUnits
,ownerFloor
,ownerRoom
,isManagerBooking
- 使用正确的字段映射关系
- 添加条件判断避免空值
- 保持日志记录完整
- 测试管家预约功能
- 验证数据保存正确性