文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Spring trim all input field

Spring trim all input field

时间:2010-05-03  来源:linxpeng

Spring3里的添加一个Convertor,把页面传来的Field去掉首尾空格.

在Spring-app-servlet.xml里,

<bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean">
    <property name="converters">
        <list>
            <bean class="sample.convertor.StringToTrimmedStringConverter"/>
        </list>
    </property>
</bean>

<mvc:annotation-driven conversion-service="conversionService"/>


class StringToTrimmedStringConverter implements org.springframework.core.convert.converter.Converter, 实现convert方法即可,如

package sample.convertor;

import org.springframework.core.convert.converter.Converter;

public class StringToTrimmedStringConverter implements
        Converter<String, String> {

    public String convert(String s) {
        return null == s ? null : s.trim();
    }

}


相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载