正如 Dave 指出的,您可以只使用 Java 从原始数据中获取所需的值,例如:
String originalData = //logic to get the entire value from your DB
String desiredValue = originalData; //If the original data does not contain "." then, the whole word is used.
//You can change it as you want
if(originalData != null){
int index = originalData.indexOf(".");
if(index != -1){
desiredValue = originalData.substring(0,index);
}
}
在这段代码中,desiredValue
变量将包含您需要的数据
我希望这是您想要的
编辑
根据您的评论,我认为您可以将此逻辑放入 bean 属性的设置器中:
private String dataWithoutDot;
//Getter here
//...
//Setter:
public void setDataWithoutDot(String originalData){
if(originalData != null){
int index = originalData.indexOf(".");
if(index != -1){
dataWithoutDot = originalData.substring(0,index);
}
}
}
编辑:根据您的评论,因为您无权ColumnDefinitionImpl
修改代码。
我不知道这是否是最好的解决方案,但至少它应该工作:
<bean id="myFactoryBean"
class="path.to.a.package.CustomDataFactory">
<property name="path" ref="MY_Data_Col"/>
</bean>
你定义一个新的工厂类:
public class CustomDataFactory{
private String path;
//getter and setter
//...
//Our factory method:
public String parseDataFromDB(){
if(path != null){
int index = path.indexOf(".");
if(index != -1){
return path.substring(0,index);
}
}
return path;
}
}
然后,进入你的 spring 上下文文件:
<bean id="date" class= "ColumnDefinitionImpl">
<property name="column" ref="lastdate"/>
<property name="path">
<bean factory-bean="myFactoryBean" factory-method="parseDataFromDB">
</property>
</bean>