spring mvc 基础三

一。转化器和格式化
     (1)Converter(将在一种类型转换成另一种类型的对象)
            【
                 1.先创建java类接口 
                    public  interface Converter<S,T>
                 2.类body中
                    T convert(S source)

              】

       (2)Formatter
                【
                    1.先创建java类接口
                      public interface Formatter<T>
                      实现接口方法1.  T  parse(String text,locale)
                                 2.  String print(T object,locale)
                    】   

二。验证器

        (1)Spring验证器(工具:ValidationUtils类)

                     public interface Validator{

                             boolean supports(Class<?> clazz);

                             void validate(Object target,Errors errors);

               }

          (2)JSR 303验证{不需要写验证器,利用JSR303标注类型嵌入约束}

三。国际化{ i18n和110n }

     (1)语言区域

          eg:   Locale locale=new Locale(“en”,“CA”)

    (2)国际化Spring mvc

                 【

                       1.将文本原件隔离成属性文件(eg:basename_languageCode_countrycode.properties)

                       2.选择和读取属性文件(eg:getBundle)

                       3.使用哪个语言区域(eg:message标签)  

             】

四。上传文件{html表格的enctype设为multipart/form-data,再用MultiparFile对象接受}

        (1)Apache Commons FileUpload

       (2)用servlet3.0及其更高版本上传文件

五。下载文件

      1.读取FileInputStream,将内容加载到字节数组,获取OutputStream,调用write传入数组 

     

猜你喜欢

转载自blog.csdn.net/qq_39736176/article/details/81291333