• 数据类型转换以及数据格式化标签_学习笔记


    数据类型转换

    1. 自定义类型转换器实现Converter<S,T>接口并加入到SpringMVC的IOC容器中:

                @Component
                public class EmployeeConverter implements Converter<String, Employee>{
                    @Override
                    public Employee convert(String source) {    
                        System.out.println(source);
                        if(source != null){
                            String[] vals = source.split("-");
                            if(vals != null && vals.length ==5){
                                String name = vals[0];
                                String email = vals[1];
                                Integer gender = Integer.parseInt(vals[2]);
                                Department department = new Department();
                                department.setId(Integer.parseInt(vals[3]));            
                                Employee employee = new Employee(null, name, email, gender, department);
                                return employee;
                            }
                        }
                        return null;
                    }
                }

    2.配置自定义转换器到FormattingConversionServiceFactoryBean工厂中!

    <!-- 将ConversionService再作为annotation-driven的一个属性存在! -->
    <mvc:annotation-driven conversion-service="conversionService"></mvc:annotation-driven>
    
    <!-- 配置ConversionService -->
    <bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
    <property name="converters">
    <set>
    <ref bean="employeeConverter"/>
    </set>
    </property>
    </bean>
  • 相关阅读:
    JS轮播图
    jquery 60秒倒计时
    jQuery 显示加载更多
    jQuery 显示加载更多
    this指针在不同情况下的指代
    web-app1--移动端等比例代码
    无障碍阅读
    javascript+dom 做javascript图片库
    初探html5---Video + DOM(视频播放)
    14个有效提高网站Banner点击率的设计技巧分享
  • 原文地址:https://www.cnblogs.com/mki-mki/p/7419836.html
Copyright © 2020-2023  润新知