mybatis新增处理逗号

        我们有时候考虑到代码复用,新增的时候希望可以选择字段,就需要对字段进行判断,但是字段后面会跟上逗号,如果是最后一个字段为空,那么会多一个逗号。代码片段如下:

    
        #{phone},
    

    
        #{idCard}
    

       如果idCard为空,#{phone}的后面就会多一个逗号。我们可以用一个标签来处理这种情况。完整代码如下:

    
  
    insert into xdd_adposition (
    
     advertisingId,
    

    
     advertisingNo,
    

    
     content,
    

    
     type,
    

    
     period,
    

    
     status,
    

    
     createTime,
    

    
     putTime,
    

    
     outTime,
    

    
     expireTime,
    

    
     remark,
    

    
     title,
    

    
     compName,
    

    
     compAddress,
    

    
     person,
    

    
     phone,
    

    
     idCard
    

    )values(
    
     #{advertisingId},
    

    
     #{advertisingNo},
    

    
     #{content},
    

    
     #{type},
    

    
     #{period},
    

    
     #{status},
    

    
        #{createTime},
    

    
        #{putTime},
    

    
        #{outTime},
    

    
        #{expireTime},
    

    
        #{remark},
    

    
        #{title},
    

    
        #{compName},
    

    
        #{compAddress},
    

    
        #{person},
    

    
        #{phone},
    

    
        #{idCard}
    
)   
  

你可能感兴趣的:(java)