通过springMVC的自定义类型转换器来解决我们在条件搜索的时候,去除空格的操作
public class CustomerParamsConverter implements Converter<String, String> {
@Override
public String convert(String source) {
if (source != null && !"".equals(source)) {
source = source.trim();
if (!"".equals(source)) {
return source;
}
}
return null;
}
在springmvc的配置文件中加载自定义类型转换器
<!-- 配置注解驱动 -->
<mvc:annotation-driven conversion-service="convertionService"/>
<!-- 在springmvc的配置文件中加载自定义类型转换器 -->
<bean id="convertionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
<property name="converters">
<set>
<bean class="cn.itheima.baba.utils.converter.CustomerParamsConverter"></bean>
</set>
</property>
</bean>