開發片斷代碼

1、JShtml

    1.劃分私有空間,對屬性和操做作訪問控制spring

    var example=(function(){
          var a=123;
          var add=function(v1,v2){
                return v1+v2;
          }
          var devide=function(v1,v2){
                return v1/v2;
          }json

        //此處不返回的屬性或操做,外部是不能訪問的。
          return{
            add:add,  
          }
    })();
    //調用
    var test=example()
    test.add(1,2);
    //若是對test新增操做,既是對新增開放,對修改關閉
    var example=(function(exa){
      exa.mod=function(v1,v2){
        return v1%v2;
      }
      return exa;
    })(window.example||{});//此處指明內部模塊依賴,或者是申明內部模塊依賴了那些東西mvc

 

2、JAVAapp

1.解決FastJson序列化時檢查對象循環引用,致使解析出"$ref"這樣的東西ide

    環境:SpringMVC,code

    修改地方:FastJson視圖解析器處的配置文件,修改以下:orm

<!-- fastjson視圖解析器 -->
	<mvc:annotation-driven>
		<mvc:message-converters register-defaults="true">
			<!-- 避免IE執行AJAX時,返回JSON出現下載文件 -->
			<bean id="fastJsonHttpMessageConverter"
				class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
				<property name="supportedMediaTypes">
					<list>
						<!-- 這裏順序不能反,必定先寫text/html,否則ie下出現下載提示 -->
						<value>text/html;charset=UTF-8</value>
						<value>application/json;charset=UTF-8</value>
					</list>
				</property>
				<property name="features">
					<list>
						<value>WriteMapNullValue</value>
						<value>QuoteFieldNames</value>
						<value>WriteDateUseDateFormat</value>
						<array value-type="com.alibaba.fastjson.serializer.SerializerFeature">  
			           		<value>DisableCircularReferenceDetect</value>  
			       		</array> 
					</list>
					
				</property>
			</bean>
		</mvc:message-converters>
	</mvc:annotation-driven>
	<!-- 配置不檢查對象循環引用"-->
 	<bean id="DisableCircularReferenceDetect" class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean">  
      <property name="staticField" value="com.alibaba.fastjson.serializer.SerializerFeature.DisableCircularReferenceDetect"></property>  
   </bean>
相關文章
相關標籤/搜索