posts - 64,comments - 22,trackbacks - 0
          阿里云主機推薦碼,可以打九折8C0BAY 有效期 11-30號
          posted @ 2015-10-15 18:13 hellxoul 閱讀(201) | 評論 (0)編輯 收藏
               摘要:   閱讀全文
          posted @ 2015-01-05 11:52 hellxoul 閱讀(320) | 評論 (0)編輯 收藏
          如果不配置其他參數,大致相當于以下的配置文件(參考自org.springframework.web.servlet.config.AnnotationDrivenBeanDefinitionParser) 
            1 <!-- 配置路徑擴展名映射的媒體類型 -->
            2   <bean name="pathExtensionContentNegotiationStrategy"
            3         class="org.springframework.web.accept.PathExtensionContentNegotiationStrategy">
            4     <constructor-arg>
            5       <props>
            6         <!-- if romePresent -->
            7         <prop key="atom">application/atom+xml</prop>
            8         <prop key="rss">application/rss+xml</prop>
            9         <!-- endif -->
           10         <!-- if jackson2Present || jacksonPresent -->
           11         <prop key="json">application/json</prop>
           12         <!-- endif -->
           13         <!-- if jaxb2Present -->
           14         <prop key="xml">application/xml</prop>
           15         <!-- endif -->
           16       </props>
           17     </constructor-arg>
           18   </bean>
           19 
           20   <!-- 配置映射媒體類型的策略 -->
           21   <bean name="mvcContentNegotiationManager"
           22         class="org.springframework.web.accept.ContentNegotiationManager">
           23     <constructor-arg>
           24       <list>
           25         <ref bean="pathExtensionContentNegotiationStrategy" />
           26       </list>
           27     </constructor-arg>
           28   </bean>
           29 
           30   <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping">
           31     <property name="order" value="0"/>
           32     <property name="removeSemicolonContent" value="false"/>
           33     <property name="contentNegotiationManager" ref="mvcContentNegotiationManager"/>
           34   </bean>
           35 
           36   <!-- 配置數據轉換服務,默認使用格式化數據轉換服務,可以對日期和數字進行格式化 -->
           37   <bean name="conversionService"
           38         class="org.springframework.format.support.DefaultFormattingConversionService">
           39     <constructor-arg index="0">
           40       <null/>
           41     </constructor-arg>
           42     <constructor-arg index="1" value="true"/>
           43   </bean>
           44 
           45   <bean name="validator"
           46         class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"/>
           47 
           48   <!-- 配置數據綁定,通過轉換服務實現綁定,如果包含jsr303實現還將進行校驗 -->
           49   <bean name="webBindingInitializer"
           50         class="org.springframework.web.bind.support.ConfigurableWebBindingInitializer">
           51     <property name="conversionService" ref="conversionService" />
           52     <!-- if jsr303Present -->
           53     <property name="validator" ref="validator" />
           54     <!-- endif -->
           55   </bean>
           56 
           57   <bean name="byteArrayHttpMessageConverter"
           58         class="org.springframework.http.converter.ByteArrayHttpMessageConverter"/>
           59 
           60   <bean name="stringHttpMessageConverter"
           61         class="org.springframework.http.converter.StringHttpMessageConverter">
           62     <property name="writeAcceptCharset" value="false" />
           63   </bean>
           64 
           65   <bean name="resourceHttpMessageConverter"
           66         class="org.springframework.http.converter.ResourceHttpMessageConverter"/>
           67   <bean name="sourceHttpMessageConverter"
           68         class="org.springframework.http.converter.xml.SourceHttpMessageConverter"/>
           69   <bean name="allEncompassingFormHttpMessageConverter"
           70         class="org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter"/>
           71   <bean name="atomFeedHttpMessageConverter"
           72         class="org.springframework.http.converter.feed.AtomFeedHttpMessageConverter"/>
           73   <bean name="rssChannelHttpMessageConverter"
           74         class="org.springframework.http.converter.feed.RssChannelHttpMessageConverter"/>
           75   <bean name="jaxb2RootElementHttpMessageConverter"
           76         class="org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter"/>
           77   <bean name="mappingJacksonHttpMessageConverter"
           78         class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"/>
           79 
           80   <!-- 配置@RequestBody,@ResponseBody注解可用的轉換器 -->
           81   <util:list id="messageConverters"
           82              list-class="org.springframework.beans.factory.support.ManagedList">
           83     <ref bean="byteArrayHttpMessageConverter" />
           84     <ref bean="stringHttpMessageConverter" />
           85     <ref bean="resourceHttpMessageConverter" />
           86     <ref bean="sourceHttpMessageConverter" />
           87     <ref bean="allEncompassingFormHttpMessageConverter" />
           88     <!-- if romePresent -->
           89     <ref bean="atomFeedHttpMessageConverter" />
           90     <ref bean="rssChannelHttpMessageConverter" />
           91     <!-- endif -->
           92     <!-- if jaxb2Present -->
           93     <ref bean="jaxb2RootElementHttpMessageConverter" />
           94     <!-- endif -->
           95     <!-- if jacksonPresent -->
           96     <ref bean="mappingJacksonHttpMessageConverter" />
           97     <!-- endif -->
           98   </util:list>
           99 
          100   <!-- 將任意類型的Controller適配為Handler -->
          101   <bean name="requestMappingHandlerAdapter"
          102         class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
          103     <property name="contentNegotiationManager" ref="mvcContentNegotiationManager" />
          104     <property name="webBindingInitializer" ref="webBindingInitializer" />
          105     <property name="messageConverters" ref="messageConverters" />
          106   </bean>
          107 
          108   <!-- 這個攔截器暴露轉換器服務讓spring:bind和spring:eval標簽可用 -->
          109   <bean name="csInterceptor"
          110         class="org.springframework.web.servlet.handler.ConversionServiceExposingInterceptor">
          111     <constructor-arg index="0" ref="conversionService"/>
          112   </bean>
          113 
          114   <!-- 現在所有攔截器都必須設定響應的路徑映射 -->
          115   <bean name="mappedCsInterceptor"
          116         class="org.springframework.web.servlet.handler.MappedInterceptor">
          117     <constructor-arg index="0">
          118       <null/>
          119     </constructor-arg>
          120     <constructor-arg index="1" ref="csInterceptor"/>
          121   </bean>
          122 
          123   <!-- 使用@ExceptionHandler注解的方法來處理Exception,優先級為0(最高) -->
          124   <bean name="exceptionHandlerExceptionResolver"
          125         class="org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver">
          126     <property name="contentNegotiationManager" ref="mvcContentNegotiationManager" />
          127     <property name="messageConverters" ref="messageConverters" />
          128     <property name="order" value="0" />
          129   </bean>
          130 
          131   <!-- 如果拋出的Exception類帶有@ResponseStatus注解,響應返回該注解的Http狀態碼,優先級為1 -->
          132   <bean name="responseStatusExceptionResolver"
          133         class="org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver">
          134     <property name="order" value="1" />
          135   </bean>
          136 
          137   <!-- SpringMvc內部異常處理 -->
          138   <bean name="defaultExceptionResolver"
          139         class="org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver">
          140     <property name="order" value="2" />
          141   </bean>
          142 
          posted @ 2014-08-03 22:35 hellxoul 閱讀(2903) | 評論 (1)編輯 收藏
          HeadFirst Servlet/JSP 學習筆記
          1.容器加載類,調用servlet的無參構造方法,并調用servlet的init()方法,從而初始化servlet。
          2.init()在servlet一生中只調用一次,往往在servlet為客戶請求提供服務之前調用。
          3.init()方法使servlet可以訪問ServletConfig和ServletContext對象,servlet需要從這些對象得到有關servlet配置和web應用的信息。
          4.容器通過調用servlet的destroy()方法來結束servlet的生命
          5.servlet一生的大多時間都是在為某個客戶端請求運行service()方法
          6.對servlet的每個請求都在一個單獨的線程中運行,任何特定servlet類都只有一個實例。
          posted @ 2014-07-05 15:21 hellxoul 閱讀(276) | 評論 (0)編輯 收藏
          轉自:http://www.cnblogs.com/peida/p/Guava_Ordering.html

          Ordering是Guava類庫提供的一個犀利強大的比較器工具,Guava的Ordering和JDK Comparator相比功能更強。它非常容易擴展,可以輕松構造復雜的comparator,然后用在容器的比較、排序等操作中。

            本質上來說,Ordering 實例無非就是一個特殊的Comparator 實例。Ordering只是需要依賴于一個比較器(例如,Collections.max)的方法,并使其可作為實例方法。另外,Ordering提供了鏈式方法調用和加強現有的比較器。

            下面我們看看Ordering中的一些具體方法和簡單的使用實例。

            常見的靜態方法:

            natural():使用Comparable類型的自然順序, 例如:整數從小到大,字符串是按字典順序;
            usingToString() :使用toString()返回的字符串按字典順序進行排序;
            arbitrary() :返回一個所有對象的任意順序, 即compare(a, b) == 0 就是 a == b (identity equality)。 本身的排序是沒有任何含義, 但是在VM的生命周期是一個常量。

            簡單實例:

          復制代碼
          import java.util.List;
          import org.junit.Test;
          import com.google.common.collect.Lists;
          import com.google.common.collect.Ordering;
          
          public class OrderingTest {
          
              @Test
              public void testStaticOrdering(){
                  List<String> list = Lists.newArrayList();
                  list.add("peida");
                  list.add("jerry");
                  list.add("harry");
                  list.add("eva");
                  list.add("jhon");
                  list.add("neron");
                  
                  System.out.println("list:"+ list);
          Ordering
          <String> naturalOrdering = Ordering.natural(); Ordering<Object> usingToStringOrdering = Ordering.usingToString(); Ordering<Object> arbitraryOrdering = Ordering.arbitrary(); System.out.println("naturalOrdering:"+ naturalOrdering.sortedCopy(list)); System.out.println("usingToStringOrdering:"+ usingToStringOrdering.sortedCopy(list)); System.out.println("arbitraryOrdering:"+ arbitraryOrdering.sortedCopy(list)); } }
          復制代碼

            輸出:

          list:[peida, jerry, harry, eva, jhon, neron]
          naturalOrdering:[eva, harry, jerry, jhon, neron, peida]
          usingToStringOrdering:[eva, harry, jerry, jhon, neron, peida]
          arbitraryOrdering:[neron, harry, eva, jerry, peida, jhon]

            操作方法:

            reverse(): 返回與當前Ordering相反的排序:
            nullsFirst(): 返回一個將null放在non-null元素之前的Ordering,其他的和原始的Ordering一樣;
            nullsLast():返回一個將null放在non-null元素之后的Ordering,其他的和原始的Ordering一樣;
            compound(Comparator):返回一個使用Comparator的Ordering,Comparator作為第二排序元素,例如對bug列表進行排序,先根據bug的級別,再根據優先級進行排序;
            lexicographical():返回一個按照字典元素迭代的Ordering;
            onResultOf(Function):將function應用在各個元素上之后, 在使用原始ordering進行排序;
            greatestOf(Iterable iterable, int k):返回指定的第k個可迭代的最大的元素,按照這個從最大到最小的順序。是不穩定的。
            leastOf(Iterable<E> iterable,int k):返回指定的第k個可迭代的最小的元素,按照這個從最小到最大的順序。是不穩定的。
            isOrdered(Iterable):是否有序,Iterable不能少于2個元素。
            isStrictlyOrdered(Iterable):是否嚴格有序。請注意,Iterable不能少于兩個元素。
            sortedCopy(Iterable):返回指定的元素作為一個列表的排序副本。

          復制代碼
          package com.peidasoft.guava.base;
          
          import java.util.List;
          
          import org.junit.Test;
          
          import com.google.common.collect.ImmutableList;
          import com.google.common.collect.Lists;
          import com.google.common.collect.Ordering;
          
          public class OrderingTest {
              
              @Test
              public void testOrdering(){
                  List<String> list = Lists.newArrayList();
                  list.add("peida");
                  list.add("jerry");
                  list.add("harry");
                  list.add("eva");
                  list.add("jhon");
                  list.add("neron");
                  
                  System.out.println("list:"+ list);
                  
                  Ordering<String> naturalOrdering = Ordering.natural();
                  System.out.println("naturalOrdering:"+ naturalOrdering.sortedCopy(list));    
          
                  List<Integer> listReduce= Lists.newArrayList();
                  for(int i=9;i>0;i--){
                      listReduce.add(i);
                  }
                  
                  List<Integer> listtest= Lists.newArrayList();
                  listtest.add(1);
                  listtest.add(1);
                  listtest.add(1);
                  listtest.add(2);
                  
                  
                  Ordering<Integer> naturalIntReduceOrdering = Ordering.natural();
                  
                  System.out.println("listtest:"+ listtest);
                  System.out.println(naturalIntReduceOrdering.isOrdered(listtest));
                  System.out.println(naturalIntReduceOrdering.isStrictlyOrdered(listtest));
                  
                  
                  System.out.println("naturalIntReduceOrdering:"+ naturalIntReduceOrdering.sortedCopy(listReduce));
                  System.out.println("listReduce:"+ listReduce);
                  
                  
                  System.out.println(naturalIntReduceOrdering.isOrdered(naturalIntReduceOrdering.sortedCopy(listReduce)));
                  System.out.println(naturalIntReduceOrdering.isStrictlyOrdered(naturalIntReduceOrdering.sortedCopy(listReduce)));
                  
          
                  Ordering<String> natural = Ordering.natural();
                        
                  List<String> abc = ImmutableList.of("a", "b", "c");
                  System.out.println(natural.isOrdered(abc));
                  System.out.println(natural.isStrictlyOrdered(abc));
                  
                  System.out.println("isOrdered reverse :"+ natural.reverse().isOrdered(abc));
           
                  List<String> cba = ImmutableList.of("c", "b", "a");
                  System.out.println(natural.isOrdered(cba));
                  System.out.println(natural.isStrictlyOrdered(cba));
                  System.out.println(cba = natural.sortedCopy(cba));
                  
                  System.out.println("max:"+natural.max(cba));
                  System.out.println("min:"+natural.min(cba));
                  
                  System.out.println("leastOf:"+natural.leastOf(cba, 2));
                  System.out.println("naturalOrdering:"+ naturalOrdering.sortedCopy(list));    
                  System.out.println("leastOf list:"+naturalOrdering.leastOf(list, 3));
                  System.out.println("greatestOf:"+naturalOrdering.greatestOf(list, 3));
                  System.out.println("reverse list :"+ naturalOrdering.reverse().sortedCopy(list));    
                  System.out.println("isOrdered list :"+ naturalOrdering.isOrdered(list));
                  System.out.println("isOrdered list :"+ naturalOrdering.reverse().isOrdered(list));
                  list.add(null);
                  System.out.println(" add null list:"+list);
                  System.out.println("nullsFirst list :"+ naturalOrdering.nullsFirst().sortedCopy(list));
                  System.out.println("nullsLast list :"+ naturalOrdering.nullsLast().sortedCopy(list));
              }
          
          }
          
          //============輸出==============
          list:[peida, jerry, harry, eva, jhon, neron]
          naturalOrdering:[eva, harry, jerry, jhon, neron, peida]
          listtest:[1, 1, 1, 2]
          true
          false
          naturalIntReduceOrdering:[1, 2, 3, 4, 5, 6, 7, 8, 9]
          listReduce:[9, 8, 7, 6, 5, 4, 3, 2, 1]
          true
          true
          true
          true
          isOrdered reverse :false
          false
          false
          [a, b, c]
          max:c
          min:a
          leastOf:[a, b]
          naturalOrdering:[eva, harry, jerry, jhon, neron, peida]
          leastOf list:[eva, harry, jerry]
          greatestOf:[peida, neron, jhon]
          reverse list :[peida, neron, jhon, jerry, harry, eva]
          isOrdered list :false
          isOrdered list :false
           add null list:[peida, jerry, harry, eva, jhon, neron, null]
          nullsFirst list :[null, eva, harry, jerry, jhon, neron, peida]
          nullsLast list :[eva, harry, jerry, jhon, neron, peida, null]
          復制代碼

          posted @ 2014-07-03 10:48 hellxoul 閱讀(398) | 評論 (0)編輯 收藏
               摘要: centos 6.5 安裝rabbitmq  閱讀全文
          posted @ 2014-06-25 22:23 hellxoul 閱讀(2266) | 評論 (0)編輯 收藏
          主站蜘蛛池模板: 拜泉县| 徐水县| 沁阳市| 斗六市| 灵台县| 兴城市| 万年县| 文水县| 浦城县| 罗定市| 武定县| 漾濞| 繁峙县| 永顺县| 定结县| 富蕴县| 禄劝| 贵州省| 阿勒泰市| 滁州市| 宿迁市| 多伦县| 汤原县| 阿克苏市| 绍兴市| 环江| 绵阳市| 瓦房店市| 武川县| 黑水县| 安达市| 望城县| 调兵山市| 怀化市| 岳普湖县| 图们市| 德安县| 措勤县| 张掖市| 额尔古纳市| 鄄城县|