springMVC的自定义类型转换器

来源:互联网 发布:win10 加密软件哪款好 编辑:程序博客网 时间:2024/06/05 16:21

通过springMVC的自定义类型转换器来解决我们在条件搜索的时候,去除空格的操作

public class CustomerParamsConverter implements Converter<String, String> {@Overridepublic 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>





原创粉丝点击