types之MyBatis之持有多种类型

lonelyxmas 阅读:87 2024-02-04 11:18:29 评论:0

在开始之前,这是我的类的结构

  • 人事
  • PersonnePhysique(扩展Personne)
  • PersonneMorale(扩展人员)
  • 企业(扩展 PersonneMorale)
  • 协会(扩展 PersonneMorale)

  • 我试图在数据库中插入一个“Personne”,我需要检查它是“PersonnePhysique”、“Entreprise”还是“Association”。
    所以,我在我的映射器中做了这个:
    <insert id="creerPersonne" parameterType="Personne"> 
       .... 
     
    <choose> 
        <when test="getClass() instanceof fr.maaf.personne.PersonnePhysique"> 
            1,  
        </when> 
        <when test="getClass() instanceof fr.maaf.personne.Association"> 
            2,  
        </when> 
        <when test="getClass() instanceof fr.maaf.personne.Entreprise"> 
            2,  
        </when> 
    </choose> 
     
      ... 
    </insert> 
    

    但是这个测试都没有通过。
    我究竟做错了什么 ?

    请您参考如下方法:

    我找到了一个解决方案,尽管不在官方文档中,但对于 future 的版本不应该是问题:if test="_parameter instanceof fr.maaf.personne.Entreprise"


    标签:MyBatis
    声明

    1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

    关注我们

    一个IT知识分享的公众号