spring使用JdbcTemplate進行OR mapping的時候,對應column名稱支援底線_
主要是下面這段程式

	/**
	 * Initialize the mapping meta-data for the given class.
	 * @param mappedClass the mapped class
	 */
	protected void initialize(Class<T> mappedClass) {
		this.mappedClass = mappedClass;
		this.mappedFields = new HashMap<>();
		this.mappedProperties = new HashSet<>();
		PropertyDescriptor[] pds = BeanUtils.getPropertyDescriptors(mappedClass);
		for (PropertyDescriptor pd : pds) {
			if (pd.getWriteMethod() != null) {
				this.mappedFields.put(lowerCaseName(pd.getName()), pd);
				String underscoredName = underscoreName(pd.getName());
				if (!lowerCaseName(pd.getName()).equals(underscoredName)) {
					this.mappedFields.put(underscoredName, pd);
				}
				this.mappedProperties.add(pd.getName());
			}
		}
	}

例如:

public class CardInfo {
  private String name;
  private String expirationYear;
  private String expirationMonth;
}

經過處理mapping對象為以下

mappedFields={
expiration_year=org.springframework.beans.GenericTypeAwarePropertyDescriptor[name=expirationYear],
expirationyear=org.springframework.beans.GenericTypeAwarePropertyDescriptor[name=expirationYear],
expiration_month=org.springframework.beans.GenericTypeAwarePropertyDescriptor[name=expirationMonth],
expirationmonth=org.springframework.beans.GenericTypeAwarePropertyDescriptor[name=expirationMonth],
name=org.springframework.beans.GenericTypeAwarePropertyDescriptor[name=name]
}
mappedProperties=[expirationYear, name, expirationMonth]

 

 

 

arrow
arrow
    創作者介紹
    創作者 咪卡恰比 的頭像
    咪卡恰比

    咪卡四處看

    咪卡恰比 發表在 痞客邦 留言(0) 人氣()