摘要:
本文介绍了租约管理系统的接口实现方案。1)租约列表接口采用多表联查方式,使用嵌套结果查询获取包含图片的租约信息;2)租约详情接口为避免复杂SQL采用通用Mapper分步查询;3)其他简单接口直接使用通用Mapper实现;4)完成前后端联调,建议更新Node版本解决启动问题。开发中需注意表关联条件、字段别名匹配及空值处理等细节。
一,获取个人租约基本信息列表接口(多表查询)
对于图片集合可以采用两种查询方式:嵌套查询(手写集合查询的<select>标签)/嵌套结果查询,因为没有分页要求这里采用结果查询,但是太多的join可能损失性能
<resultMap id="AgreementItemVoMap" type="com.atguigu.lease.web.app.vo.agreement.AgreementItemVo" autoMapping="true">
<id column="id" property="id"/>
<collection property="roomGraphVoList" ofType="com.atguigu.lease.web.app.vo.graph.GraphVo" autoMapping="true"/>
</resultMap>
<select id="listItemByPhone" resultMap="AgreementItemVoMap">
select la.id,
la.lease_start_date,
la.lease_end_date,
la.rent,
la.payment_type_id,
la.status lease_status,
la.source_type,
ai.name apartment_name,
ri.room_number,
gi.name,
gi.url
from lease_agreement la
left join room_info ri on la.room_id = ri.id and ri.is_deleted = 0
left join apartment_info ai on la.apartment_id = ai.is_deleted = 0
left join graph_info gi on gi.item_id = ri.id and gi.item_type = 2 and gi.is_deleted = 0
where la.is_deleted = 0
and la.phone = #{phone}
</select>
注意点:
1,因为lease_agreement表中没有userId,所以无法直接使用本地线程里的userId,但是可以使用username(就是用户手机号)
2,记得元素别名与Vo类中保持一致,如ai.name apartment_name
3,left join图片表的连接条件是房间id
二,根据id获取租约详细信息接口
因为查询需要的表太多,所以不采用手写sql的方式来查询结果,而是在实现类中使用通用mapper来处理所有逻辑(注意处理空leaseAgreement的情况)
LeaseAgreement leaseAgreement = mapper.selectById(id);
if (leaseAgreement==null){
return null;
}
ApartmentInfo apartmentInfo=apartmentInfoMapper.selectById(leaseAgreement.getApartmentId());
List<GraphVo> apartmentGraphVoList = graphInfoMapper.getGraphVoList(leaseAgreement.getApartmentId(), ItemType.APARTMENT);
RoomInfo roomInfo = roomInfoMapper.selectById(leaseAgreement.getRoomId());
三,剩下几个接口比较简单,都是单表操作,直接使用通用接口即可,尽量自行完成,也可以当作项目实操,建议自行完成,这里不再赘述
四,至此,web-app模块所有接口完成,进行前后端联调
1,下载前端依赖并启动项目
tips:如果启动失败可以尝试更新node版本,这个项目要求较新的node版本
npm install
npm run dev
启动成功后便可以看到一个local网址:http://localhost:xxxx/,在浏览器访问即可,打开开发人员工具 ,切换到设备仿真。
1718

被折叠的 条评论
为什么被折叠?



