java数据库多态

博客介绍了如何在Java数据库设计中处理一对多关系,特别是涉及预报警办理过程的状态管理。通过创建主表和外键表实现多态,使用MyBatis的discriminator技术匹配不同状态,并探讨了新增和修改操作的实现,提出了全删全增的策略以及dispatcher类的设计思路。
摘要由CSDN通过智能技术生成

现在有一个需求,预报警需要一个办理过程的属性,办理过程有5种状态
已下达 、已接受、请求无人机出动、无人机任务完成、已上报
每种状态可以有多个
这是典型的一对多的模式、应该设计一张外键表来表示内容
设计数据库如下
主表
在这里插入图片描述
子表
在这里插入图片描述
无人机任务表
在这里插入图片描述
这里的关系是 warning_alert 一对多关联 warning_alert_processing_step 关联 flight_issue
然后是mybatis里面的映射
使用一种叫做discriminator的技术,用于匹配状态

<resultMap id="warningAlertMap" type="com.swcote.warningAlert.entity.WarningAlert">
        <id property="id" column="id"/>
        <result property="reportTime" column="report_time"/>
        <result property="issue" column="issue"/>
        <result property="remarks" column="remarks"/>
        <result property="location" column="location"/>
        <result property="lat" column="lat"/>
        <result property="lng" column="lng"/>
        <result property="state" column="state"/>
        <result property="startTime" column="start_time"/>
        <result property="conclusion" column="conclusion"/>
        <result property="type" column="type"/>
        <collection property="steps" javaType="ArrayList">
            <discriminator javaType="string" column="waps_types">
                <case value="NewProcessing" resultMap="NewProcessingMap"/>
                <case value="StartProcessing" resultMap="StartProcessingMap"/>
                <case value="RequestFlight" resultMap="RequestFlightMap"/>
                <case value="FlightComplete" resultMap="FlightCompleteMap"/>
                <case value="Complete" resultMap="CompleteMap"/>
            </discriminator>
        </collection>
    </resultMap>
    <resultMap id="CompleteMap" type="com.swcote.warningAlert.entity.processingSteps.CompleteStep">
        <id property="id" column="waps_id"/>
        <result property="createTime" column="waps_create_time"/>
    </resultMap>
    <resultMap id="FlightCompleteMap" type="com.swcote.warningAlert.entity.processingSteps.FlightCompleteStep">
        <id property="id" column="waps_id"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值