Mapper icon indicating copy to clipboard operation
Mapper copied to clipboard

添加别名

Open tjpanda88 opened this issue 7 years ago • 1 comments

在@Column的字段名含名表别名的时候,会出现检索不到值的问题。 经过调查原因是SQL的返回字段名和ResultMap中的字段名不匹配造成的。 SQL的返回字段名只含有字段名(不含名表别名),ResultMap中的字段名是和@Column的name属性一致的(含名表别名)。

出现问题的代码如下: 我的代码是通过在表名中加入Left Join以实现简单的多表关联查询。但是就算没有多表查询,@Column中指定表别名的时候依旧会有问题的。

@Table(name = 
             "ATABLE AS A " + 
             "LEFT JOIN BTABLE AS B ON A.id = B.id "
)
public class AlipayComposite {

    @Id
    @Column(name = "A.field1")
    private Long atableField1;

    @Column(name = "BTable.field1")
    private String btableField1;

    // ....Get/Set略	
}

tjpanda88 avatar Mar 23 '18 08:03 tjpanda88

这种改动相当于不使用resultMap了...特殊情况先不考虑。

abel533 avatar Oct 16 '22 07:10 abel533