您好,我正在尝试将我的数据类映射到 jdbcTemplate 结果集。它映射与结果集匹配的所有列,但如果不同,则不映射。我们有任何注释来映射这些列吗?资助类不是实体类。
@Data
public class Funding {
private Long loanId; // DataBase Column name is LOAN_ID - This is mapping correctly
private String sellerLoanId;// Database Column name is L_SELLER_LOAN_ID - This is not
// mapping.
}
mapper = BeanPropertyRowMapper.newInstance(Funding.class);
List<Funding> fundingValues = this.jdbcTemplate.query(sql,mapper);
I tried with annotations like
@Column(name = "L_SELLER_LOAN_ID")
你必须实现自己的Mapper。
上的示例您需要在 SQL 查询中将
L_SELLER_LOAN_ID
别名为 SELLER_LOAN_ID
,例如:
SELECT LOAN_ID, L_SELLER_LOAN_ID as SELLER_LOAN_ID
FROM MY_TABLE;
然后
BeanPropertyRowMapper
应该按预期工作。请参阅:https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/jdbc/core/BeanPropertyRowMapper.html
为了促进没有匹配名称的列和属性之间的映射,请尝试在 SQL 语句中使用下划线分隔的列别名,例如“select fname as first_name from customer”,其中first_name可以映射到 setFirstName(String) 方法目标班级。